chiark / gitweb /
wip subwindow
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 9 Jun 2012 19:54:01 +0000 (20:54 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 9 Jun 2012 19:54:01 +0000 (20:54 +0100)
applet.tcl
example

index e660bce7acbba766981b75cf9a68ab5052ee2c6c..4cf6e119545be2ea6783199e7316e6e2eebd6ee5 100644 (file)
@@ -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 <<IconConfigure>> { innerwindow-resetup-required IconConfigure }
+    bind .i <<IconConfigure>> { 
+       applet::innerwindow-resetup-required IconConfigure
+    }
+}
+
 }
diff --git a/example b/example
index 588f3cade9975d1b6061d804a25e57348408eaf7..b1a9c862236e90c57b6bc0196f1c00d64d51ad83 100755 (executable)
--- 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