in reply to Tk buttons: Run/Cancel

Here's what I would do:

In your "Cancel" callback, add a line that creates a file somewhere, say "/tmp/myprogram-cancel", and returns.

In your "Run callback", fork your app, and add checks for something like
if (-f "/tmp/myprogram-cancel") { unlink "/tmp/myprogram-cancel"; exit; }
If you're not familiar with this technique, it's called a semaphore file, and there are numerous other ways to get a similar result too! You'll probably get a lot of responses from the monks on this one :).

Eh, you will likely also want to use another semaphore or check to make sure that your user doesn't click Run multiple times with this one! :)

Update: Do look at that Tk::ExecuteCommand, it greatly simplifies doing what you want! TIMTOWTDI (did I get that right?)

HTH

mhoward - at - hattmoward.org

Replies are listed 'Best First'.
Re: Re: Tk buttons: Run/Cancel
by gri6507 (Deacon) on Aug 13, 2003 at 17:53 UTC
    I have thought of this method (or something similar, using a global variable). However, I don't think this method would work here. My Run callback is something like this:

    foreach(@list){ DoLongBlockingThing($_); }

    so, I would need the cancel button to immediately break the LongBlockingThing() routine and not have to wait for the loop to come around and check the presence of the temp file (or variable).

      Well, noting your reply above also, I would fork and store the child pid somewhere (file or well-scoped variable), then have your cancel button shoot a kill at it. :) would this solve your problem?

      mhoward - at - hattmoward.org