Artifact
9025766c67c8a4fa9c7ac1ac226365a8ce6ce104:
Attachment "beachball-bug.tcl" to
ticket [3028676f]
added by
lars_h
2010-07-13 05:12:19.
variable main_loop_stack {}
variable stack_height 0
proc push_main_task {args} {
variable main_loop_stack
lappend main_loop_stack $args
}
proc completion_main_loop {} {
variable main_loop_stack
variable stack_height [llength $main_loop_stack]
if {[llength $main_loop_stack]} then {
set cmd [lindex $main_loop_stack end]
set main_loop_stack [lreplace $main_loop_stack end end]
} else {
set cmd increment_count
}
eval $cmd
after 0 [list after idle completion_main_loop]
}
variable main_count 0
proc increment_count {} {
variable main_count
incr main_count
push_main_task count_down $main_count
}
proc count_down {n} {
after 5
if {$n} then {push_main_task count_down [expr {$n-1}]}
}
interp alias {} pause_main_loop {} push_main_task return
proc halt_main_loop {} {
variable main_loop_stack
set main_loop_stack [linsert $main_loop_stack 0 return]
}
eval {
toplevel .control
grid [
label .control.lcount -textvariable main_count
] x [
label .control.lheight -textvariable stack_height
]
grid [
button .control.halt -text "Halt" -command halt_main_loop
] [
button .control.pause -text "Pause" -command pause_main_loop
] [
button .control.run -text "Run" -command completion_main_loop
]
wm title .control "Control panel"
}