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


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-----



Relevant Pages

  • Is there a way to terminate a Tcl procedure within the application/event loop?
    ... I'm writing an application that uses a loop to simulate an indeterminate ... progress bar just loops over and over again. ... "ShowProgress" puts these into a top-level window. ... Once I call "ShowProgress," it won't stop, even if I destroy the ...
    (comp.lang.tcl)
  • Re: Possible to time out a popup?
    ... The progress bar is nice, ... >| I am trying to display a popup box that times out. ... >| loop it so it doesn't allow user interaction until the ... > showBar oIe ...
    (microsoft.public.scripting.vbscript)
  • Using a progress bar and app is not responsive
    ... I open the window and update the progress bar as I do ... I have the cancel button set a member variable that I check ... every loop of my process. ...
    (microsoft.public.dotnet.languages.vb.controls)
  • Tk::ProgressBar
    ... I am looking for help on how to get a perl Tk progress bar to show how many ... files out of an array of files have been processed in a very long execution ... I need to fork the main window but I do not know how to pass data to it if I ... close the window when the loop is complete ...
    (comp.lang.perl.tk)
  • Re: remoting a dbase call and getting intermittent progress back...
    ... I want to make one call to the dataAccess object (which loops x times ... to loop through the data on the client side and pass the row details. ... > The progress bar really exists on the client side in your remoting case. ...
    (microsoft.public.dotnet.languages.csharp)