Re: Is there a way to terminate a Tcl procedure within the application/event loop?
From: Kevin Walzer (sw_at_wordtech-software.com)
Date: 10/25/04
- Next message: Kevin Walzer: "Re: License question"
- Previous message: Kevin Walzer: "Re: Wx vs Tk"
- In reply to: Gerald W. Lester: "Re: Is there a way to terminate a Tcl procedure within the application/event loop?"
- Next in thread: Helmut Giese: "Re: Is there a way to terminate a Tcl procedure within the application/event loop?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 24 Oct 2004 22:21:11 -0400
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Thanks, that was helpful. I found some code snippets at the wiki site
that got me in the right direction.
Gerald W. Lester wrote:
| Kevin Walzer wrote:
|
|> -----BEGIN PGP SIGNED MESSAGE-----
|> Hash: SHA1
|>
|> I'm writing an application that uses a loop to simulate an indeterminate
|> progress bar; because Tk doesn't have a "barber pole" style widget, the
|> progress bar just loops over and over again. I'm having a problem,
|> though, because once it starts, I can't terminate the loop.
|>
|> Here's the main part of the code in question:
|>
|> proc every {ms body} {
|> ~ after $ms [info level 0]
|> ~ eval $body
|>
|> }
|>
|> ~ proc Update {w interval} {
|>
|>
|> ~ set v [expr {[$w get] + $interval}]
|> ~ if {$v > [$w cget -to]} {
|> ~ set v [$w cget -from]
|> ~ }
|>
|> ~ $w set $v
|>
|>
|> ~ }
|>
|> proc ShowProgress {} {
|>
|> toplevel .progress
|>
|>
|> ~ tlabel .progress.text -textvariable show -width 70 -height 40
|> ~ pack .progress.text -side top -fill both
|> ~ pack [tprogress .progress.show -from 0 -to 10 ] -fill both -side
|> bottom
|> ~ .progress.show set 0
|>
|> grab .progress
|> ~ wm title .progress ""
|> ~ every 250 {Update .progress.show 1}
|>
|>
|> }
|>
|> Basically, the procedure "every" defines a time interval to evaluate the
|> loop, "Update" provides the increments on the progress bar to loop, and
|> "ShowProgress" puts these into a top-level window.
|>
|> Once I call "ShowProgress," it won't stop, even if I destroy the
|> .progress window. Once I do this, I then get an error message saying
|> that .progress.show isn't a valid command--it appears that Update and/or
|> ~ every are still running in memory.
|>
|> I'd like to have the application provide two ways to terminate the
|> progress bar:
|>
|> 1. Bind it to a procedure, so that it exits gracefully when the
|> procedure itself is complete. Right now it keeps running when the
|> procedure that calls it has closed its pipe/channel.
|>
|> 2. I'd also like to be able to stop the loop with a command, or by
|> destroying the window.
|>
|> Can anyone point me in the right direction? I've tried "after cancel,"
|> and I haven't gotten that to work. "after 500 destroy .progress" closes
|> the progress bar window, but then I get the error messages I mentioned
|> above--the loop is still running. I'm envisioning something like the
|> Unix "kill pid" command, but this is an internal Tcl procedure.
|
|
| You want "after cancel" -- but to use it you need the id after returns
| when it scheduele the event (kind of like a pid). Most people store it
| in a gloval variable or array.
|
| Check out wiki.tcl.tk/after
|
- --
Kevin Walzer, PhD
WordTech Software--Open Source Applications and Packages for OS X
http://www.wordtech-software.com
http://www.smallbizmac.com
http://www.kevin-walzer.com
mailto:sw@wordtech-software.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFBfGMWJmdQs+6YVcoRAn3fAJ42Otsc9Oz9XrD+1GLLZmM050wTNQCfTnrn
wuHypiC8kqmuJZtcpX/eQDE=
=nXvx
-----END PGP SIGNATURE-----
- Next message: Kevin Walzer: "Re: License question"
- Previous message: Kevin Walzer: "Re: Wx vs Tk"
- In reply to: Gerald W. Lester: "Re: Is there a way to terminate a Tcl procedure within the application/event loop?"
- Next in thread: Helmut Giese: "Re: Is there a way to terminate a Tcl procedure within the application/event loop?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|