Check-in [3ca786aced]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:improve twv examples
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 3ca786acedf6972472d4b86497617972231c41ee
User & Date: chw 2019-06-26 10:47:17
Context
2019-06-26
10:55
more tcl upstream changes check-in: fd82382c82 user: chw tags: trunk
10:47
improve twv examples check-in: 3ca786aced user: chw tags: trunk
04:11
add selected tcllib upstream changes check-in: 17beea27ed user: chw tags: trunk
Changes

assets/tcllib1.19/math/pdf_stat.tcl became executable.

assets/tcllib1.19/simulation/pkgIndex.tcl became executable.

assets/tcllib1.19/simulation/random.tcl became executable.

Changes to undroid/tsb/examples/northwind.tsb.

1
2
3
4

5
6
7
8
9
10
11
12

















13
14
15
16
17
18
19
20
21
1 {h2 "Northwind Sample With SQLite3"} 2 {#HTML
<p>Some helper code to fetch data from an URL ...</p>} 3 {package require TclCurl

proc curl_get {url} {

    set handle [curl::init]
    $handle configure -url $url -bodyvar result
    catch {$handle perform} code
    if {$code != 0} {
        return -code error [curl::easystrerror $code]
    }
    $handle cleanup
    return $result

















}} 4 {#HTML
<p>The Northwind Sample data is on github, here's the base URL</p>} 5 set\ BASEURL\ \\\n\ \ \ \ https://raw.githubusercontent.com/jpwhite3/northwind-SQLite3/master 6 {#HTML
<p>Let's retrieve the schema diagram of the Northwind database ...</p>} 7 {img_from_binary [curl_get ${BASEURL}/Northwind_ERD.png] image/png 0} 8 {#HTML
<p>Now we create an in-memory SQLite3 database,
fill it with the NorthWind data from SQL source,
and finally list data from the [Categories] table.</p>} 9 package\ require\ sqlite3\n\nsqlite3\ DB\ :memory:\n\nDB\ eval\ \[encoding\ convertfrom\ iso8859-15\ \\\n\ \ \ \ \[curl_get\ \$\{BASEURL\}/Northwind.Sqlite3.create.sql\]\]\n\ntable\ \{CategoryID\ CategoryName\ Description\}\ \[DB\ eval\ \{\n\ \ \ \ select\ CategoryID,\ CategoryName,\ Description\ from\ \[Categories\]\n\}\] 10 {#HTML
<p>Display the images from table [Categories].</p>} 11 {foreach img [DB eval {select Picture from [Categories]}] {
    img_from_binary $img image/jpeg 0
}} 12 {tsb::save northwind.tsb}

|
<
<
>
|
|
|
|
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


|


|



1
2


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
1 {h2 "Northwind Sample With SQLite3"} 2 {#HTML
<p>Some helper code to fetch data from an URL ...</p>} 3 {if {![catch {package require TclCurl}]} {


    proc fetch_url {url} {
        set handle [curl::init]
        $handle configure -url $url -bodyvar result
        catch {$handle perform} code
        if {$code != 0} {
            return -code error [curl::easystrerror $code]
        }
        $handle cleanup
        return $result
    }
} else {
    package require http
    package require tls
    http::register https 443 tls::socket
    proc fetch_url {url} {
        set handle [http::geturl $url -binary true]
        http::wait $handle
        if {[http::status $handle] ne "ok"} {
            set code [http::code $handle]
            http::cleanup $handle
            return -code error "http::geturl code $code"
        }
        set result [http::data $handle]
        http::cleanup $handle
        return $result
    }
}} 4 {#HTML
<p>The Northwind Sample data is on github, here's the base URL</p>} 5 set\ BASEURL\ \\\n\ \ \ \ https://raw.githubusercontent.com/jpwhite3/northwind-SQLite3/master 6 {#HTML
<p>Let's retrieve the schema diagram of the Northwind database ...</p>} 7 {img_from_binary [fetch_url ${BASEURL}/Northwind_ERD.png] image/png 0} 8 {#HTML
<p>Now we create an in-memory SQLite3 database,
fill it with the NorthWind data from SQL source,
and finally list data from the [Categories] table.</p>} 9 package\ require\ sqlite3\n\nsqlite3\ DB\ :memory:\n\nDB\ eval\ \[encoding\ convertfrom\ iso8859-15\ \\\n\ \ \ \ \[fetch_url\ \$\{BASEURL\}/Northwind.Sqlite3.create.sql\]\]\n\ntable\ \{CategoryID\ CategoryName\ Description\}\ \[DB\ eval\ \{\n\ \ \ \ select\ CategoryID,\ CategoryName,\ Description\ from\ \[Categories\]\n\}\] 10 {#HTML
<p>Display the images from table [Categories].</p>} 11 {foreach img [DB eval {select Picture from [Categories]}] {
    img_from_binary $img image/jpeg 0
}} 12 {tsb::save northwind.tsb}

Changes to undroid/tsb/tsb.tcl.

794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
....
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260

1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272




















1273
1274
1275
1276
1277
1278
1279
		    upvar 1 $arg2 var
		    set var ""
		    return ""
		}
	    }
	}
    }
    if {[catch [linsert $args 0 ::tsb::gets] msg]} {
	return -code error $msg
    }
    return $msg
}

proc read {args} {
    set len [llength $args]
................................................................................
    # MacOS:     data:text/html,<html><head><script>window.external.invoke("0 ::tsb::reload");</script></head></html>
    # WebkitGtk: data:text/html,<html><head><script>window.webkit.messageHandlers.extern.postMessage("0 ::tsb::reload");</script></head></html>

    variable U
    set U "data:text/html,%3Chtml%3E%3Chead%3E%3Cscript%3E"
    if {($tcl_platform(platform) eq "windows") ||
	($tcl_platform(os) eq "Darwin")} {
	append U "window.external.invoke(%220%20::tsb::reload%22)%3B"
    } else {
	append U "window.webkit.messageHandlers.external.postMessage(%220%20::tsb::reload%22)%3B"
    }
    append U "%3C%2Fscript%3E%3C%2Fhead%3E%3C%2Fhtml%3E"

    # The base title
    variable title "Taygete Scrap Book"

    # The current file
    variable file ""
}

# If file name given, load history array from it now.


set title $::tsb::title
if {[llength $argv] && [file readable [lindex $argv 0]]} {
    catch {
	apply {name {
	    set f [open $name r]
	    set data [read $f]
	    close $f
	    array set ::H $data
	    set ::tsb::file $name
	}} [lindex $argv 0]
    }




















}

# Initialize webview; document is loaded indirectly via the URL
# which triggers ::tsb::reload which does the rest, but see
# the ::tsb::ready block below.

set W [::twv::new -width 800 -height 600 -title $::tsb::title \







|







 







|

|










|
>












>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
....
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
		    upvar 1 $arg2 var
		    set var ""
		    return ""
		}
	    }
	}
    }
    if {[catch {uplevel 1 ::tsb::gets {*}$args} msg]} {
	return -code error $msg
    }
    return $msg
}

proc read {args} {
    set len [llength $args]
................................................................................
    # MacOS:     data:text/html,<html><head><script>window.external.invoke("0 ::tsb::reload");</script></head></html>
    # WebkitGtk: data:text/html,<html><head><script>window.webkit.messageHandlers.extern.postMessage("0 ::tsb::reload");</script></head></html>

    variable U
    set U "data:text/html,%3Chtml%3E%3Chead%3E%3Cscript%3E"
    if {($tcl_platform(platform) eq "windows") ||
	($tcl_platform(os) eq "Darwin")} {
	append U "window.external.invoke%28%220%20::tsb::reload%22%29%3B"
    } else {
	append U "window.webkit.messageHandlers.external.postMessage%28%220%20::tsb::reload%22%29%3B"
    }
    append U "%3C%2Fscript%3E%3C%2Fhead%3E%3C%2Fhtml%3E"

    # The base title
    variable title "Taygete Scrap Book"

    # The current file
    variable file ""
}

# If file name given, load history array from it now, else
# fill the first history item with some links to examples.

set title $::tsb::title
if {[llength $argv] && [file readable [lindex $argv 0]]} {
    catch {
	apply {name {
	    set f [open $name r]
	    set data [read $f]
	    close $f
	    array set ::H $data
	    set ::tsb::file $name
	}} [lindex $argv 0]
    }
} else {
    apply {dir {
	set t ""
	foreach n [lsort -dictionary [glob -nocomplain $dir/*.tsb]] {
	    if {[string match "*\"'*" $n]} {
		continue
	    }
	    append t "<dt><a href='javascript:void(0);'"
	    append t " onclick='RunTcl(\"0 ::tsb::load [list $n]\");'>"
	    append t [file tail $n] "</a></dt>\n"
	}
	if {$t ne ""} {
	    set h "#HTML\n<h3>Welcome!</h3>"
	    append h "<dl><dt><a href='javascript:void(0);'"
	    append h " onclick='RunTcl(\"0 ::tsb::clear\");'>"
	    append h " Start a new empty document.</a></dt></dl>\n"
	    append h "<h4>Example documents:</h4>\n"
	    set ::H(1) ${h}<dl>${t}</dl>
	}
    }} [file join [file dirname [info script]] examples]
}

# Initialize webview; document is loaded indirectly via the URL
# which triggers ::tsb::reload which does the rest, but see
# the ::tsb::ready block below.

set W [::twv::new -width 800 -height 600 -title $::tsb::title \