From dab74bc8b4245e9808a256d4c0e38b9c055078e4 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 9 Jun 2012 20:54:01 +0100 Subject: [PATCH 1/1] wip subwindow --- applet.tcl | 40 ++++++++++++++++++++++++++++++---------- example | 6 +++--- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/applet.tcl b/applet.tcl index e660bce..4cf6e11 100644 --- a/applet.tcl +++ b/applet.tcl @@ -36,9 +36,16 @@ package require tktray # applet::setimage IMAGE # as necessary. # -# Inner window subprocess: +# Alternatively, instead of icon, it may arrange to run (repeatedly +# if necessary) a subprocess. # -# Caller that needs access to inner window should define +# Caller that needs access to inner window should call +# applet::setup-subwindow WIDTH ON-DESTROYING ON-READY +# Then the main code will call ON-DESTROYING just before +# destroying the inner window and recreating it, and ON-READY +# just after. Afterwards, theh inner window is called +# . +# # proc innerwindow {} { ... } # and run # innerwindow @@ -174,23 +181,27 @@ proc setimage {image} { .i configure -image $image } -} +#----- subwindow ----- +variable subwindow_on_destroying +variable subwindow_on_ready proc innerwindow-resetup-required {why} { variable innerwindow_after puts "IW-EVENT $why" if {[info exists innerwindow_after]} return - set innerwindow_after [after idle innerwindow-resetup] + set innerwindow_after [after idle applet::innerwindow-resetup] } proc innerwindow-resetup {} { variable innerwindow_after + variable subwindow_on_destroying + variable subwindow_on_ready unset innerwindow_after puts RESETUP - innerwindow-destroying + uplevel #0 $subwindow_on_destroying catch { destroy .i.i.c } if {![winfo exists .i.i]} return @@ -211,19 +222,28 @@ puts RESETUP # set inner_lastw $w # set inner_lasth $h # innerwindow-ph-dummy configure -width $w -height 2 - innerwindow-ready + + uplevel #0 $subwindow_on_ready # } } -proc setupinnerwindow {w} { +proc setup-subwindow {w on_destroying on_ready} { + foreach v {destroying ready} { + variable subwindow_on_$v [set on_$v] + } + global inner_lastw inner_lasth set inner_lastw -2 set inner_lasth -2 - image create photo innerwindow-ph-dummy -width $w -height 2 - .i configure -image innerwindow-ph-dummy + image create photo applet::innerwindow-ph-dummy -width $w -height 2 + .i configure -image applet::innerwindow-ph-dummy destroy [frame .i.make-exist] destroy [frame .i.i.make-exist] - bind .i <> { innerwindow-resetup-required IconConfigure } + bind .i <> { + applet::innerwindow-resetup-required IconConfigure + } +} + } diff --git a/example b/example index 588f3ca..b1a9c86 100755 --- a/example +++ b/example @@ -25,7 +25,7 @@ fconfigure stdout -buffering line set status none -proc innerwindow-destroying {} { +proc destroying {} { global status puts "DESTROYING $status" switch -exact $status { @@ -35,7 +35,7 @@ proc innerwindow-destroying {} { } } -proc innerwindow-ready {} { +proc ready {} { global status puts "READY $status" switch -exact $status { @@ -90,4 +90,4 @@ proc child-died {how how2} { } } -setupinnerwindow 40 +applet::setup-subwindow 40 destroying ready -- 2.30.2