Check-in [d0fc7d3af8]
Not logged in

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

Overview
Comment:improve twv demos
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d0fc7d3af8eaa6fb83f357e6844e39627f9c1aa6
User & Date: chw 2019-06-12 13:05:05
Context
2019-06-13
07:46
fix pkg index template in tclcan check-in: 086eeca314 user: chw tags: trunk
2019-06-12
13:05
merge with trunk check-in: 6c7a410ba0 user: chw tags: wtf-8-experiment
13:05
improve twv demos check-in: d0fc7d3af8 user: chw tags: trunk
12:53
in tk protect against weird screen dpi values check-in: e54a8ad2b7 user: chw tags: trunk
Changes

Changes to undroid/tsb/examples/cheatsheet.tsb.

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
..
41
42
43
44
45
46
47
48

49

50
51
52
53
54
55
56
 <dd>The Webview for displaying the page.</dd>
 <dt><b>H</b></dt>
 <dd>The history array of input fields, keys are integer numbers starting from 1.</dd>
</dl>} 5 {# current state of history array
table 2 [array get H]} 6 {h4 "Useful procs in the global namespace"} 7 {info proc *} 8 {#HTML
<dl>
 <dt><code><b>parray</b> arrayname ?pattern?</code></dt>
 <dd>Pretty print an array using <code><b>puts</b></code> and thus outputs after the corresponding input field.</dd><br>

 <dt><code><b>htmlraw</b> html ?hidden?</code></dt>
 <dd>Output raw HTML after the corresponding input field, if <code>hidden</code> is true, auto-hide the input field.</dd><br>

 <dt><code><b>gets</b></code>, <code><b>read</b></code></dt>
 <dd>Overriden, reading from <code>stdin</code> channel yields empty string.</dd><br>

 <dt><code><b>puts</b></code></dt>
 <dd>Overriden, writing to <code>stdout</code>/<code>stderr</code> channels outputs after the corresponding input field.</dd><br>

 <dt><code><b>h1</b> string</code>, <code><b>h2..h5</b></code></dt>
 <dd>Format a HTML header after the correspondig input field, auto-hide the input field.</dd><br>



 <dt><code><b>img</b> ?filename import mime?</code></dt>
 <dd>Format a HTML IMG given <code>filename</code>, if file name omitted, present file selection. If <code>import</code> is true, the image is inlined. If the mime type of the image is unknown it can be specified with the <code>mime</code> parameter.</dd><br>



 <dt><code><b>img_from_binary</b> data mime ?hidden?</code></dt>

 <dd>Format a HTML IMG given the byte array <code>data</code> and mime type <code>mime</code>. If <code>hidden</code> is false, the corresponding input field is not auto-hidden.</dd><br>

 <dt><code><b>table</b> ncols data</code></dt>

 <dd>Format a HTML table, <code>ncols</code> gives the number of columns, if negative, use the first <code>-ncols</code> items as header columns.</dd>
</dl>} 9 {h4 "Useful procs in the tsb namespace"} 10 {info proc tsb::*} 11 {#HTML
<dl>
 <dt><code><b>tsb::load</b> ?filename?</code></dt>
 <dd>Load page from given <code>filename</code>, if file name omitted, present file selection.</dd><br>
 <dt><code><b>tsb::save</b> ?filename?</code></dt>
 <dd>Save page to given <code>filename</code>, if file name omitted, present file selection.</dd><br>
 <dt><code><b>tsb::canvas</b> ?-width w -height h?</code></dt>
................................................................................
 <dd>Re-evaluates field with number <code>id</code>.</dd><br>
 <dt><code><b>tsb::print</b></code></dt>
 <dd>Opens the print dialog to print the page.</dd>
</dl>} 12 {h4 "Input Fields"} 13 {#HTML
<p>Input fields have a label of the form <code>in(&lt;number&gt;)</code> where the
number is the index in the history array. Arbitraty text can be entered which
however should be valid Tcl code, except the very first line is <code>#HTML</code>
in which case the following lines should be valid HTML text. The input field

is evaluated when <code>&lt;Shift&gt;-&lt;Return&gt;</code> is pressed.</p>

<p>Depending on the command evaluation the input field is sometimes hidden.
A double click on the corresponding output field(s) makes the input field visible
and thus editable, again.</p>} 14 {h4 "Output Fields"} 15 {#HTML
<p>Each input field has two corresponding output fields which are visible/non-empty
depending on context. One output field receives preformatted text, either the result
or the error message of a command evaluation. The other output field receives HTML,
e.g. for displaying an image or for the <code>#HTML</code> form from the input field.</p>} 16 {tsb::save cheatsheet.tsb}







|
>

|
>

|
>

|
>

|
>
>
>

|
>
>
>

>
|
>

>
|







 







|
>
|
>







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
38
39
40
41
42
43
44
45
46
47
..
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
 <dd>The Webview for displaying the page.</dd>
 <dt><b>H</b></dt>
 <dd>The history array of input fields, keys are integer numbers starting from 1.</dd>
</dl>} 5 {# current state of history array
table 2 [array get H]} 6 {h4 "Useful procs in the global namespace"} 7 {info proc *} 8 {#HTML
<dl>
 <dt><code><b>parray</b> arrayname ?pattern?</code></dt>
 <dd>Pretty print an array using <code><b>puts</b></code> and thus outputs
     after the corresponding input field.</dd><br>
 <dt><code><b>htmlraw</b> html ?hidden?</code></dt>
 <dd>Output raw HTML after the corresponding input field, if <code>hidden</code>
     is true, auto-hide the input field.</dd><br>
 <dt><code><b>gets</b></code>, <code><b>read</b></code></dt>
 <dd>Overriden, reading from <code>stdin</code> channel yields empty
     string.</dd><br>
 <dt><code><b>puts</b></code></dt>
 <dd>Overriden, writing to <code>stdout</code>/<code>stderr</code> channels
     outputs after the corresponding input field.</dd><br>
 <dt><code><b>h1</b> string</code>, <code><b>h2..h5</b></code></dt>
 <dd>Format a HTML header after the correspondig input field, auto-hide
     the input field.</dd><br>
 <dt><code><b>hr</b></code></dt>
 <dd>Format a horizontal ruler, auto-hide the input field.</dd><br>
 <dt><code><b>img</b> ?filename import mime?</code></dt>
 <dd>Format a HTML IMG given <code>filename</code>, if file name omitted,
     present file selection. If <code>import</code> is true, the image is
     inlined. If the mime type of the image is unknown it can be specified
     with the <code>mime</code> parameter.</dd><br>
 <dt><code><b>img_from_binary</b> data mime ?hidden?</code></dt>
 <dd>Format a HTML IMG given the byte array <code>data</code> and mime
     type <code>mime</code>. If <code>hidden</code> is false, the corresponding
     input field is not auto-hidden.</dd><br>
 <dt><code><b>table</b> ncols data</code></dt>
 <dd>Format a HTML table, <code>ncols</code> gives the number of columns,
     if negative, use the first <code>-ncols</code> items as header columns.</dd>
</dl>} 9 {h4 "Useful procs in the tsb namespace"} 10 {info proc tsb::*} 11 {#HTML
<dl>
 <dt><code><b>tsb::load</b> ?filename?</code></dt>
 <dd>Load page from given <code>filename</code>, if file name omitted, present file selection.</dd><br>
 <dt><code><b>tsb::save</b> ?filename?</code></dt>
 <dd>Save page to given <code>filename</code>, if file name omitted, present file selection.</dd><br>
 <dt><code><b>tsb::canvas</b> ?-width w -height h?</code></dt>
................................................................................
 <dd>Re-evaluates field with number <code>id</code>.</dd><br>
 <dt><code><b>tsb::print</b></code></dt>
 <dd>Opens the print dialog to print the page.</dd>
</dl>} 12 {h4 "Input Fields"} 13 {#HTML
<p>Input fields have a label of the form <code>in(&lt;number&gt;)</code> where the
number is the index in the history array. Arbitraty text can be entered which
however should be valid Tcl code, except the very first line is <code>#HTML</code>
or <code>#MARKDOWN</code>, in which case the following lines should be valid HTML
or Markdown text, respectively. The input field is evaluated when
<code>&lt;Shift&gt;-&lt;Return&gt;</code> is pressed.</p>

<p>Depending on the command evaluation the input field is sometimes hidden.
A double click on the corresponding output field(s) makes the input field visible
and thus editable, again.</p>} 14 {h4 "Output Fields"} 15 {#HTML
<p>Each input field has two corresponding output fields which are visible/non-empty
depending on context. One output field receives preformatted text, either the result
or the error message of a command evaluation. The other output field receives HTML,
e.g. for displaying an image or for the <code>#HTML</code> form from the input field.</p>} 16 {tsb::save cheatsheet.tsb}

Changes to undroid/tsb/tsb.tcl.

1
2
3

4
5
6
7
8
9
10
..
54
55
56
57
58
59
60










61
62
63
64
65
66
67
# Load webview.

package require twv


# On MacOSX we need Tk early, otherwise crashes occur.

if {$tcl_platform(os) eq "Darwin"} {
    package require Tk
}

................................................................................
	set n [string first "\n" $str]
	if {$n > 4} {
	    incr n
	    set str [string range $str $n end]
	}
	$::W call Wraw $id $str 1
	$::W call Inhide $id 1










	set newfield 1
    } elseif {[catch {uplevel \#0 $str} ret opts]} {
	if {[dict get $opts -code] == 4} {
	    # continue
	    $::W call Wclear $id
	} else {
	    $::W call Werror $id $::errorInfo
|


>







 







>
>
>
>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
..
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Load webview and other stuff.

package require twv
package require Markdown

# On MacOSX we need Tk early, otherwise crashes occur.

if {$tcl_platform(os) eq "Darwin"} {
    package require Tk
}

................................................................................
	set n [string first "\n" $str]
	if {$n > 4} {
	    incr n
	    set str [string range $str $n end]
	}
	$::W call Wraw $id $str 1
	$::W call Inhide $id 1
	set newfield 1
    } elseif {[string first "#MARKDOWN" $str] == 0} {
	set n [string first "\n" $str]
	if {$n > 8} {
	    incr n
	    set str [string range $str $n end]
	}
	set str [Markdown::convert $str]
	$::W call Wraw $id $str 1
	$::W call Inhide $id 1
	set newfield 1
    } elseif {[catch {uplevel \#0 $str} ret opts]} {
	if {[dict get $opts -code] == 4} {
	    # continue
	    $::W call Wclear $id
	} else {
	    $::W call Werror $id $::errorInfo