Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Sticky Button Down State

From: SunandaDH::aol::com at: 30-Jun-2003 14:43

Daril:
> The sticky button is not very disirable to see, but > even less, if user clicks button during wait, the > events held in queue and then processed. Returning > button immediately to "up" state is desireable but > invites user clicks.
You have several "real world" issues here and, as usual, they complicate code that looks very simple until you start adding the stuff to handle them. As I see it, you have four main issues: 1. How to stop a block of code being executed a number of times concurrently if someone repeatedly presses the button. This is important as REBOL can crash if someone tries this; 2. How to allow the user to cancel a long-running operation; 3. How to change a button state to show "in-progess" or some such; 4. How to show a progress bar. The last two are relatively trivial, so I'll leave them up to you. The first two need some extra code. In the rewrite of your code below, I've added: -- two extra "state variables" so we can track if a process is underway, and we can request a termination; -- A cancel button so the user can request the termination; -- wait 0 in the action loop -- important as otherwise the cancel action will be deferred until the main process is complete -- not what you want. ===== Cancel-requested: false in-process: false sites: [ http://www.rebol.com http://www.rebol.org http://www.reboltech.com http://www.rebolforces.com ] unview/all view layout [ button "Start Scan" [ if in-process [return true] in-process: true cancel-requested: false foreach site sites [ wait 0 if cancel-requested [in-process: false return true] print read site ] ;; for in-process: false ] ;; action button "Cancel" red [ cancel-requested: true ] ;; action ] ;; layout ===== [In the real, real world, you'd want to surround some of this with a 'try block so that the extra variables get set correctly in the event of an error -- otherwise, higher level recovery and restart code may leave the variables incorrectly set....If in-process is accidentally left true for any reason, the button becomes effectively disabled. Error-recover code can seem endless :-) ] Sunanda