# Eventchange for spinner

**URL:** <https://forum.inductiveautomation.com/t/eventchange-for-spinner/5125>\
**Category:** Ignition\
**Created:** [September 10, 2012, 6:13pm UTC](https://forum.inductiveautomation.com/t/eventchange-for-spinner/5125 "2012-09-10T18:13:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![AJBerera](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@AJBerera](https://forum.inductiveautomation.com/u/AJBerera)\
**Post date:** [September 10, 2012, 6:13pm UTC](https://forum.inductiveautomation.com/t/eventchange-for-spinner/5125/1 "2012-09-10T18:13:46Z")

</div>

Is there any way of ‘Knowing’ whether the buttons are held down on or something so that I can call a script for the event?

Right now I have this:

`if event.propertyName == "intValue":
   event.source.active = 1
else:
	event.source.active = 0`  
This is only writing a 0 for some reason whether I click the spinner or hold it down.  
I think the solution is something I am missing on the Event handlers… or that the one I need has been removed from the component build…  
I’m looking at the setup for this using python and java and it seems very simple but I can’t get it to work either way and I think this is the only piece i’m missing.

Using Ignition I have this on the property change script.  
a timer is grouped with the spinner and I have my numeric step size bound to :

`if({Root Container.Group.Spinner.level}<1,1,if({Root Container.Group.Spinner.level}<3,10,if({Root Container.Group.Spinner.level}<7,100,0)))
`  
I need the Running property of the timer to be bound to a reset condition and a max bound value as well.

Something like this would be awesome…

`if event.source == "MousePressed":
	event.source.active = 'true'
else:
	event.source.active = 'false'`

---

<div class="post-metadata">

**Author:** ![James.Lorenz](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/james.lorenz/32/3290_2.png) [@James.Lorenz](https://forum.inductiveautomation.com/u/James.Lorenz)\
**Post date:** [September 10, 2012, 7:57pm UTC](https://forum.inductiveautomation.com/t/eventchange-for-spinner/5125/2 "2012-09-10T19:57:19Z")

</div>

I think the best way to approach this may be a client timer script. You can put a custom property on each button, call it “upActive” or “downActive”, and have it set to 1 when the mousePressed event fires, and 0 when the mouseReleased event fires. The timer script will then check to see if the value is true, and execute whatever code needs to be executed, which in this case will either be incrementing or decrementing a component, such as a numeric text field.

---

<div class="post-metadata">

**Author:** ![AJBerera](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@AJBerera](https://forum.inductiveautomation.com/u/AJBerera)\
**Post date:** [September 11, 2012, 1:17pm UTC](https://forum.inductiveautomation.com/t/eventchange-for-spinner/5125/3 "2012-09-11T13:17:30Z")

</div>

How would I read a property on a button from a timer script?  
How would I write back to a property?  
Take advantage of the timer?

---

<div class="post-metadata">

**Author:** ![James.Lorenz](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/james.lorenz/32/3290_2.png) [@James.Lorenz](https://forum.inductiveautomation.com/u/James.Lorenz)\
**Post date:** [September 11, 2012, 3:45pm UTC](https://forum.inductiveautomation.com/t/eventchange-for-spinner/5125/4 "2012-09-11T15:45:26Z")

</div>

You can access the component of a window by getting a reference to the window, as outlined in the manual:

[inductiveautomation.com/support/ … onents.htm](http://inductiveautomation.com/support/usermanuals/ignition/working_with_components.htm)

You’ll want to put the timer script inside of a try/except statement to suppress errors about the window not being open, because calling getWindow() depends on the window being open at that time. Also note that I said client timer script, a gateway timer script can’t access windows for a project.

The timer script is used to run a single increment/decrement, so instead of implementing a loop statement yourself, the script will increment/decrement at whatever interval you set the timer script to run. For example, I set the script to run every 100ms, so it will change the spinner every 100ms if I am holding the button down.

---

<div class="post-metadata">

**Author:** ![AJBerera](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@AJBerera](https://forum.inductiveautomation.com/u/AJBerera)\
**Post date:** [September 13, 2012, 2:42pm UTC](https://forum.inductiveautomation.com/t/eventchange-for-spinner/5125/5 "2012-09-13T14:42:56Z")

</div>

[code]try:  
window = system.gui.getWindow(‘Screen’)  
spinner = window.rootContainer.getComponent(“spinEdit”)  
downActive = spinner.getPropertyValue(“downActive”)  
upActive = spinner.getPropertyValue(“upActive”)  
value = spinner.getPropertyValue(“value”)  
increment = spinner.getPropertyValue(“increment”)  
if upActive == 1:  
incr = increment + 1  
valuemod = value + incr  
spinner.setPropertyValue(“increment”, incr)  
spinner.getComponent(“Spinner”).floatValue = valuemod  
#spinner.setPropertyValue(“value”, valuemod)

```
elif downActive == 1:
	incr = increment + 1
	valuemod = value - incr
	spinner.setPropertyValue("increment", incr)
	spinner.getComponent("Spinner").floatValue = valuemod
else:
	spinner.setPropertyValue("increment", 0)	
	#need to handle bounds...

```

except ValueError:  
# ignore error with a pass keyword  
pass[/code]

OK, this seems to work okay… I was thinking about incremementing like 10^0, 1, 2 to make it look better.

I have 2 concerns.  
I noticed that on the numeric text box there is a suffix property and I would like a prefix instead…

Also, I set bounds enabled and I set my max and mins on the text box… For some reason these are completely ignored when this script affects it…although when I manually enter a value outside of that range it does not

EDIT:  
I fixed the bounds directly in the value property change… It’s fine now, I was more concerned with how the text field allowed the change to happen.

---

<div class="post-metadata">

**Author:** ![James.Lorenz](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/james.lorenz/32/3290_2.png) [@James.Lorenz](https://forum.inductiveautomation.com/u/James.Lorenz)\
**Post date:** [September 13, 2012, 4:03pm UTC](https://forum.inductiveautomation.com/t/eventchange-for-spinner/5125/6 "2012-09-13T16:03:56Z")

</div>

You could use a numeric label and should be able to fix both those issues, but I’m guessing you need the user to type in a number in the box as well as use the up/down buttons, right?
