How to make buttons to control a timer

OK I have my timer component which works and it’s flipping through a set of windows.

Now I’m trying to make three buttons on the same window as the timer. The first button should stop the timer and scroll one window back. The second button is a toggle button which should simply stop or start the timer depending on whether its selected property is true or false. The third button should stop the timer and scroll one window forward.

Nothing I do is working. If I try

event.source.parent.getComponent('Timer').Running = 0 it gives me an error that I can’t write to the Running property.

For the toggle button I tried this

event.source.parent.getComponent('Timer').running = !event.source.selected but that won’t even compile unless I take out the negation and then it still doesn’t do anything.

I’m also not sure how to address the window list/array which is declared in the timer component. Is that variable visible to other components or do I need to move it somewhere else?

[quote="timf"]Nothing I do is working. If I try

event.source.parent.getComponent('Timer').Running = 0

The running property starts with a lower case "r" - Python is case-sensitive.

[quote="timf"]For the toggle button I tried this

event.source.parent.getComponent('Timer').running = !event.source.selected

Ok, first of all - you might not want to use a script here. Just bind the Timer's "running" property to the Toggle Button's "selected" property - no scripting needed! If there is some reason you have to use the script, try putting this script in the Toggle Button's "itemStateChanged" event: (note - it should all be one line)

event.source.parent.getComponent('Timer').running = event.stateChange != event.SELECTED

Where is it declared in the timer - in an action script? If so, these aren't visible to other components. Heck - they aren't even defined for longer that it takes to run the action script.

Hope this helps,

Thanks. Here’s what I’ve done. On the ‘Prev’ button actionPerformed I have

event.source.parent.getComponent('Pause').selected = 1

On the ‘Pause’ button I have nothing. On the ‘Next’ button actionPerformed I have

event.source.parent.getComponent('Pause').selected = 1

On the timer I have this bound to Running attribute

!{Root Container.Pause.selected}

which makes the state of the ‘Pause’ button control the timer, and the ‘Next’ and ‘Prev’ buttons control the state of the ‘Pause’ button, so everything works. The user can now click any of the three buttons and they all work to control the timer running state.

Right now the timer is controlling the windows via this propertyChange action:

[code]#list of windows to cycle through
windows = [“Window 1”, “Window 2”, “Window 3”, “Window 4”]

if event.propertyName == “value”:
i = event.source.value
#close the previous window
fpmi.gui.closeWindow(windows[i-1])
#open the next window
fpmi.gui.openWindow(windows[i])
[/code]

What I need to do now is add to the ‘Next’ and ‘Prev’ buttons actionPerformed script so they also rotate through that list of windows. But as you’ve said they can’t see the list while it’s inside a timer action script, and I don’t want to have to maintain three copies of this array in three different components. So what do I do with the array to make it visible to all three components? I’ve tried a DataSet but it seems very complicated to work with, like a database, and I couldn’t figure it out. Can I put the array somewhere that it can be seen and addressed globally as an array rather than a DataSet?

Well, DataSets are what you would use for this - they aren’t that complicated. To keep things easier, however, you could do something like this:

Put a String Dynamic Property somewhere (on the pause button, or a container that held all of these components, perhaps), that was called “WindowList”.

Make the value equal to: “Window 1;Window 2;Window 3;Window 4”

Now in your script, create the list of windows like this:

windowString = event.source.parent.WindowList windows = windowString.split(";")

Tada! More python string manipulations here:
docs.python.org/lib/string-methods.html

Hope this helps,

Thanks, it’s all working now. I did your solution for exposing the window list, and it worked. But then once I got it all working I realized I didn’t even need to do that. The buttons don’t need to know what the window names are. All they need to do is write new values to timer.value and let the timer do its work of swapping through the list of windows! heh Easier than I thought.

Excellent! The simpler the better!

Do you ever turn the timer on/off? The easiest way to do that is just binding the running value to whatever is controlling it (a client SQLTag if control needs to happen across multiple windows).

1 Like