2 #----- general machinery -----
6 # tk::tktray widget is called .i
9 # Caller that needs access to inner window should define
10 # proc innerwindow {} { ... }
14 # .i.i.b frame to contain container
15 # .i.i.b.c actual container
18 # Caller should provide
19 # proc pressed {b x y} { ... }
20 # which should examine b and do something appropriate.
23 proc manyset {list args} {
24 foreach val $list var $args {
32 package require tktray
36 tktray::icon .i -class example
37 .i configure -docked 1
45 proc menubuttonpressed {b x y} {
49 puts "unpost $posted toggle"
52 } elseif {[winfo exists .m$b]} {
55 puts "unpost $posted other"
68 proc innerwindow-resetup-required {why} {
69 global innerwindow_after
71 if {[info exists innerwindow_after]} return
72 set innerwindow_after [after idle innerwindow-resetup]
75 proc innerwindow-resetup {} {
76 global innerwindow_after
77 unset innerwindow_after
81 innerwindow-destroying
83 catch { destroy .i.i.c }
84 if {![winfo exists .i.i]} return
85 destroy [frame .i.i.make-exist]
86 catch { destroy .i.i.b.c }
87 catch { destroy .i.i.b }
89 pack .i.i.b -fill both -side left -expand 1
90 frame .i.i.b.c -container 1 -background orange
91 pack .i.i.b.c -fill both -side left -expand 1
92 bind .i.i <ButtonPress> { pressed %b %X %Y }
94 global inner_lastw inner_lasth
95 #set w [winfo width .i.i]
96 # set w [winfo width .i.i]
97 # set h [winfo height .i.i]
99 # if {$w != $inner_lastw || $h != $inner_lasth} {
102 # innerwindow-ph-dummy configure -width $w -height 2
107 proc setupinnerwindow {w} {
108 global inner_lastw inner_lasth
112 image create photo innerwindow-ph-dummy -width $w -height 2
113 .i configure -image innerwindow-ph-dummy
115 destroy [frame .i.make-exist]
116 destroy [frame .i.i.make-exist]
117 bind .i <<IconConfigure>> { innerwindow-resetup-required IconConfigure }
120 bind .i <ButtonPress> { pressed %b %X %Y }
122 proc tooltip_starttimer {state x y} {
123 global tooltip_after posted tooltip_inwindow
124 if {$state || $posted || !$tooltip_inwindow} { tooltip_cancel; return }
125 catch { after cancel $tooltip_after }
126 set tooltip_after [after 500 tooltip_show $x $y]
129 proc tooltip_cancel {} {
131 catch { after cancel $tooltip_after }
132 catch { unset $tooltip_after }
136 set tooltip_inwindow 0
138 proc tooltip_enter {state x y} {
139 global tooltip_inwindow
140 set tooltip_inwindow 1
141 tooltip_starttimer $state $x $y
144 proc tooltip_leave {} {
145 global tooltip_inwindow
146 set tooltip_inwindow 0
150 proc setuptooltip {} {
151 bind .i <Enter> { tooltip_enter %s %X %Y }
152 bind .i <Leave> { tooltip_leave }
153 bind .i <ButtonRelease> { tooltip_cancel; tooltip_starttimer %s %X %Y }
154 bind .i <Motion> { tooltip_starttimer %s %X %Y }
155 toplevel .tt -background black
157 wm overrideredirect .tt 1
158 label .tt.t -justify left -background {#EEE1B3}
159 pack .tt.t -padx 1 -pady 1
163 proc settooltip {s} {
164 .tt.t configure -text $s
167 proc tooltip_show {x y} {
170 wm geometry .tt +$x+$y
174 proc setimage {image} {
175 .i configure -image $image
178 proc fork-then {ondeath inchild} {
179 global children errorCode errorInfo
180 foreach f {stdout stderr} {
181 if {[catch { flush $f } emsg]} {
182 catch { bgerror $emsg }
190 puts stderr "CHILD ERROR $emsg\n$errorCode\n$errorInfo\n"
192 kill KILL [id process]
194 set children($pid) $ondeath
198 proc chld-handler {} {
201 if {[catch { set got [wait -nohang] }]} break
202 if {![llength $got]} break
203 manyset $got pid how how2
204 if {[info exists children($pid)]} {
205 set l $children($pid)
208 uplevel #0 [concat [list $l] $how $how2]
210 catch { bgerror $emsg }
216 signal -restart trap CHLD { after idle chld-handler }