Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: How to freeze a button while it is in active mode

by sundialsvc4 (Abbot)
on Jul 17, 2014 at 12:33 UTC ( #1094027=note: print w/replies, xml ) Need Help??

in reply to How to freeze a button while it is in active mode

It partly depends upon exactly what your graphic user-interface is set up to do (and how much support for, e.g., “button groups” you have at your disposal with any particular platform), but here is a general strategy for the handler for a button that will take a little while to complete.   (Entirely-abstract non-Perl pseudocode):

disableButton(); try { doTheWork(); } finally { enableButton(); } }
Translating that to “Perl or what-have-you” I leave as an exercise to the reader.   The try..finally construct that I refer to (which doesn’t automatically exist in Perl) is one that will always execute the finally portion even if an exception occurred.

My point, in using it, is that you always have to anticipate and to handle exceptions that may occur in your button-handler, so that you always re-enable the button.

Some GUIs provide for button-groups which simply means that the outer-level framework takes care of enabling and disabling the buttons.

Likewise, some GUIs implement buttons as objects that automatically handle the disable/enable logic (and exception-trapping), calling an onClick method of some kind to doTheWork().

Replies are listed 'Best First'.
Re^2: How to freeze a button while it is in active mode
by SuicideJunkie (Vicar) on Jul 17, 2014 at 19:31 UTC

    Note that if you just run off and loop on a job, then the GUI will be frozen and windows will mark it "not responding". Be sure to sprinkle in some DoOneEvent() or equivalent calls so your GUI keeps rolling while you work.

    Also note that just because a button is disabled, doesn't mean it can't be click()ed again if the user is quick and/or tricky. (Eg: Win32-GuiTest) The enable state of the button itself makes a decent flag if the application isn't multithreaded.

Re^2: How to freeze a button while it is in active mode
by Janish (Sexton) on Jul 18, 2014 at 02:41 UTC

    Thank you very much Sundialsvc4, for helping me to understand the logic. I finally manage to work on it as disable that before the function and enable it right afterward in my subroutine of button function. Appreciate!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1094027]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2017-06-25 07:37 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (564 votes). Check out past polls.