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.
25 package require tktray
26 #load /home/ian/things/Systray/tktray-1.3.8/libtktray1.3.8.so
31 tktray::icon .i -class example
32 .i configure -docked 1
40 proc menubuttonpressed {b x y} {
44 puts "unpost $posted toggle"
47 } elseif {[winfo exists .m$b]} {
50 puts "unpost $posted other"
63 proc innerwindow-event {why} {
64 global innerwindow_after
66 if {[info exists innerwindow_after]} return
67 set innerwindow_after [after idle innerwindow-resetup]
70 proc innerwindow-resetup {} {
71 global innerwindow_after
72 unset innerwindow_after
76 catch { destroy .i.i.c }
77 if {![winfo exists .i.i]} return
78 destroy [frame .i.i.make-exist]
79 catch { destroy .i.i.b.c }
80 catch { destroy .i.i.b }
82 pack .i.i.b -fill both -side left -expand 1
83 frame .i.i.b.c -container 1 -background orange
84 pack .i.i.b.c -fill both -side left -expand 1
85 bind .i.i <ButtonPress> { pressed %b %X %Y }
87 global inner_lastw inner_lasth
88 #set w [winfo width .i.i]
89 # set w [winfo width .i.i]
90 # set h [winfo height .i.i]
92 # if {$w != $inner_lastw || $h != $inner_lasth} {
95 # innerwindow-ph-dummy configure -width $w -height 2
96 innerwindow [winfo id .i.i.b.c]
100 proc setupinnerwindow {w} {
101 global inner_lastw inner_lasth
105 image create photo innerwindow-ph-dummy -width $w -height 2
106 .i configure -image innerwindow-ph-dummy
108 destroy [frame .i.make-exist]
109 destroy [frame .i.i.make-exist]
110 bind .i <<IconConfigure>> { innerwindow-event "%w" }
113 bind .i <ButtonPress> { pressed %b %X %Y }
115 proc tooltip_starttimer {state x y} {
116 global tooltip_after posted tooltip_inwindow
117 if {$state || $posted || !$tooltip_inwindow} { tooltip_cancel; return }
118 catch { after cancel $tooltip_after }
119 set tooltip_after [after 500 tooltip_show $x $y]
122 proc tooltip_cancel {} {
124 catch { after cancel $tooltip_after }
125 catch { unset $tooltip_after }
129 set tooltip_inwindow 0
131 proc tooltip_enter {state x y} {
132 global tooltip_inwindow
133 set tooltip_inwindow 1
134 tooltip_starttimer $state $x $y
137 proc tooltip_leave {} {
138 global tooltip_inwindow
139 set tooltip_inwindow 0
143 proc setuptooltip {} {
144 bind .i <Enter> { tooltip_enter %s %X %Y }
145 bind .i <Leave> { tooltip_leave }
146 bind .i <ButtonRelease> { tooltip_cancel; tooltip_starttimer %s %X %Y }
147 bind .i <Motion> { tooltip_starttimer %s %X %Y }
148 toplevel .tt -background black
150 wm overrideredirect .tt 1
151 label .tt.t -justify left -background {#EEE1B3}
152 pack .tt.t -padx 1 -pady 1
156 proc settooltip {s} {
157 .tt.t configure -text $s
160 proc tooltip_show {x y} {
163 wm geometry .tt +$x+$y
167 proc setimage {image} {
168 .i configure -image $image