Changing Label Text on Substacks

Trevor DeVore lists at mangomultimedia.com
Thu Dec 8 18:12:51 EST 2005


On Dec 8, 2005, at 2:35 PM, Adam wrote:

> Hi all:
>
> I have a series of modal windows that display the progress of  
> current process.  In these modal windows I have a label that lists  
> the current action being taken.
>
> How can update these labels as new processes take place without  
> closing the window?
>
> All the modal windows are substacks.

Here is a script I use in a progress dialog.  It goes in the stack  
script.  The scripts use a bunch of setProp/getProp handlers to show/ 
hide/update the dialog.  The script expects that you have a scrollbar  
named "Progress" and a field named "Feedback" on the stack.  Here is  
an example of how I use it:

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

The secret to having a modal dialog that you can update is this:

go invisible stack "MyModal" as modal
set visible of me to true

By opening the stack as invisible your scripts won't halt but you  
will display a modal dialog.


-- 
Trevor DeVore
Blue Mango Multimedia
trevor at mangomultimedia.com




=====
== 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




More information about the use-livecode mailing list