X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;f=example;h=b719c50409dae9a48ce7b4e60c42ab5da791c125;hb=13fd7884410510c20f77bdd1204d60a419eb7ac4;hp=457d75d3aeb8fbc30eae101a44597ba446d588fb;hpb=208895273cfa7904e09251ee19495b0c0d1ff5e8;p=chiark-tcl-applet.git diff --git a/example b/example index 457d75d..b719c50 100755 --- a/example +++ b/example @@ -1,108 +1,93 @@ -#!/usr/bin/wish8.4 +#!/usr/bin/wish8.4 -f +# -*- Tcl -*- -#----- general machinery ----- +source applet.tcl +source subproc.tcl -package require tktray - -wm withdraw . - -tktray::icon .i -class example -.i configure -docked 1 - -set posted 0 +#----- menu ----- foreach b {1 3} { - menu .m$b -tearoff 0 -} - -proc pressed {b x y} { - global posted - tooltip_cancel - if {$posted == $b} { - puts "unpost $posted toggle" - .m$posted unpost - set posted 0 - } elseif {[winfo exists .m$b]} { - if {$posted} { - .m$posted unpost - puts "unpost $posted other" - } - puts "post $b" - set posted $b - .m$b post $x $y - } + applet::setup-button-menu $b } -proc msel {} { - global posted - set posted 0 -} +.m1 add command -command { msel; puts hi } -label hi +.m3 add command -command { msel; puts boo } -label boo -bind .i { pressed %b %X %Y } +#image create bitmap ims -file gs_s.xbm +#image create bitmap ims -file /usr/share/ghostscript/8.71/lib/gs_s.xbm +#setimage ims +#setimage ims -proc tooltip_starttimer {state x y} { - global tooltip_after posted tooltip_inwindow - if {$state || $posted || !$tooltip_inwindow} { tooltip_cancel; return } - catch { after cancel $tooltip_after } - set tooltip_after [after 500 tooltip_show $x $y] -} +applet::setup-tooltip { puts VIS } { puts INVIS } +applet::tooltip-set "line\nanother" -proc tooltip_cancel {} { - global tooltip_after - catch { after cancel $tooltip_after } - catch { unset $tooltip_after } - wm withdraw .tt -} +fconfigure stdout -buffering line -set tooltip_inwindow 0 +set status none -proc tooltip_enter {state x y} { - global tooltip_inwindow - set tooltip_inwindow 1 - tooltip_starttimer $state $x $y +proc innerwindow-destroying {} { + global status + puts "DESTROYING $status" + switch -exact $status { + none { } + old { } + default { kill $status; set status old } + } } -proc tooltip_leave {} { - global tooltip_inwindow - set tooltip_inwindow 0 - tooltip_cancel +proc innerwindow-ready {} { + global status + puts "READY $status" + switch -exact $status { + none { + run-child + } + old { + # wait for it to die + } + default { + error "unexpected state $status" + } + } + puts "READY-done $status" } -proc setuptooltip {} { - bind .i { tooltip_enter %s %X %Y } - bind .i { tooltip_leave } - bind .i { tooltip_cancel; tooltip_starttimer %s %X %Y } - bind .i { tooltip_starttimer %s %X %Y } - toplevel .tt -background black - wm withdraw .tt - wm overrideredirect .tt 1 - label .tt.t -justify left -background {#EEE1B3} - pack .tt.t -padx 1 -pady 1 - settooltip {} -} +set ratelimit 0 -proc settooltip {s} { - .tt.t configure -text $s -} +proc run-child {} { + global status ratelimit -proc tooltip_show {x y} { - incr x 9 - incr y 9 - wm geometry .tt +$x+$y - wm deiconify .tt -} + puts "RUN-CHILD $status" + set now [clock seconds] + lappend ratelimit $now + while {[lindex $ratelimit 0] < {$now - 10}} { + set ratelimit [lrange $ratelimit 1 end] + } + if {[llength $ratelimit] > 10} { + puts stderr "crashing repeatedly, quitting $ratelimit" + exit 127 + } -proc setimage {image} { - .i configure -image $image + set status none + set status [subproc::fork child-died { + execl xacpi-simple [list -into [winfo id .i.i.b.c]] + }] + puts "FORKED $status" } -#----- specifics ----- - -.m1 add command -command { msel; puts hi } -label hi -.m3 add command -command { msel; puts boo } -label boo - -image create bitmap ims -file /usr/share/ghostscript/8.71/lib/gs_s.xbm -setimage ims +proc child-died {how how2} { + puts "DIED $how $how2" + global status + switch -exact $status { + old { + set status none + run-child + } + default { + set status none + innerwindow-resetup-required "child died" + } + } +} -setuptooltip -settooltip "line\nanother" +setupinnerwindow 40