Making Modal (but non-blocking) Progress Dialogs |
|
The secret to having a modal dialog that you can update is this:set the uTitle of stack "MyProgress" to "Updating Database" set the uFeedback of stack "MyProgress" to "I'm updating stuff. Keep your pants on." set the uProgress of stack "MyProgress" to 0 --> Do stuff to update progress set the uProgress of stack "MyProgress" to currentAction/totalActions
By opening the stack as invisible your scripts won't halt but you will display a modal dialog.go invisible stack "MyModal" as modal set visible of me to true
==== == START SCRIPT ==== local sEndValue = 100 local sCenterOnScreen = "true" setProp uTitle pValue set title of me to pValue end uTitle setProp uFeedback pValue set htmlText of fld "Feedback" of me to pValue wait 50 milliseconds end uFeedback setProp uCenter pValue if pValue <> false then put true into pValue put pValue into sCenterOnScreen end uCenter setProp uProgress pValue if pValue is not a number then put 0 into pValue put round(pValue) into pValue if pValue >= 0 then if visible of sb "Progress" of me = false then show sb "Progress" of me set thumbPosition of sb "Progress" of me to max(0, min(pValue, sEndValue)) else hide sb "Progress" end if end uProgress setProp uEndValue pValue if pValue is not a number then put 100 into pValue put round(pValue) into sEndValue set the endValue of sb "Progress" of me to max(0, sEndValue) end uEndValue getProp uProgress return thumbPosition of sb "Progress" of me end uProgress setProp uShow pValue local tTarget = "" if pValue = true then put line 1 of openStacks() into tTarget if sCenterOnScreen = false AND tTarget <> empty then put loc of stack tTarget into tLoc else put screenLoc() into tLoc end if go invisible stack (short name of me) as modal set loc of me to tLoc set visible of me to true --> GIVE IT TIME TO DISPLAY wait 100 milliseconds else put true into sCenterOnScreen set the uEndValue of me to 100 --put 100 into sEndValue close me wait 0 milliseconds end if end uShow setProp uComplete pValue set the uProgress of me to 100 close me wait 50 milliseconds end uComplete getProp uShow if short name of me is among lines of openStacks() then return true else return false end if end uShow getProp uVisible if short name of me is among lines of openStacks() then return true else return false end if end uVisible --> FOR TESTING on mousedown if environment() = "development" AND commandKey() is down then close stack (short name of me) end mousedown
Posted on 12/8/05 by Trevor Devore to the Use Revolution list