Check-in [6c7a410ba0]
Not logged in

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

Overview
Comment:merge with trunk
Timelines: family | ancestors | descendants | both | wtf-8-experiment
Files: files | file ages | folders
SHA1: 6c7a410ba0cb4dfe472e2793fa9b21366e3c4857
User & Date: chw 2019-06-12 13:05:47.987
Context
2019-06-13
12:55
merge with trunk check-in: cd7193897b user: chw tags: wtf-8-experiment
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
11:35
merge with trunk check-in: 7a33036b05 user: chw tags: wtf-8-experiment
Changes
Unified Diff Ignore Whitespace Patch
Changes to jni/sdl2tk/library/tk.tcl.
494
495
496
497
498
499
500





501

502
503
504
505
506
507
508
# ----------------------------------------------------------------------
# Setup flags/vars for SDL, screen dpi, and Android.
# ----------------------------------------------------------------------

namespace eval ::tk {
    variable sdltk [expr {[info command "sdltk"] eq "sdltk"}]
    variable dpi





    set dpi [expr int((25.4 * [winfo screenwidth .]) / [winfo screenmmwidth .])]

    variable android 0
    if {$sdltk} {
	set android [sdltk android]
    }
}

# ----------------------------------------------------------------------







>
>
>
>
>
|
>







494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
# ----------------------------------------------------------------------
# Setup flags/vars for SDL, screen dpi, and Android.
# ----------------------------------------------------------------------

namespace eval ::tk {
    variable sdltk [expr {[info command "sdltk"] eq "sdltk"}]
    variable dpi
    set dpi [winfo screenmmwidth .]
    if {$dpi <= 0} {
	# Observed in X on Wayland in a VM, provide fallback
	set dpi 75
    } else {
	set dpi [expr {int((25.4 * [winfo screenwidth .]) / $dpi)}]
    }
    variable android 0
    if {$sdltk} {
	set android [sdltk android]
    }
}

# ----------------------------------------------------------------------
Changes to jni/sdl2tk/unix/tkUnixEvent.c.
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189


















190
191
192
193
194
195
196
    */
    display = XkbOpenDisplay((char *)displayNameStr, &event, &error, &major,
	    &minor, &reason);

    if (display == NULL) {
	/*fprintf(stderr,"event=%d error=%d major=%d minor=%d reason=%d\nDisabling xkb\n",
	event, error, major, minor, reason);*/
	display  = XOpenDisplay(displayNameStr);
    } else {
	use_xkb = TK_DISPLAY_USE_XKB;
	/*fprintf(stderr, "Using xkb %d.%d\n", major, minor);*/
    }

    if (display == NULL) {
	return NULL;
    }
    dispPtr = ckalloc(sizeof(TkDisplay));
    memset(dispPtr, 0, sizeof(TkDisplay));
    dispPtr->display = display;
    dispPtr->flags |= use_xkb;
#ifdef TK_USE_INPUT_METHODS
    OpenIM(dispPtr);
    XRegisterIMInstantiateCallback(dispPtr->display, NULL, NULL, NULL,
	    InstantiateIMCallback, (XPointer) dispPtr);
#endif
    Tcl_CreateFileHandler(ConnectionNumber(display), TCL_READABLE,
	    DisplayFileProc, dispPtr);



















    /*
     * Key map info must be available immediately, because of "send event".
     */
    TkpInitKeymapInfo(dispPtr);

    return dispPtr;







|



















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







163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
    */
    display = XkbOpenDisplay((char *)displayNameStr, &event, &error, &major,
	    &minor, &reason);

    if (display == NULL) {
	/*fprintf(stderr,"event=%d error=%d major=%d minor=%d reason=%d\nDisabling xkb\n",
	event, error, major, minor, reason);*/
	display = XOpenDisplay(displayNameStr);
    } else {
	use_xkb = TK_DISPLAY_USE_XKB;
	/*fprintf(stderr, "Using xkb %d.%d\n", major, minor);*/
    }

    if (display == NULL) {
	return NULL;
    }
    dispPtr = ckalloc(sizeof(TkDisplay));
    memset(dispPtr, 0, sizeof(TkDisplay));
    dispPtr->display = display;
    dispPtr->flags |= use_xkb;
#ifdef TK_USE_INPUT_METHODS
    OpenIM(dispPtr);
    XRegisterIMInstantiateCallback(dispPtr->display, NULL, NULL, NULL,
	    InstantiateIMCallback, (XPointer) dispPtr);
#endif
    Tcl_CreateFileHandler(ConnectionNumber(display), TCL_READABLE,
	    DisplayFileProc, dispPtr);

    /*
     * Observed weird WidthMMOfScreen() in X on Wayland on a
     * Fedora 30/i386 running in a VM. Fallback to 75 dpi,
     * otherwise many other strange things may happen later.
     */
    if (WidthMMOfScreen(DefaultScreenOfDisplay(display)) <= 0) {
	int mm;

	mm = (WidthOfScreen(DefaultScreenOfDisplay(display)) * 25.4) / 75.0;
	WidthMMOfScreen(DefaultScreenOfDisplay(display)) = mm;
    }
    if (HeightMMOfScreen(DefaultScreenOfDisplay(display)) <= 0) {
	int mm;

	mm = (HeightOfScreen(DefaultScreenOfDisplay(display)) * 25.4) / 75.0;
	HeightMMOfScreen(DefaultScreenOfDisplay(display)) = mm;
    }

    /*
     * Key map info must be available immediately, because of "send event".
     */
    TkpInitKeymapInfo(dispPtr);

    return dispPtr;
Changes to undroid/tsb/examples/cheatsheet.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
38
39
40
41
42
43
44
45
46
47
48

49

50
51
52
53
54
55
56
1 {h3 "Taygete Scrap Book Cheat Sheet"} 2 {h4 "Important (internal) global variables"} 3 {table 1 [info global {[A-Z]*}]} 4 {#HTML
<dl>
 <dt><b>ID</b></dt>
 <dd>The current input field during evaluation, an integer number.</dd>
 <dt><b>W</b></dt>
 <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>Creates a <code>canvas</code> emulation implementing enough methods for Plotchart, returns a widget command.</dd><br>
 <dt><code><b>tsb::canvascmd</b> cmd ...</code></dt>
 <dd>Implementation of the canvas widget command, supports <code>create</code>, <code>delete</code> and other methods plus method <code>svg</code> which renders the canvas as SVG after the corresponding input field.</dd><br>
 <dt><code><b>tsb::clear</b></code></dt>
 <dd>Clears the entire page.</dd><br>
 <dt><code><b>tsb::eval</b> id</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}












|
>

|
>

|
>

|
>

|
>
>
>

|
>
>
>

|
>
>

|
>




















|
>
|
>







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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
1 {h3 "Taygete Scrap Book Cheat Sheet"} 2 {h4 "Important (internal) global variables"} 3 {table 1 [info global {[A-Z]*}]} 4 {#HTML
<dl>
 <dt><b>ID</b></dt>
 <dd>The current input field during evaluation, an integer number.</dd>
 <dt><b>W</b></dt>
 <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>Creates a <code>canvas</code> emulation implementing enough methods for Plotchart, returns a widget command.</dd><br>
 <dt><code><b>tsb::canvascmd</b> cmd ...</code></dt>
 <dd>Implementation of the canvas widget command, supports <code>create</code>, <code>delete</code> and other methods plus method <code>svg</code> which renders the canvas as SVG after the corresponding input field.</dd><br>
 <dt><code><b>tsb::clear</b></code></dt>
 <dd>Clears the entire page.</dd><br>
 <dt><code><b>tsb::eval</b> id</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
# Load webview.

package require twv


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

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

|


>







1
2
3
4
5
6
7
8
9
10
11
# 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
}

54
55
56
57
58
59
60










61
62
63
64
65
66
67
	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







>
>
>
>
>
>
>
>
>
>







55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
	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