From bc5e203f7787980f65f81ddbf69a619ab34fa85e Mon Sep 17 00:00:00 2001 From: "N.N." Date: Tue, 9 Mar 2004 12:41:22 +0000 Subject: toxy alpha6 svn path=/trunk/externals/miXed/; revision=1396 --- test/toxy/button-test.pd | 3 + test/toxy/default.wid | 235 ------------------------------------- test/toxy/kb-test.pd | 18 +-- test/toxy/kb.wid | 8 +- test/toxy/listbox-test.pd | 38 +++--- test/toxy/multiscale-test.pd | 20 ++++ test/toxy/multiscale.wid | 39 +++++++ test/toxy/popcustom-test.pd | 39 +++++++ test/toxy/popup-test.pd | 90 +++++++------- test/toxy/setup.wid | 272 +++++++++++++++++++++++++++++++++++++++++++ test/toxy/stress/pophurd.pd | 84 +++++++++++++ test/toxy/tclversion.pd | 29 +++-- 12 files changed, 563 insertions(+), 312 deletions(-) delete mode 100644 test/toxy/default.wid create mode 100644 test/toxy/multiscale-test.pd create mode 100644 test/toxy/multiscale.wid create mode 100644 test/toxy/popcustom-test.pd create mode 100644 test/toxy/setup.wid create mode 100644 test/toxy/stress/pophurd.pd (limited to 'test') diff --git a/test/toxy/button-test.pd b/test/toxy/button-test.pd index b37978b..26e181b 100644 --- a/test/toxy/button-test.pd +++ b/test/toxy/button-test.pd @@ -22,6 +22,8 @@ red -command .<.>; $c "-text" $c.>.); #X obj 294 268 loadbang; #X msg 294 295 ini .- config -textvariable ""; +#X obj 250 21 widget button bb -bg green -activebackground yellow +-command .<.> ; #X connect 0 0 3 0; #X connect 1 0 0 0; #X connect 2 0 0 0; @@ -39,3 +41,4 @@ $c "-text" $c.>.); #X connect 16 0 0 0; #X connect 17 0 18 0; #X connect 18 0 0 0; +#X connect 19 0 10 0; diff --git a/test/toxy/default.wid b/test/toxy/default.wid deleted file mode 100644 index c7898af..0000000 --- a/test/toxy/default.wid +++ /dev/null @@ -1,235 +0,0 @@ -# LATER transfer the `standard' toxy setup definitions into a tcl package -# LATER think about using a slave interpreter, and a toxy-specific connection - -# LATER ask for adding something of the sort to pd.tk: -bind Canvas <1> {+focus %W} - -# In order to keep the state after our canvas has been destroyed -# (i.e. our subpatch closed) -- use 'store' and 'restore' handlers, -# if defined, otherwise try setting -variable and -textvariable traces. - -proc ::toxy::itemdotrace {target varname ndxname op} { - if {[catch {set v [set $varname]}] == 0} { - if {$v != [set $varname.last]} { -# FIXME activate this on demand (for explicit traces) -# pd $target.rp _value $v \; - set $varname.last $v - } - } else { puts stderr [concat failed ::toxy::itemdotrace] } -} - -proc ::toxy::itembindtrace {varname mastername ndxname op} { - set $varname [set $mastername] -} - -proc ::toxy::itemsettrace {op path target varname} { - if {[catch {$path cget $op} res] == 0} { - if {$res == ""} { - if {[catch {$path config $op $varname} err]} { - error $err - } - } else { - if {[info tclversion] < 8.4} { - trace variable $res w "::toxy::itembindtrace $varname" - } else { - trace add variable $res write "::toxy::itembindtrace $varname" - } - } - if {![info exists $varname.last]} { set $varname.last "" } - if {[info tclversion] < 8.4} { - trace variable $varname w "::toxy::itemdotrace $target" - } else { - trace add variable $varname write "::toxy::itemdotrace $target" - } - return - } else { return 0 } -} - -# LATER revisit -- seems clumsy and fragile -proc ::toxy::itemremovetrace {op path varname} { - if {[catch {$path cget $op} res] == 0} { - if {$res == $varname} { - if {[catch {$path config $op ""} err]} { - error $err - } - } elseif {$res != ""} { - if {[info tclversion] < 8.4} { - catch { trace vdelete $res w "::toxy::itembindtrace $varname" } - } else { - catch { trace remove variable \ - $res write "::toxy::itembindtrace $varname" } - } - } - } -} - -proc ::toxy::itemdestroy {path varname} { - ::toxy::itemremovetrace -variable $path $varname.var - ::toxy::itemremovetrace -textvariable $path $varname.txt - if {[info tclversion] < 8.4} { - catch { unset $varname.last $varname.var $varname.txt $varname } - } else { - unset -nocomplain $varname.last $varname.var $varname.txt $varname - } - catch {destroy $path} -} - -proc ::toxy::itemgetconfig {path target} { - pd $target.rp _config $target.rp [$path cget -bg] \ - [winfo reqwidth $path] [winfo reqheight $path] \ - [catch {$path config -state normal}]\; -} - -proc ::toxy::itemvisconfig {path target name varname cvpath px py} { - if {[info exists ::toxy::itemoptions]} { - catch {eval $path config $::toxy::itemoptions} - unset ::toxy::itemoptions - } - - $cvpath create window $px $py \ - -anchor nw -window $path -tags [concat toxy$name $target] - -# FIXME - if {[info exists ::toxy::storethispath]} { -# FIXME explicit traces - set needtraces 0 - } else { - set needtraces 1 - } - - if {$needtraces != 0} { - if {[catch {::toxy::itemsettrace -variable \ - $path $target $varname.var} res1]} { - error $res1 - } - if {[catch {::toxy::itemsettrace -textvariable \ - $path $target $varname.txt} res2]} { - error $res2 - } -# puts stderr [concat traces: ($res1) ($res2)] - if {$res1 == 0 && $res2 == 0} { -# puts stderr [concat toxy warning: $path untraceable] - } - } - - if {[info exists ::toxy::masterinits]} { - catch {eval $::toxy::masterinits} - unset ::toxy::masterinits - } - if {[info exists ::toxy::typeinits]} { - catch {eval $::toxy::typeinits} - unset ::toxy::typeinits - } - if {[info exists ::toxy::iteminits]} { - catch {eval $::toxy::iteminits} - unset ::toxy::iteminits - } - - ::toxy::itemgetconfig $path $target - - return -} - -proc ::toxy::itemvis {tkclass path target name varname cvpath px py} { - if {[winfo exists $path]} { -# puts [concat $path exists] - set ::toxy::itemfailure 0 - } else { - set ::toxy::itemfailure [catch {$tkclass $path} ::toxy::itemerrmess] - } - if {$::toxy::itemfailure == 0} { - set ::toxy::itemfailure [catch {::toxy::itemvisconfig \ - $path $target $name $varname $cvpath $px $py} \ - ::toxy::itemerrmess] - } - if {$::toxy::itemfailure} { - if {[winfo exists $path]} {destroy $path} - pd $target.rp _failure $::toxy::itemerrmess \; - } -} - -proc ::toxy::itemclick {target cvpath x y b f} { - pd $target.rp _click \ - [$cvpath canvasx [expr $x - [winfo rootx $cvpath]]] \ - [$cvpath canvasy [expr $y - [winfo rooty $cvpath]]] $b $f\; -} - -# FIXME -proc ::toxy::scalecommand {target sel v} { - pd [concat $target $sel $v \;] -} - -proc ::toxy::popupcommand {path target remote i text} { - set [$path cget -textvariable] $text - pd [concat $target _cb $i \;] - if {$remote != "."} { - pd [concat $remote $i \;] - } -} - -proc ::toxy::popup {path target remote entries args} { - eval {menu $path.pop} $args - set i 1 - foreach e $entries { - $path.pop add command -label [lindex $e 0] \ - -command [concat ::toxy::popupcommand $path $target $remote $i \ - [lindex $e [expr {[llength $e] > 1}]]] - incr i - } -} - -# the default initializer -#> default - -# empirically, binding event coords as %X - [winfo rootx .^.c] works better, -# than %x + [winfo x %W], or %x + t->te_xpix, LATER investigate - -# pdtk_canvas_mouseup is a hack, which we must call anyway -bind .- { - eval .<|_inout 3.> - pdtk_canvas_mouseup .^.c \ - [expr %X - [winfo rootx .^.c]] [expr %Y - [winfo rooty .^.c]] %b -} - -bind .- <1> {::toxy::itemclick .| .^.c %X %Y %b 0} -bind .- {::toxy::itemclick .| .^.c %X %Y %b 1} -bind .- {::toxy::itemclick .| .^.c %X %Y %b 2} -bind .- {::toxy::itemclick .| .^.c %X %Y %b 3} -bind .- {::toxy::itemclick .| .^.c %X %Y %b 4} -bind .- {::toxy::itemclick .| .^.c %X %Y %b 5} -bind .- {::toxy::itemclick .| .^.c %X %Y %b 6} -bind .- {::toxy::itemclick .| .^.c %X %Y %b 7} -bind .- <3> {::toxy::itemclick .| .^.c %X %Y %b 8} - -bind .- .<|_motion \ - [.^.c canvasx [expr %X - [winfo rootx .^.c]]] \ - [.^.c canvasy [expr %Y - [winfo rooty .^.c]]] 0.> -bind .- .<|_inout 1.> -bind .- .<|_inout 0.> - -# standard widget types - -#> bang button -#. -image ::toxy::img::empty -command .<.> -#. -bg pink -activebackground red -width 50 -height 50 -#. @bang .- flash .: .- invoke - -#> float scale -#. -command [concat ::toxy::scalecommand .| _cb] -#. -bg pink -activebackground red -length 200 -#. @float .- set .#1 - -#> symbol entry -#. -bg pink -font .(helvetica 24.) -width 16 -#. @symbol .- delete 0 end .: .- insert 0 .#1 - -bind .- {eval .<[.- get].>; focus .^.c} - -#> popup menubutton -#. -menu .-.pop -#. -bg purple -fg white -activebackground magenta -width 8 -text popup -#. @float if .(.#1 >= 1.) .(.-.pop invoke .#1.) -#. #items test -#. #iprops "-bg" purple "-fg" white "-activebackground" magenta - -::toxy::popup .- .| . [concat .#items] .#iprops diff --git a/test/toxy/kb-test.pd b/test/toxy/kb-test.pd index 2978dce..22df275 100644 --- a/test/toxy/kb-test.pd +++ b/test/toxy/kb-test.pd @@ -1,17 +1,21 @@ #N canvas 354 116 645 486 12; -#X obj 37 61 widget kb k1; +#X obj 37 59 widget kb k1; #X floatatom 37 160 5 0 0 0 - - -; -#X obj 37 310 widget kb k2 #oct 8 #size 0.35 -bg red; +#X obj 37 310 widget kb k2 #oct 10 #size 0.35 -bg red; #X floatatom 37 369 5 0 0 0 - - -; -#X msg 120 271 #oct \$1 \, refresh; #X floatatom 120 237 5 0 0 0 - - -; #X floatatom 37 24 5 0 0 0 - - -; #X msg 114 24 bang; #X floatatom 37 237 5 0 0 0 - - -; +#X floatatom 205 237 5 0 0 0 - - -; +#X msg 205 271 #size \$1; +#X msg 120 271 #oct \$1; #X connect 0 0 1 0; #X connect 2 0 3 0; -#X connect 4 0 2 0; -#X connect 5 0 4 0; +#X connect 4 0 10 0; +#X connect 5 0 0 0; #X connect 6 0 0 0; -#X connect 7 0 0 0; -#X connect 8 0 2 0; +#X connect 7 0 2 0; +#X connect 8 0 9 0; +#X connect 9 0 2 0; +#X connect 10 0 2 0; diff --git a/test/toxy/kb.wid b/test/toxy/kb.wid index e447697..9a64d70 100644 --- a/test/toxy/kb.wid +++ b/test/toxy/kb.wid @@ -1,10 +1,10 @@ proc ::toxy::kb {path target remote noctaves size} { set lft [expr {round(5 * $size)}] - set top [expr {5 * $size}] - set bot [expr {100 * $size}] + set top [expr {round(5 * $size)}] + set bot [expr {round(100 * $size)}] set dx [expr {round(17 * $size)}] - set wid [expr {$dx - $size * .5}] - set blbot [expr {$bot * .65}] + set wid [expr {round($dx - $size * .5)}] + set blbot [expr {round($bot * .65)}] $path config -height [expr {$bot + $top}] \ -width [expr {$dx * ($noctaves * 7 + 1) + $lft * 2 - 1}] diff --git a/test/toxy/listbox-test.pd b/test/toxy/listbox-test.pd index cd1fa46..751fb58 100644 --- a/test/toxy/listbox-test.pd +++ b/test/toxy/listbox-test.pd @@ -1,18 +1,24 @@ -#N canvas 154 52 626 383 12; -#X obj 281 144 widget listbox lb -width 32 -height 12 -bg black -fg -white; -#X obj 20 282 tow . listbox lb; -#X obj 20 21 loadbang; -#X msg 20 52 ini foreach fn [lsort [glob *]] .(.- insert end $fn.) -; -#X obj 236 143 widget button b -text ok -height 14 -bg black -fg white +#N canvas 445 76 626 425 12; +#X obj 281 179 widget listbox lb -width 32 -height 12 -bg black -fg +white @bang ::toxy::lbcommand .- .|; +#X obj 20 295 tow . listbox lb; +#X obj 20 23 loadbang; +#X obj 236 179 widget button b -text ok -height 1 -bg black -fg white -command .<.>; -#X obj 112 21 tow . button b; -#X msg 36 83 tot if .([.- curselection] != "".) .(eval ..); -#X msg 20 324; -#X connect 1 0 7 0; -#X connect 2 0 3 0; -#X connect 3 0 1 0; -#X connect 5 0 6 0; +#X obj 84 179 tow . button b; +#X msg 20 337; +#X msg 54 257 tot puts [.- size]; +#X msg 44 222 tot .- delete 0 end; +#X msg 33 179 bang; +#X msg 20 57 tot proc ::toxy::lbcommand .(path target.) .(if .([$path +curselection] != "".) .(pd [concat $target _cb set [$path get [$path +curselection]] .`.:].).) \, ini if .([.- size] == 0.) .(foreach fn +[lsort [glob *]] .(.- insert end $fn.) .: bind .- +.(::toxy::lbcommand .- .|.).) \, @bang ::toxy::lbcommand .- .|; +#X connect 1 0 5 0; +#X connect 2 0 9 0; +#X connect 4 0 1 0; #X connect 6 0 1 0; +#X connect 7 0 1 0; +#X connect 8 0 1 0; +#X connect 9 0 1 0; diff --git a/test/toxy/multiscale-test.pd b/test/toxy/multiscale-test.pd new file mode 100644 index 0000000..c0383a6 --- /dev/null +++ b/test/toxy/multiscale-test.pd @@ -0,0 +1,20 @@ +#N canvas 39 49 775 469 12; +#X obj 27 98 widget multiscale m1 #n 30 #dx 15 #dy 60; +#X obj 27 200 widget multiscale m2 #bg red #dy 120; +#X obj 188 371 tow . multiscale m1; +#X msg 27 59 #n \$1; +#X floatatom 27 24 5 0 0 0 - - -; +#N canvas 0 0 450 300 graph1 0; +#X array t 50 float 0; +#X coords 0 1 49 0 400 140 1; +#X restore 296 206 graph; +#X obj 188 410 tabwrite t; +#X obj 27 367 unpack; +#X floatatom 27 411 5 0 0 0 - - -; +#X floatatom 100 411 5 0 0 0 - - -; +#X connect 1 0 7 0; +#X connect 2 0 6 0; +#X connect 3 0 0 0; +#X connect 4 0 3 0; +#X connect 7 0 8 0; +#X connect 7 1 9 0; diff --git a/test/toxy/multiscale.wid b/test/toxy/multiscale.wid new file mode 100644 index 0000000..f66ef6c --- /dev/null +++ b/test/toxy/multiscale.wid @@ -0,0 +1,39 @@ +proc ::toxy::multiscalecommand {target sel ndx v} { + pd [concat $target $sel $v $ndx \;] +} + +proc ::toxy::multiscale {path target remote count dx dy bg} { + if {[winfo exists $path.s0]} { +# puts stderr [concat $path.s0 exists] + } else { + set width [expr {$count * $dx + 10}] + set height [expr {$dy + 10}] + $path config -width $width -height $height -bg $bg + set px 5 + set py 5 + for {set ndx 0} {$ndx < $count} {incr ndx} { + scale $path.s$ndx -width $dx -length $dy \ + -from 1 -to 0 -resolution 0.01 \ + -bg $bg -highlightthickness 0 \ + -command [concat ::toxy::multiscalecommand $target _cb $ndx] + if {$dx < 50} { + $path.s$ndx config -showvalue 0 -relief flat + } else { + $path.s$ndx config -digits 3 -relief sunken + } + set id [$path create window $px $py -width $dx -height $dy \ + -anchor nw -window $path.s$ndx -tags $path.s$ndx] + ::toxy::masterinit $path.s$ndx $target $path + incr px $dx + } + } +} + +#> multiscale canvas +#. #n 3 #dx 60 #dy 90 +#. #bg yellow + +::toxy::multiscale .- .| . .#n .#dx .#dy .#bg + +# undo the "bind Canvas <1> {+focus %W}" in the setup part above +bind .- {focus .^.c} diff --git a/test/toxy/popcustom-test.pd b/test/toxy/popcustom-test.pd new file mode 100644 index 0000000..7f49162 --- /dev/null +++ b/test/toxy/popcustom-test.pd @@ -0,0 +1,39 @@ +#N canvas 356 9 338 241 12; +#X obj 38 104 r rpop; +#X floatatom 38 142 5 0 0 0 - - -; +#X floatatom 120 142 5 0 0 0 - - -; +#X obj 120 104 r rpop1; +#X floatatom 210 142 5 0 0 0 - - -; +#X obj 210 104 r rpop2; +#N canvas 12 11 293 279 blackpanel 1; +#X obj 23 111 widget menubutton mb -menu .-.pop -bg green -activebackground +yellow -width 5 -text one @float if .(.#1 >= 1.) .(.-.pop invoke .#1.) +; +#X obj 23 12 loadbang; +#X obj 96 110 widget pop1 p1; +#X obj 188 110 widget pop2 p2; +#X msg 23 41 ini ::toxy::popup .- .| rpop [list one two three four five] +-bg green -activebackground yellow .: destroy .^.m .: .^.scrollvert +configure -width 0 .: .^.scrollhort configure -width 0 .: .^.c configure +-bg black; +#X obj 23 150 r topop; +#X obj 96 150 r topop1; +#X obj 188 150 r topop2; +#X connect 1 0 4 0; +#X connect 4 0 0 0; +#X connect 5 0 0 0; +#X connect 6 0 2 0; +#X connect 7 0 3 0; +#X restore 95 198 pd blackpanel; +#X floatatom 38 24 5 0 0 0 - - -; +#X floatatom 120 24 5 0 0 0 - - -; +#X floatatom 210 24 5 0 0 0 - - -; +#X obj 38 58 s topop; +#X obj 120 58 s topop1; +#X obj 210 58 s topop2; +#X connect 0 0 1 0; +#X connect 3 0 2 0; +#X connect 5 0 4 0; +#X connect 7 0 10 0; +#X connect 8 0 11 0; +#X connect 9 0 12 0; diff --git a/test/toxy/popup-test.pd b/test/toxy/popup-test.pd index 7f49162..ff8df82 100644 --- a/test/toxy/popup-test.pd +++ b/test/toxy/popup-test.pd @@ -1,39 +1,51 @@ -#N canvas 356 9 338 241 12; -#X obj 38 104 r rpop; -#X floatatom 38 142 5 0 0 0 - - -; -#X floatatom 120 142 5 0 0 0 - - -; -#X obj 120 104 r rpop1; -#X floatatom 210 142 5 0 0 0 - - -; -#X obj 210 104 r rpop2; -#N canvas 12 11 293 279 blackpanel 1; -#X obj 23 111 widget menubutton mb -menu .-.pop -bg green -activebackground -yellow -width 5 -text one @float if .(.#1 >= 1.) .(.-.pop invoke .#1.) -; -#X obj 23 12 loadbang; -#X obj 96 110 widget pop1 p1; -#X obj 188 110 widget pop2 p2; -#X msg 23 41 ini ::toxy::popup .- .| rpop [list one two three four five] --bg green -activebackground yellow .: destroy .^.m .: .^.scrollvert -configure -width 0 .: .^.scrollhort configure -width 0 .: .^.c configure --bg black; -#X obj 23 150 r topop; -#X obj 96 150 r topop1; -#X obj 188 150 r topop2; -#X connect 1 0 4 0; -#X connect 4 0 0 0; -#X connect 5 0 0 0; -#X connect 6 0 2 0; -#X connect 7 0 3 0; -#X restore 95 198 pd blackpanel; -#X floatatom 38 24 5 0 0 0 - - -; -#X floatatom 120 24 5 0 0 0 - - -; -#X floatatom 210 24 5 0 0 0 - - -; -#X obj 38 58 s topop; -#X obj 120 58 s topop1; -#X obj 210 58 s topop2; -#X connect 0 0 1 0; -#X connect 3 0 2 0; -#X connect 5 0 4 0; -#X connect 7 0 10 0; -#X connect 8 0 11 0; -#X connect 9 0 12 0; +#N canvas 80 56 700 405 12; +#X obj 17 17 widget popup p #items [.- config] -width 20; +#X obj 20 130 tow . popup p; +#X floatatom 20 71 5 0 0 0 - - -; +#X obj 437 287 tow . popup q; +#X obj 271 17 widget popup q -width 40; +#X obj 20 208 t 0 0; +#X obj 150 130 r rdefault; +#X msg 55 249 list rdefault \$1 3; +#X msg 20 287 list rcurrent \$1 4; +#X msg 89 71 tot pd [concat \$1 set [lindex [.- config [lindex [lindex +[.- config] \$2] 0]] \$3] .`.:]; +#X obj 20 170 - 1; +#X obj 331 130 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 +1; +#X obj 405 130 r rcurrent; +#X msg 150 170; +#X msg 405 170; +#X obj 225 213 route set; +#X obj 331 249 random 20; +#X msg 437 249 tot .-.pop add separator; +#X msg 225 330 tot .-.pop add command -label \$1 .: set [.- cget -textvariable] +\$1; +#X obj 490 208 sel 1; +#X obj 331 170 t 0 0; +#X obj 331 208 metro 500; +#X obj 225 249 route float; +#X obj 308 287 symbol; +#X connect 1 0 10 0; +#X connect 2 0 1 0; +#X connect 5 0 8 0; +#X connect 5 1 7 0; +#X connect 6 0 13 0; +#X connect 7 0 9 0; +#X connect 8 0 9 0; +#X connect 9 0 1 0; +#X connect 10 0 5 0; +#X connect 11 0 20 0; +#X connect 12 0 14 0; +#X connect 12 0 15 0; +#X connect 15 0 22 0; +#X connect 16 0 8 0; +#X connect 17 0 3 0; +#X connect 18 0 3 0; +#X connect 19 0 17 0; +#X connect 20 0 21 0; +#X connect 20 1 19 0; +#X connect 21 0 16 0; +#X connect 22 0 18 0; +#X connect 22 1 23 0; +#X connect 23 0 18 0; diff --git a/test/toxy/setup.wid b/test/toxy/setup.wid new file mode 100644 index 0000000..9f66b61 --- /dev/null +++ b/test/toxy/setup.wid @@ -0,0 +1,272 @@ +# LATER transfer the `standard' toxy setup definitions into a tcl package +# LATER think about using a slave interpreter, and a toxy-specific connection +# LATER gather aqua incompatibilities, and decide, if there is no other +# way than branching (different meaning of -bg, -borderwidth trouble, +# right click, etc.) + +# LATER ask for adding something of the sort to pd.tk: +bind Canvas <1> {+focus %W} + +# In order to keep the state after our canvas has been destroyed +# (i.e. our subpatch closed) -- use 'store' and 'restore' handlers, +# if defined, otherwise try setting -variable and -textvariable traces. + +proc ::toxy::itemdotrace {target varname ndxname op} { + if {[catch {set v [set $varname]} res] == 0} { + if {$v != [set $varname.last]} { +# FIXME activate this on demand (for explicit traces) +# pd $target.rp _value $v \; + set $varname.last $v + } + } else { puts stderr [concat failed ::toxy::itemdotrace: $res] } +} + +proc ::toxy::itembindtrace {varname mastername ndxname op} { + set $varname [set $mastername] +} + +proc ::toxy::itemsettrace {op path target varname} { + if {[catch {$path cget $op} res] == 0} { + if {$res == ""} { + if {[catch {$path config $op $varname} err]} { + error $err + } + } else { + if {[info tclversion] < 8.4} { + trace variable $res w "::toxy::itembindtrace $varname" + } else { + trace add variable $res write "::toxy::itembindtrace $varname" + } + } + if {![info exists $varname.last]} { set $varname.last "" } + if {[info tclversion] < 8.4} { + trace variable $varname w "::toxy::itemdotrace $target" + } else { + trace add variable $varname write "::toxy::itemdotrace $target" + } + return + } else { return 0 } +} + +# LATER revisit -- seems clumsy and fragile +proc ::toxy::itemremovetrace {op path varname} { + if {[catch {$path cget $op} res] == 0} { + if {$res == $varname} { + if {[catch {$path config $op ""} err]} { + error $err + } + } elseif {$res != ""} { + if {[info tclversion] < 8.4} { + catch { trace vdelete $res w "::toxy::itembindtrace $varname" } + } else { + catch { trace remove variable \ + $res write "::toxy::itembindtrace $varname" } + } + } + } +} + +proc ::toxy::itemdestroy {path varname} { + ::toxy::itemremovetrace -variable $path $varname.var + ::toxy::itemremovetrace -textvariable $path $varname.txt + if {[info tclversion] < 8.4} { + catch { unset $varname.last $varname.var $varname.txt $varname } + } else { + unset -nocomplain $varname.last $varname.var $varname.txt $varname + } + catch {destroy $path} +} + +proc ::toxy::itemgetconfig {path target} { + pd $target.rp _config $target.rp [$path cget -bg] \ + [winfo reqwidth $path] [winfo reqheight $path] \ + [catch {$path config -state normal}]\; +} + +proc ::toxy::itemvisconfig {path target name varname cvpath px py} { + if {[info exists ::toxy::itemoptions]} { + set failed [catch {eval $path config $::toxy::itemoptions} res] + unset ::toxy::itemoptions + if {$failed} { error [concat in $path config: $res] } + } + + $cvpath create window $px $py \ + -anchor nw -window $path -tags [concat toxy$name $target] + +# FIXME + if {[info exists ::toxy::storethispath]} { +# FIXME explicit traces + set needtraces 0 + } else { + set needtraces 1 + } + + if {$needtraces != 0} { + if {[catch {::toxy::itemsettrace -variable \ + $path $target $varname.var} res1]} { + error [concat in ::toxy::itemsettrace: $res1] + } + if {[catch {::toxy::itemsettrace -textvariable \ + $path $target $varname.txt} res2]} { + error [concat in ::toxy::itemsettrace: $res2] + } +# puts stderr [concat traces: ($res1) ($res2)] + if {$res1 == 0 && $res2 == 0} { +# puts stderr [concat toxy warning: $path untraceable] + } + } + + if {[info exists ::toxy::masterinits]} { + set failed [catch {eval $::toxy::masterinits} res] + unset ::toxy::masterinits + if {$failed} { error [concat in ::toxy::masterinits: $res] } + } + if {[info exists ::toxy::typeinits]} { + set failed [catch {eval $::toxy::typeinits} res] + unset ::toxy::typeinits + if {$failed} { error [concat in ::toxy::typeinits: $res] } + } + if {[info exists ::toxy::iteminits]} { + set failed [catch {eval $::toxy::iteminits} res] + unset ::toxy::iteminits + if {$failed} { error [concat in ::toxy::iteminits: $res] } + } + + ::toxy::itemgetconfig $path $target + + return +} + +proc ::toxy::itemvis {tkclass path target name varname cvpath px py} { + if {[winfo exists $path]} { +# puts stderr [concat $path exists] + set ::toxy::itemfailure 0 + } else { + set ::toxy::itemfailure [catch {$tkclass $path} ::toxy::itemerrmess] + } + if {$::toxy::itemfailure == 0} { + set ::toxy::itemfailure [catch {::toxy::itemvisconfig \ + $path $target $name $varname $cvpath $px $py} \ + ::toxy::itemerrmess] + } + if {$::toxy::itemfailure} { + if {[winfo exists $path]} {destroy $path} + puts stderr [concat tcl error: $::toxy::itemerrmess] + pd $target.rp _failure \; + } +} + +# FIXME +proc ::toxy::scalecommand {target sel v} { + pd [concat $target $sel $v \;] +} + +proc ::toxy::popupcommand {path target remote i text} { + set [$path cget -textvariable] $text + pd [concat $target _cb $i \;] + if {$remote != "."} { + pd [concat $remote $i \;] + } +} + +proc ::toxy::popup {path target remote entries args} { + if {[winfo exists $path.pop]} { +# puts stderr [concat $path.pop exists] + } elseif {[catch {eval {menu $path.pop} $args} err] == 0} { + set i 0 + foreach e $entries { + if {$e == "."} { + $path.pop add separator + } else { + incr i + $path.pop add command -label [lindex $e 0] \ + -command [concat ::toxy::popupcommand \ + $path $target $remote $i \ + [lindex $e [expr {[llength $e] > 1}]]] + } + } + } else { error [concat in ::toxy::popup: $err] } +} + +# empirically, binding event coords as %X - [winfo rootx $cvpath] works +# better, than %x + [winfo x %W], or %x + t->te_xpix, LATER investigate + +proc ::toxy::itemclick {target cvpath x y b f} { + pd $target.rp _click \ + [$cvpath canvasx [expr {$x - [winfo rootx $cvpath]}]] \ + [$cvpath canvasy [expr {$y - [winfo rooty $cvpath]}]] $b $f\; +} + +proc ::toxy::iteminout {target v} { + pd [concat $target.rp _inout $v \;] +} + +proc ::toxy::masterrelease {target cvpath x y b} { + ::toxy::iteminout $target 3 +# pdtk_canvas_mouseup is a hack, which we must call anyway + pdtk_canvas_mouseup $cvpath \ + [expr {$x - [winfo rootx $cvpath]}] \ + [expr {$y - [winfo rooty $cvpath]}] $b +} + +proc ::toxy::mastermotion {target cvpath x y} { + pd $target.rp _motion \ + [$cvpath canvasx [expr {$x - [winfo rootx $cvpath]}]] \ + [$cvpath canvasy [expr {$y - [winfo rooty $cvpath]}]] 0 \; +} + +proc ::toxy::masterinit {path target cvpath} { + set topitem [expr {[string index $cvpath end-1] == "."}] +# FIXME subitem handling + if {$topitem} { + bind $path \ + "::toxy::masterrelease $target $cvpath %X %Y %b" + } + bind $path <1> "::toxy::itemclick $target $cvpath %X %Y %b 0" + bind $path "::toxy::itemclick $target $cvpath %X %Y %b 1" + bind $path "::toxy::itemclick $target $cvpath %X %Y %b 2" + bind $path "::toxy::itemclick $target $cvpath %X %Y %b 3" + bind $path "::toxy::itemclick $target $cvpath %X %Y %b 4" + bind $path "::toxy::itemclick $target $cvpath %X %Y %b 5" + bind $path "::toxy::itemclick $target $cvpath %X %Y %b 6" + bind $path \ + "::toxy::itemclick $target $cvpath %X %Y %b 7" + bind $path <3> "::toxy::itemclick $target $cvpath %X %Y %b 8" + + bind $path "::toxy::mastermotion $target $cvpath %X %Y" + bind $path "::toxy::iteminout $target 1" + bind $path "::toxy::iteminout $target 0" +} + +# master initializer +#> master + +::toxy::masterinit .- .| .^.c + +# standard widget types + +#> bang button +#. -image ::toxy::img::empty -command .<.> +#. -bg pink -activebackground red -width 50 -height 50 +#. @bang .- flash .: .- invoke + +#> float scale +#. -command [concat ::toxy::scalecommand .| _cb] +#. -bg pink -activebackground red -length 200 +#. @float .- set .#1 + +#> symbol entry +#. -bg pink -font .(helvetica 24.) -width 16 +#. @symbol .- delete 0 end .: .- insert 0 .#1 + +bind .- {eval .<[.- get].>; focus .^.c} + +#> popup menubutton +#. -menu .-.pop +#. -bg purple -fg white -activebackground magenta -text popup +#. -width 8 -relief raised -borderwidth 3 +#. @float if .(.#1 >= 1.) .(.-.pop invoke .#1.) +#. #items test +#. #iprops "-bg" purple "-fg" white "-activebackground" magenta "-borderwidth" 3 + +::toxy::popup .- .| . [concat .#items] .#iprops diff --git a/test/toxy/stress/pophurd.pd b/test/toxy/stress/pophurd.pd new file mode 100644 index 0000000..0a55222 --- /dev/null +++ b/test/toxy/stress/pophurd.pd @@ -0,0 +1,84 @@ +#N canvas 151 100 700 416 12; +#X obj 16 47 tow . popup p; +#X floatatom 16 15 5 0 0 0 - - -; +#X floatatom 16 84 5 0 0 0 - - -; +#X obj 180 10 widget popup p #items [info globals]; +#X obj 260 10 widget popup p #items [info globals]; +#X obj 340 10 widget popup p #items [info globals]; +#X obj 420 10 widget popup p #items [info globals]; +#X obj 500 10 widget popup p #items [info globals]; +#X obj 580 10 widget popup p #items [info globals]; +#X obj 180 40 widget popup p #items [info globals]; +#X obj 260 40 widget popup p #items [info globals]; +#X obj 340 40 widget popup p #items [info globals]; +#X obj 420 40 widget popup p #items [info globals]; +#X obj 500 40 widget popup p #items [info globals]; +#X obj 580 40 widget popup p #items [info globals]; +#X obj 180 70 widget popup p #items [info globals]; +#X obj 260 70 widget popup p #items [info globals]; +#X obj 340 70 widget popup p #items [info globals]; +#X obj 420 70 widget popup p #items [info globals]; +#X obj 500 70 widget popup p #items [info globals]; +#X obj 580 70 widget popup p #items [info globals]; +#X obj 180 100 widget popup p #items [info globals]; +#X obj 260 100 widget popup p #items [info globals]; +#X obj 340 100 widget popup p #items [info globals]; +#X obj 420 100 widget popup p #items [info globals]; +#X obj 500 100 widget popup p #items [info globals]; +#X obj 580 100 widget popup p #items [info globals]; +#X obj 180 130 widget popup p #items [info globals]; +#X obj 260 130 widget popup p #items [info globals]; +#X obj 340 130 widget popup p #items [info globals]; +#X obj 420 130 widget popup p #items [info globals]; +#X obj 500 130 widget popup p #items [info globals]; +#X obj 580 130 widget popup p #items [info globals]; +#X obj 180 160 widget popup p #items [info globals]; +#X obj 260 160 widget popup p #items [info globals]; +#X obj 340 160 widget popup p #items [info globals]; +#X obj 420 160 widget popup p #items [info globals]; +#X obj 500 160 widget popup p #items [info globals]; +#X obj 580 160 widget popup p #items [info globals]; +#X obj 180 190 widget popup p #items [info globals]; +#X obj 260 190 widget popup p #items [info globals]; +#X obj 340 190 widget popup p #items [info globals]; +#X obj 420 190 widget popup p #items [info globals]; +#X obj 500 190 widget popup p #items [info globals]; +#X obj 580 190 widget popup p #items [info globals]; +#X obj 180 220 widget popup p #items [info globals]; +#X obj 260 220 widget popup p #items [info globals]; +#X obj 340 220 widget popup p #items [info globals]; +#X obj 420 220 widget popup p #items [info globals]; +#X obj 500 220 widget popup p #items [info globals]; +#X obj 580 220 widget popup p #items [info globals]; +#X obj 180 250 widget popup p #items [info globals]; +#X obj 260 250 widget popup p #items [info globals]; +#X obj 340 250 widget popup p #items [info globals]; +#X obj 420 250 widget popup p #items [info globals]; +#X obj 500 250 widget popup p #items [info globals]; +#X obj 580 250 widget popup p #items [info globals]; +#X obj 180 280 widget popup p #items [info globals]; +#X obj 260 280 widget popup p #items [info globals]; +#X obj 340 280 widget popup p #items [info globals]; +#X obj 420 280 widget popup p #items [info globals]; +#X obj 500 280 widget popup p #items [info globals]; +#X obj 580 280 widget popup p #items [info globals]; +#X obj 180 310 widget popup p #items [info globals]; +#X obj 260 310 widget popup p #items [info globals]; +#X obj 340 310 widget popup p #items [info globals]; +#X obj 420 310 widget popup p #items [info globals]; +#X obj 500 310 widget popup p #items [info globals]; +#X obj 580 310 widget popup p #items [info globals]; +#X obj 180 340 widget popup p #items [info globals]; +#X obj 260 340 widget popup p #items [info globals]; +#X obj 340 340 widget popup p #items [info globals]; +#X obj 420 340 widget popup p #items [info globals]; +#X obj 500 340 widget popup p #items [info globals]; +#X obj 580 340 widget popup p #items [info globals]; +#X obj 180 370 widget popup p #items [info globals]; +#X obj 260 370 widget popup p #items [info globals]; +#X obj 340 370 widget popup p #items [info globals]; +#X obj 420 370 widget popup p #items [info globals]; +#X obj 500 370 widget popup p #items [info globals]; +#X obj 580 370 widget popup p #items [info globals]; +#X connect 0 0 2 0; +#X connect 1 0 0 0; diff --git a/test/toxy/tclversion.pd b/test/toxy/tclversion.pd index 9b348b0..442e81f 100644 --- a/test/toxy/tclversion.pd +++ b/test/toxy/tclversion.pd @@ -1,13 +1,20 @@ -#N canvas 68 131 532 301 24; -#X obj 38 191 tot .; +#N canvas 68 131 662 379 24; +#X obj 38 247 tot .; #X obj 38 29 loadbang; -#X msg 38 138 query concat set [info tclversion]; -#X msg 38 243; -#X obj 38 86 t b b; -#X msg 147 191 set; -#X connect 0 0 3 0; +#X msg 38 299; +#X msg 147 247 set; +#X obj 38 79 t b b b; +#X obj 231 247 tot .; +#X msg 231 299; +#X msg 78 188 query concat set patchlevel [info patchlevel]; +#X msg 38 138 query concat set version [info tclversion]; +#X connect 0 0 2 0; #X connect 1 0 4 0; -#X connect 2 0 0 0; -#X connect 4 0 2 0; -#X connect 4 1 5 0; -#X connect 5 0 3 0; +#X connect 3 0 2 0; +#X connect 3 0 6 0; +#X connect 4 0 8 0; +#X connect 4 1 7 0; +#X connect 4 2 3 0; +#X connect 5 0 6 0; +#X connect 7 0 5 0; +#X connect 8 0 0 0; -- cgit v1.2.1