Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

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().


Comment on Re: How to freeze a button while it is in active mode
Download Code
Re^2: How to freeze a button while it is in active mode
by SuicideJunkie (Priest) 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 (Novice) 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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1094027]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2014-10-02 12:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (56 votes), past polls