chiark / gitweb /
an applet
[chiark-tcl-applet.git] / example
1 #!/usr/bin/wish8.4
2
3 #----- general machinery -----
4
5 package require tktray
6
7 wm withdraw .
8
9 image create bitmap ims -file /usr/share/ghostscript/8.71/lib/gs_s.xbm   
10
11 tktray::icon .i -class example
12 .i configure -docked 1
13
14 set posted 0
15
16 foreach b {1 3} {
17     menu .m$b -tearoff 0
18 }
19
20 proc pressed {b x y} {
21     global posted
22     if {$posted == $b} {
23         puts "unpost $posted toggle"
24         .m$posted unpost
25         set posted 0
26     } elseif {[winfo exists .m$b]} {
27         if {$posted} {
28             .m$posted unpost
29             puts "unpost $posted other"
30         }
31         puts "post $b"
32         set posted $b
33         .m$b post $x $y
34     }
35 }
36
37 proc msel {} {
38     global posted
39     set posted 0
40 }
41
42 bind .i <ButtonPress> { pressed %b %X %Y }
43
44 #----- specifics -----
45
46 .i configure -image ims
47 .m1 add command -command { msel; puts hi } -label hi
48 .m3 add command -command { msel; puts boo } -label boo
49