2 #----- general machinery -----
8 tktray::icon .i -class example
17 proc pressed {b x y} {
21 puts "unpost $posted toggle"
24 } elseif {[winfo exists .m$b]} {
27 puts "unpost $posted other"
40 bind .i <ButtonPress> { pressed %b %X %Y }
42 proc tooltip_starttimer {state x y} {
43 global tooltip_after posted tooltip_inwindow
44 if {$state || $posted || !$tooltip_inwindow} { tooltip_cancel; return }
45 catch { after cancel $tooltip_after }
46 set tooltip_after [after 500 tooltip_show $x $y]
49 proc tooltip_cancel {} {
51 catch { after cancel $tooltip_after }
52 catch { unset $tooltip_after }
56 set tooltip_inwindow 0
58 proc tooltip_enter {state x y} {
59 global tooltip_inwindow
60 set tooltip_inwindow 1
61 tooltip_starttimer $state $x $y
64 proc tooltip_leave {} {
65 global tooltip_inwindow
66 set tooltip_inwindow 0
70 proc setuptooltip {} {
71 bind .i <Enter> { tooltip_enter %s %X %Y }
72 bind .i <Leave> { tooltip_leave }
73 bind .i <ButtonRelease> { tooltip_cancel; tooltip_starttimer %s %X %Y }
74 bind .i <Motion> { tooltip_starttimer %s %X %Y }
75 toplevel .tt -background black
77 wm overrideredirect .tt 1
78 label .tt.t -justify left -background {#EEE1B3}
79 pack .tt.t -padx 1 -pady 1
84 .tt.t configure -text $s
87 proc tooltip_show {x y} {
90 wm geometry .tt +$x+$y
94 proc setimage {image} {
95 .i configure -image $image