Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Difference From 10841691dec0938c
To e7a0818911d9c09c
|
2017-05-16
| | |
| 01:49 |
|
check-in: 1df339eaad user: aspect tags: trunk
|
|
2017-05-15
| | |
| 11:25 |
|
check-in: e7a0818911 user: aspect tags: trunk
|
| 09:58 |
|
check-in: 61b819dcb7 user: aspect tags: trunk
|
|
2015-09-14
| | |
| 04:08 |
|
check-in: ec76b66d82 user: aspect tags: trunk
|
|
2015-08-27
| | |
| 13:37 |
|
check-in: 10841691de user: aspect tags: trunk
|
|
2015-08-21
| | |
| 23:40 |
|
check-in: f848e6ea45 user: aspect tags: trunk
|
| | |
Changes to README.
| ︙ | | |
13
14
15
16
17
18
19
|
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
+
+
+
+
+
+
+
+
+
+
+
|
oometa - TclOO extension done right
procmap - collect metadata about Tcl procedures at runtime. Dangerously.
tcltags - ctags(1) clone for Tcl
modules - various general-purpose pure-Tcl modules
hacks - interesting hacks that are too experimental to be useful yet
Where stuff is demo'able, I've included "boot.tcl" which will stuff the
appropriate dirs into $::auto_path and tcl::tm::path so that it can find its
modules. Just put that in the command-line:
$ tclsh boot.tcl hacks/Window-0.tm
!NOTE!: the contents of this repository often lag dreadfully behind what I'm
actually using in live projects. If anything seems particularly funky, or
simply fails to work, ping me with a ticket (or on the chat) to update it.
|
Added boot.tcl.
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
#!/usr/bin/env tclsh
#
#lappend auto_path [file normalize [info script]/../modules]
#::tcl::tm::path add [file normalize [info script]/../modules]
proc boot {args} [format {
{*}$args [list lappend auto_path %1$s]
{*}$args [list ::tcl::tm::path add %1$s]
} [list [file normalize [info script]/../modules]]]
boot eval
package provide boot 0.1
if {$::argv ne ""} {
proc info_cmdline {} [list list [info nameofexe] $::argv0 $::argv] ;# hack for restartability
set ::argv [lassign $::argv ::argv0]
source $::argv0
} else {
return
# async repl:
package require repl
coroutine main repl::chan stdin stdout stderr
trace add command main delete {unset ::forever; #}
vwait forever
}
|
| | | | | | | | | | | | | | | | | | | | | |
Changes to ebnf/README.md.
| ︙ | | |
55
56
57
58
59
60
61
|
55
56
57
58
59
60
61
62
63
64
65
66
|
+
+
+
+
+
|
** Inbuilt lexers
[token] - consume (space then) a literal without reporting (doesn't appear in $0)
[token!] - consume (space then) a literal and push its value onto $0
[opt script] - attempt script. If it fails, push a single empty result onto $0.
[any s0 ...] - attempt each script until one succeeds. The successful script's results will appear on $0.
[many script]- try script repeatedly until it fails. Results are collected into a list and pushed.
** References
http://www.garshol.priv.no/download/text/bnf.html
|
Changes to ebnf/parser-1.tm.
| ︙ | | |
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
-
+
-
+
|
debug log {[string repeat " " [info level]][info level -1]: [uplevel 1 {list $i $s}] -> $args}
tailcall tailcall lappend 0 {*}$args
}
;# commands to define parsers:
proc space {} {} ;# default space is a noop
proc space {} { ;# for RC we want a better space
upvar 1 s s i i
incr i [string length {*}[regexp -inline -start $i {\s*} $s]]
incr i [string length [lindex [regexp -inline -start $i {\s*} $s] 0]]
return
}
proc %space {re} {
set re \\A(?:$re)
tailcall proc space {} [format {
upvar 1 s s i i
incr i [string length {*}[regexp -inline -start $i %s $s]]
incr i [string length [lindex [regexp -inline -start $i %s $s] 0]]
return
} [list $re]]
}
proc %token {name re {result "set 0"}} {
set re \\A(?:$re)
tailcall proc $name {} [format {
|
| ︙ | | |
Changes to go/README.md.
| ︙ | | |
48
49
50
51
52
53
54
|
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
+
+
+
+
+
+
+
+
+
|
subscribe pattern ?cmd? ?arg ...?
proc waiton {args} { subscribe $args [info coroutine] }
notify event
delete event
unrelated margin note: [yieldto _ [info coroutine]] ~= (call/cc)
Further refinements might be had from examining:
http://jlongster.com/Taming-the-Asynchronous-Beast-with-CSP-in-JavaScript
Note that his [go] returns a one-shot channel for the generator's final result.
[take [timeout 100]] vs [sleep 100] is a tidy identity too.
Sliding and Dropping channels are missing from securitykiss CSP and this implementation.
|
Changes to hacks/Window-0.tm.
| ︙ | | |
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
-
+
+
+
-
+
-
+
+
-
-
-
-
+
+
+
+
+
+
+
-
+
+
+
+
+
+
-
+
-
+
|
# an OptSpec looks like:
# {-commandlineswitch resourceName ResourceClass defaultValue verifier}
# snit provides -default -verifier -configuremethod -cgetmethod
# I think options belong in class definition, whilst this is (so far) object definition
#
# making classes out of these is going to be the kicker!
#
# Hierarchical bindtags a la bindtags(n) example looks interesting
# Hierarchical bindtags (bubbling) a la bindtags(n) example looks interesting
#
# method upvar is indeed cool, but I've broken [my variable].
#
# Do we want instead [myvariable] and [mymethod] ? I think we do, because [variable] is a useful method name.
#
#
# w container constructor ?...? {script}] can put things in a container
# gridconfigure to hide things
#
# containers make visible hierarchies, which will be interesting
#
#
# To make forms:
# * frames (also panes and tabs)
# * onchange and condition need a bit of work
# * collections are still a bit icky
#
# Some tidy up is due:
# * widget/varnames should be Upper Cased but the Tk name has to be .lOwer
# * options want to come from a metaclass. But remember I want item options too.
# * a trace mixin would tidy thing some
#
# I almost want to make these namespace ensembles rather than objects
#
# TODO:
# * ttk-ify everything
# * panedwindow container
# * notebook container
# * tooltips!
# * some kind of options support
#
package require Tk
package require snidgets
package require pkg
package require tests
package require adebug
#package require repl
package require debug
package require tkImprover
pkg -export * Window {
pkg -export {[A-Z]*} Window {
proc putl args {puts $args}
proc callback {args} {
tailcall namespace code $args
}
proc windowcontext {} {}
oo::class create Widget {
variable w
constructor {cmd args} {
namespace path [linsert [namespace path] end ::ttk]
# if the first argument is a window path, we adopt that window
# otherwise, it is a window constructor
if {[string match .* $cmd]} {
set w $cmd
$w configure {*}$args
} else {
set w [uplevel 1 windowcontext].[namespace tail [self object]]
$cmd $w {*}$args
set w [uplevel 1 windowcontext].[namespace tail [self object]]
$cmd $w {*}$args
}
# move the window into this object's namespace
rename $w [namespace current]::$w
namespace export $w
namespace eval :: [list namespace import [namespace current]::$w]
# init vars
if {$w eq "."} {
proc windowcontext {} {return ""}
} else {
proc windowcontext {} [list return $w]
proc windowcontext {} [list return $w]
}
set griddefaults {}
bind $w <Destroy> [list catch [my callback Reaper %W]] ;# we still need to catch
bind $w <Destroy> [list catch [callback my Reaper %W]] ;# we still need to catch
;# because tear-down order
self
return [self]
}
destructor {
bind $w <Destroy> {}
catch next
}
export varname ;# this will be useful for consumers
;# as will this:
method callback {method args} {
namespace code [list my $method {*}$args]
method eval {script} {
try $script
}
method Reaper {W} {
if {$W eq $w} {
debug log {[self] Dying on <Destroy>}
my destroy
} else {
debug log {WARNING: [self] Reaper $W (doing nothing)}
}
}
method w {} {return $w}
method widget {cmd name args} {
Widget create $name $cmd {*}[my WidgetArgs $args]
oo::objdefine [self] forward $name $name
oo::objdefine [self] export $name
if {[info exists autolayout] && $autolayout ne ""} {
set largs [lassign $autolayout method]
my $method $name {*}$largs
}
return $name
return [namespace which $name]
}
method WidgetArgs {arglist} {
set q 0
lmap a $arglist {
if {$q} {
if {![string match ::* $a]} {
if {[string match *(*) $a]} { ;# unwrap array name
set n [lindex [split $a (] 0]
} else {
set n $a
}
debug assert {$a in [info object variables [self]]}
debug assert {$n in [info object variables [self]]}
set q 0
my varname $a
} else {
set a
}
} else {
if {[string match -*variable $a]} {
if {[string match -*variable $a] || [string match -*var $a]} {
set q 1
}
set a
}
}
}
|
| ︙ | | |
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
-
+
+
-
+
-
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
-
+
-
-
+
|
if {$args eq ""} {
bind $w destroy {}
next ;# destroy self, taking window with
} else {
destroy {*}[my ItemArgs $args]
}
}
variable autolayout
method autolayout args {
multiargs {
{packer args} {
my GM $packer [my GetIn $args]
set autolayout [list $packer {*}$args]
}
{} {
return $autolayout
}
}
}
variable griddefaults
method griddefaults args {
set griddefaults $args
}
method packdefaults args {
set griddefaults $args
}
method GM args {
multiargs {
{} {
list [self] [dict get $GM $w]
}
{packer container} {
if {![string match .* $container]} {
set container [$container w]
}
if {[info exists GM] && [dict exists $GM $container]} {
set gm [dict get $GM $container]
if {$gm ne $packer} {
throw {GM CONFLICT} "Geometry manager is already $gm!"
}
}
dict set GM $container $packer
}
}
}
method GetIn {opts} {
set idx [lsearch -exact $opts -in]
if {$idx == -1} {
return $w
} else {
lindex $opts $idx+1
}
}
method grid {cmd args} {
my GM grid [my GetIn $args]
if {$cmd eq "anchor"} {
multiargs {
{slave} {
grid $cmd [my WinArg $slave]
}
{slave anchor} {
grid $cmd [my WinArg $slave] $anchor
}
}
if {$cmd in "anchor bbox location size propagate slaves configure rowconfigure columnconfigure"} {
} elseif {$cmd in "bbox location size propagate slaves configure rowconfigure columnconfigure forget"} {
putl grid $cmd $w {*}[my ItemArgs {*}$args]
grid $cmd $w {*}[my ItemArgs {*}$args]
} else {
grid {*}[my GridArgs $cmd {*}$args] -in $w
grid {*}[my GridArgs $cmd {*}$args] ;#-in $w
}
}
method pack {cmd args} {
my GM pack [my GetIn $args]
if {$cmd in "propagate slaves"} {
if {$cmd in "propagate slaves forget"} {
pack $cmd $w {*}[my ItemArgs {*}$args]
} else {
pack {*}[my GridArgs $cmd {*}$args] -in $w
pack {*}[my GridArgs $cmd {*}$args] ;#-in $w
}
}
method ItemArgs {args} {
set j [lsearch -glob $args -*]
if {$j == -1} {
set preargs $args
set i 0
set args [lmap a $args {
if {[string match -* $a]} {
set opts {}
} else {
set preargs [lrange $args 0 [expr {$j-1}]]
set opts [lrange $args $j end]
}
puts "preargs = $preargs"
set preargs [lmap a $preargs {my WinArg $a}]
puts "postargs = $preargs"
if {[dict exists $opts -in]} {
incr i
}
dict set opts -in [my WinArg [dict get $opts -in]]
}
expr {$i ? $a : [$a w]}
}]
concat $preargs $opts
}
method GridArgs {args} {
set j [lsearch -glob $args -*]
if {$j == -1} {
set preargs $args
set i 0
array set def $griddefaults
set args [lmap a $args {
if {[string match -* $a]} {
unset -nocomplain def($a)
incr i
}
set opts {}
} else {
set preargs [lrange $args 0 [expr {$j-1}]]
set opts [lrange $args $j end]
}
set preargs [lmap a $preargs {my WinArg $a}]
set opts [dict merge $griddefaults $opts]
if {[dict exists $opts -in]} {
dict set opts -in [my WinArg [dict get $opts -in]]
}
concat $preargs $opts
}
method WinArg {w} {
if {[string match .* $w]} {
return $w
} else {
return [$w w]
}
expr {$i ? $a : [$a w]}
}]
concat $args [array get def]
}
method bind args {
multiargs {
{event script} {
bind [my w] $event $script
}
method bind {event argspec body args} {
oo::objdefine [self] method $event [my BindArgs $argspec] $body
oo::objdefine [self] export $event
set cmdargs [my BindCmdArgs $argspec]
bind [my w] $event [list [self] $event {*}$cmdargs {*}$args]
{event argspec body args} {
oo::objdefine [self] method $event [my BindArgs $argspec] $body
oo::objdefine [self] export $event
set cmdargs [my BindCmdArgs $argspec]
bind [my w] $event [list [self] $event {*}$cmdargs {*}$args]
}
}
}
method BindArgs {argspec} {
lmap a $argspec {
string trimleft $a %
}
}
method BindCmdArgs {argspec} {
lmap a $argspec {
if {![string match %* $a]} break
set a
}
}
method bindtags args {
tailcall bindtags [my w] {*}$args
}
method dialog {args} {
if {[llength $args]%2} {
set args [linsert $args end-1 -message]
}
if {![dict exists $args -parent]} {
dict set args -parent [my w]
}
tk_messageBox {*}$args
}
method choosefile {args} {
if {[llength $args]%2} {
set args [linsert $args 0 -type]
}
if {![dict exists $args -type]} {
throw {TCL BADARGS} "Must specify -type!"
}
switch -exact $type {
"multi" {
set cmd tk_getOpenFile
dict set args -multiple yes
}
"open" {
set cmd tk_getOpenFile
}
"save" {
set cmd tk_getSaveFile
}
"dir" - "folder" {
set cmd tk_chooseDirectory
}
}
if {![dict exists $args -parent]} {
dict set args -parent [my w]
}
$cmd {*}$args
}
variable options
method options {} {
lsort -dictionary [concat [array values options] [$w configure]]
}
method option {option resource class default verifier} {
# -commandlineswitch resourceName ResourceClass defaultValue verifier
set options($option) [list $option $resource $class $default $verifier]
# .. learn more from snit
}
method method {name argspec body} {
oo::objdefine [self] method $name $argspec $body
oo::objdefine [self] export $name
}
method variable args {
oo::objdefine [self] variable {*}$args
}
method upvar {name} { ;# this wants more arguments, but their selection is subtle
oo::objdefine [self] variable $name
set upvar [uplevel 1 namespace current]::$name
set myvar [my varname $name]
upvar 0 $upvar $myvar
return $myvar
}
method get {name} {
set [my varname $name]
method get args {
if {[llength $args] eq 1} {
set [my varname $name]
} elseif {$args eq ""} {
my getdict
} else {
throw {TCL WRONGARGS} [list [self class] get ?name?]
}
}
method set args {
foreach {name val} $args {
set [my varname $name] $val
}
}
method getdict {} {
lconcat name [info object variables [self]] {
list $name [set [my varname $name]]
}
}
method unknown {args} {
if {$args eq ""} {
return [my w]
return [self] ;#[my w]
} else {
tailcall [my w] {*}$args
}
}
}
}
if 1 {
package require Tk
# used in the "notebook class" demo
catch {rename After {}}
oo::class create After { ;# a mixin that cancels afters when the object is destroyed
variable Afters
method AfterCancel {id} {
if {[info exists Afters($id)]} {
after cancel $Afters($id)
unset Afters($id)
|
| ︙ | | |
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
|
+
+
+
+
+
+
+
+
+
+
|
foreach k [array names Afters] {
my AfterCancel $k
}
catch next ;# eww .. but it's a mixin
}
}
if 0 { ;# shell
chan configure stdin -blocking 0
chan configure stdout -buffering none
coroutine repl repl::chan stdin stdout
puts vwaiting
vwait forever
}
if 0 {
oo::class create Notebook {
variable w
constructor {} {
set w [Widget win]
w griddefauts -sticky nsew
w grid [w widget ttk::frame tabs]
w grid [w widget ttk::frame main]
|
| ︙ | | |
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
|
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
|
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
method insert {index id pane} {
}
method remove {index} {
}
method move {id index} {
}
}
oo::class create Winspector {
superclass Widget
mixin After
constructor {} {
next toplevel
# proc windowcontext {} [list return [namespace tail [self]]]
}
set demos {
"winspector" {
oo::class create Winspector {
superclass Widget
mixin After
constructor {} {
next toplevel
# proc windowcontext {} [list return [namespace tail [self]]]
#Widget create w toplevel
#oo::objdefine [self] forward w w
my variable name
my variable class
my variable bindtags
my widget label _name -textvariable name
my widget label _class -textvariable class
my widget label _bindtags -textvariable bindtags
my griddefaults -sticky nsew
my grid _name _class
my grid _bindtags -
#bind all <Enter> [namespace code {my Enter %W}]
my Refresh
}
method Refresh {} {
try {
set xy [winfo pointerxy .]
set name [winfo containing {*}$xy]
if {$name eq ""} return
# if {[string match [[self]]* $name]} return
set class [winfo class $name]
set bindtags [bindtags $name]
my set xy $xy name $name class $class bindtags $bindtags
} finally {
my After refresh 300 {my Refresh}
}
}
}
Winspector create win
}
if 0 {
Widget create t toplevel
t widget entry e1
t widget button b1 -command {puts hello}
t griddefaults -sticky nsew
t grid e1
t grid b1 ;# -weight 1
t grid [t widget button b2 -text okde]
t grid rowconfigure b1 -weight 1
t e1 insert end "lalala"
t configure b1 -text "Press me"
t bind <1> {%W %x %y a} { ;# implicitly creates a method on the object ..
puts "$W $x $y: $ack ($a)" ;# that can resolve object variables!
} five ;# remember: % args must come first!
t variable ack
t configure e1 -textvariable ack ;# ack is resolved in t's scope!
}
#Widget create w toplevel
#oo::objdefine [self] forward w w
my variable name
my variable class
my variable bindtags
my widget label _name -textvariable name
my widget label _class -textvariable class
my widget label _bindtags -textvariable bindtags
my griddefaults -sticky nsew
my grid _name _class
my grid _bindtags -
#bind all <Enter> [namespace code {my Enter %W}]
my Refresh
}
method Refresh {} {
try {
set xy [winfo pointerxy .]
set name [winfo containing {*}$xy]
if {$name eq ""} return
# if {[string match [[self]]* $name]} return
set class [winfo class $name]
set bindtags [bindtags $name]
my set xy $xy name $name class $class bindtags $bindtags
} finally {
my After refresh 300 {my Refresh}
}
}
}
Winspector create win
}
"tabs" {
Widget create notebook toplevel
notebook widget frame tabs
notebook widget frame main
set tabs [notebook tabs]
}
"basic multi-function Tk example" {
Widget create t toplevel
t widget entry e1
t widget button b1 -command {puts hello}
t griddefaults -sticky nsew
t grid e1
t grid b1 ;# -weight 1
t grid [t widget button b2 -text okde]
t grid rowconfigure b1 -weight 1
t e1 insert end "lalala"
t configure b1 -text "Press me"
t bind <1> {%W %x %y a} { ;# implicitly creates a method on the object ..
puts "$W $x $y: $ack ($a)" ;# that can resolve object variables!
} five ;# remember: % args must come first!
t variable ack
t configure e1 -textvariable ack ;# ack is resolved in t's scope!
}
"container widgets" {
Widget create t toplevel
t widget ttk::labelframe one -text "First set"
t widget entry e1
t widget checkbutton cb1 -text "Really?"
t widget ttk::labelframe two -text "Next set"
t widget entry e2
t widget checkbutton cb2 -text "are you sure?"
t grid one
t grid two
puts [t e1]
t one grid [t e1]
t one grid [t cb1]
t two grid [t e2]
t two grid [t cb2]
}
if 0 {
package require repl
chan configure stdin -blocking 0
chan configure stdout -buffering none
coroutine repl repl::chan stdin stdout
puts vwaiting
vwait forever
}
"choiceform with method upvar" {
oo::class create ChoiceForm {
variable choices
constructor {dict} {
Widget create w toplevel
w upvar choices ;# shares this variable with the Widget
dict for {k v} $dict {
set b b[incr i]
w widget checkbutton $b -text $k -variable choices($v)
w grid $b -
}
w widget button invert -command [namespace code {my Invert}] -text "Invert selections"
w widget button print -command [namespace code {my Print}] -text "Print values"
w grid invert print
}
method Invert {} {
dict for {k v} [array get choices] {
set choices($k) [expr {!$v}]
}
}
method Print {} {
parray choices
}
}
ChoiceForm create c {"One fine day" tomorrow "Never comes" around "There once was a" "little blue pony"}
}
"a basic form" {
oo::class create ::FormWidget {
superclass Widget
variable OnChange
variable Conditions
constructor args {
namespace path [linsert [namespace path] end ::ttk]
set OnChange {}
set Conditions {}
next {*}$args
}
method onchange {varname script} {
my SetTrace $varname
variable OnChange
dict set OnChange $varname $script
}
method condition {w option expr args} {
my SetTrace {} ;# hack?
variable Conditions
multiargs {
{} { set true true; set false false }
{true} { set false "" }
{true false} { }
}
dict set Conditions $expr [list w $w option $option expr $expr true $true false $false]
}
method SetTrace {varname} {
trace remove variable [my varname $varname] write "[callback my HandleTrace $varname]; --"
trace remove variable [my varname $varname] unset "[callback my SetTrace $varname]; --"
trace add variable [my varname $varname] write "[callback my HandleTrace $varname]; --"
trace add variable [my varname $varname] unset "[callback my SetTrace $varname]; --"
}
method HandleTrace {varname} {
variable Triggers
dict incr Triggers $varname
after 0 [list after idle [callback my Trigger]]
}
method Trigger {} {
variable Triggers
variable OnChange
variable Conditions
if {![info exists Triggers]} return
foreach varname [dict keys $Triggers] {
if {[dict exists $OnChange $varname]} {
my Apply [dict get $OnChange $varname]
}
dict unset Triggers $varname
}
my update
}
method update {} {
dict for {expr cond} $Conditions {
dict with cond {}
set new [expr {[my Apply expr $expr] ? $true : $false}]
set old [$w cget $option]
if {$new ne $old} {
my configure $w $option $new
}
}
}
method Apply {cmd args} {
variable {}
try [concat $cmd $args]
}
}
oo::class create ::FormBase {
variable {} ;# the form
constructor {args} {
namespace path [linsert [namespace path] end ::ttk]
proc windowcontext {} {} ;# FIXME: this is a dirty hack
FormWidget create w {*}$args ;# FIXME: use args better than just for this
#array set {} {}
w upvar {}
w method frame {name args} {
if {[llength $args] % 2} {
set script [lindex $args end]
set args [lreplace $args end end]
} else {
set script ""
}
if {[dict exists $args -text] || [dict exists $args -labelwidget]} {
set win [my widget ::ttk::labelframe $name {*}$args]
} else {
set win [my widget ::ttk::frame $name {*}$args]
}
set win [$name w]
if {$script ne ""} {
set al [my autolayout]
my autolayout {*}$al -in $win
try {
my eval $script
} finally [callback my autolayout {*}$al]
}
}
my Construct
w bind <<Submit>> [callback my Submit]
w bind <<Cancel>> [callback my Cancel]
w update
my Defaults
}
forward dialog w dialog
method buttons {script} {
w frame buttons
set w [w buttons w]
set al [w autolayout]
puts "Autolayout was: $al"
w autolayout pack -in $w -side left -expand yes -fill x
puts "Autolayout is: [w autolayout]"
try {
my eval $script
} finally [callback w autolayout {*}$al]
}
method button {text args} {
set name b$text
if {![dict exists $args -command]} {
if {$text in [info object methods [self] -all -private]} {
dict set args -command [callback my $text]
} else {
dict set args -command [callback my Return $text]
}
}
w widget button $name -text $text {*}$args
}
method Defaults {} {
variable Defaults
set Defaults [array get {}]
}
if 0 {
Window create notebook toplevel
notebook widget tabs frame
notebook widget main frame
set tabs [notebook tabs]
}
method changed? {} {
variable Defaults
dict for {k v} $Defaults {
if {$v ne $($k)} {
return true
}
}
return false
}
method Cancel {} {
if {![my changed?] || [my ConfirmCancel]} {
my Return ""
}
}
method Submit {} {
if {![my Validate]} {
# highlight errors
my dialog -type okay -message "Please complete the form before pressing Okay"
return
}
my Return [my get]
}
method ConfirmCancel {} {
my dialog -type yesno -message "Really cancel?"
}
method Validate {} {
return true
}
method wait {} { ;# wait is to be called in a coroutine
my ReturnTo [info coroutine]
return [yield]
}
method get {} {
array get {}
}
method ReturnTo {args} {
variable ReturnTo
set ReturnTo $args
}
method Return {what} {
variable ReturnTo
# after idle?
tailcall {*}$ReturnTo $what
}
}
oo::class create ::FormClass {
superclass oo::class
self method create {name script} {
set script "superclass ::FormBase; variable {}; $script"
next $name $script
}
method run {{w toplevel} args} {
set i [my new $w {*}$args]
try {
$i wait
} finally {
$i destroy
}
}
}
FormClass create Inliner {
method Construct {} {
w autolayout grid -sticky nsew
w frame wrapper -padding 10
w grid anchor wrapper center
w autolayout grid -sticky nsew -in [w wrapper w]
w eval {
my widget FilesChooser files -listvariable (files) -text "Choose HTML file" -multiple yes
my frame selections -text " Selections: " {
# the -variable args work because of [w upvar ""] in the constructor
my widget checkbutton do_toc -variable (do_toc) -text "Generate ToC"
my widget checkbutton do_js -variable (do_js) -text "Inline JS"
my widget checkbutton do_css -variable (do_css) -text "Inline CSS"
my widget checkbutton do_img -variable (do_img) -text "Inline images"
}
}
w onchange (do_js) {puts lalala:\$(do_js)}
w condition do_js -state {$(do_toc)} normal disabled
#w condition selections
set (do_toc) 0
set (do_js) 1
set (do_css) 1
set (do_img) 1
w autolayout grid -sticky nsew
my buttons {
my button "Cancel"
my button "Show"
my button Submit -text "Okay" -default active
}
}
method Show {} {
my dialog "[array get {}]"
}
}
coroutine main {*}[namespace code {
set d [Inliner run toplevel]
if {$d eq ""} {
puts "Form cancelled!"
} else {
puts "Form submitted!"
pdict $d
}
}]
catch {
source [file normalize [info script]/../../modules/inspect-0.tcl]
puts "== inspecting Inliner =="
pdict [inspect Inliner]
puts ""
}
}
}
# run demos
proc restart {} {
try {
set cmd [info_cmdline]
} on error {} {
set cmd [list [info nameofexe] $::argv0 {*}$::argv]
}
puts "Executing: $cmd"
exec {*}$cmd &
exit
}
proc run_demo {key} {
set script [dict get $::demos $key]
catch {namespace delete ::demo}
namespace eval ::demo {}
apply [list {} $script ::demo]
}
if 1 {
package require tkcon
tkcon show
}
if {$::argv eq ""} {
Widget create main . ;# adopt the root window
main griddefaults -sticky nsew
set i 0
dict for {label script} $demos {
main widget button b[incr i] -text $label -command [list run_demo $label]
main grid b$i
}
main grid [main widget button bRestart -text "Restart" -command restart]
main grid [main widget button bQuit -text "Quit" -command exit]
} else {
coroutine main apply {{} {
foreach a $::argv {
foreach k [dict keys $::demos $a] {
puts "** running demo: \"$a\""
run_demo $a
yieldto after 1000 [info coroutine]
}
}
}}
}
|
Added hacks/aes-test.tcl.