For Programmers: Free Programming Magazines  


Home > Archive > Tcl > December 2004 > Interrupting a procedure









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Interrupting a procedure
Phil Biehl

2004-12-22, 9:14 pm

I have a procedure that flashes a button and updates the button text at 1
sec intervals. I'd like to be able to interrupt and end this proccedure from
another procedure. How can I do this?

Thanks,
Phil

proc DoSMTimer {} {
proc toggle {v} {uplevel [concat set $v \[expr \[set $v\] ^ 1\]]}
proc Sleep {time} {after $time set end 1; vwait end}

set TogBit 0
for {set i $::SMTime} {$i >= 0} {incr i -1} {
if {[set TogBit [toggle TogBit]]} {set color #33ffff} else {set
color #3333ff}
.row5.spell configure -text "SpellMode in $i seconds" -background
$color
Sleep 1000
}
.row5.spell configure -text "Spell" -background #33ffff
}


Quokka

2004-12-23, 4:11 am

Phil Biehl wrote:
> I have a procedure that flashes a button and updates the button text at 1
> sec intervals. I'd like to be able to interrupt and end this proccedure from
> another procedure. How can I do this?
>
> Thanks,
> Phil
>
> proc DoSMTimer {} {
> proc toggle {v} {uplevel [concat set $v \[expr \[set $v\] ^ 1\]]}
> proc Sleep {time} {after $time set end 1; vwait end}
>
> set TogBit 0
> for {set i $::SMTime} {$i >= 0} {incr i -1} {
> if {[set TogBit [toggle TogBit]]} {set color #33ffff} else {set
> color #3333ff}
> .row5.spell configure -text "SpellMode in $i seconds" -background
> $color
> Sleep 1000
> }
> .row5.spell configure -text "Spell" -background #33ffff
> }
>
>

I think you are going about this the Wrong Way(R)..

You should create a proc to do the toggle functionality you want
then call it as a timer event. The following shows a simple
example...


proc DoDisplayToggle { } {
global runcount
global timerid

puts "Timer runcount = $runcount"

incr runcount
if { $runcount < 5 } {
set timerid [ after 1000 DoDisplayToggle ]
}
}

proc StartTimer { } {
global runcount
global timerid

# Start toggle timer
set runcount 0

set timerid [ after 1000 DoDisplayToggle ]
}

proc StopTimer { } {
global timerid

after cancel $timerid
}
Phil Biehl

2004-12-23, 4:08 pm

Thanks Quokka! That worked perfectly. You read my mind and gave me just what
I needed!

Happy Holidaze,
Phil


"Quokka" <NoSpam@iinet.net.au> wrote in message
news:41CA1B5A.6090903@iinet.net.au...
> Phil Biehl wrote:
> I think you are going about this the Wrong Way(R)..
>
> You should create a proc to do the toggle functionality you want
> then call it as a timer event. The following shows a simple
> example...
>
>
> proc DoDisplayToggle { } {
> global runcount
> global timerid
>
> puts "Timer runcount = $runcount"
>
> incr runcount
> if { $runcount < 5 } {
> set timerid [ after 1000 DoDisplayToggle ]
> }
> }
>
> proc StartTimer { } {
> global runcount
> global timerid
>
> # Start toggle timer
> set runcount 0
>
> set timerid [ after 1000 DoDisplayToggle ]
> }
>
> proc StopTimer { } {
> global timerid
>
> after cancel $timerid
> }



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com