I have the following code in the property change event handler for a single select list:
if event.propertyName == 'selectedIndex':
print event.source.selectedIndex
Two events are generated as I click on each item in the list box. Here is some sample output:
3
3
2
2
4
4
I think this issue has been highlighted before (“One other thing- working with Colby the other day, we found that the List.selectedIndex property change generates two events instead of one”). For details see:
http://www.inductiveautomation.com/forum/viewtopic.php?f=23&t=3974&p=7685&hilit=list+selectedIndex#p7685
Is this correct behaviour? If it is, can you suggest a simple workaround so I can get a single event for a single click?
We are using Ignition version 7.2.3 (b6630).
Thank you for your help,
You can work around this issue with a client property.
if event.propertyName == 'selectedIndex':
if event.newValue != event.source.getClientProperty("LastIndex"):
print event.source.selectedIndex
event.source.putClientProperty("LastIndex",event.newValue)
Hello Kyle,
Thank you very much for the work around. My property change event is working perfectly now.
I can’t find any details of the methods:
event.source.getClientProperty
event.source.putClientProperty
…in the Ignition documentation. Is this working directly with dynamic properties?
Thank you again for your help,
Patrick
All the components in Ignition are extensions of JComponents.
http://download.oracle.com/javase/6/docs/api/javax/swing/JComponent.html
As such, most methods available to a JComponent will be available to Ignition Components, unless they are over-ridden.
Because the scripts we write are written in Jython, we can access the Java methods and constructors through Jython.
To list all the methods available to a certain component, you can do the following:
methods = event.source.parent.getComponent('Pie Chart').class.getMethods()
data = []
for method in methods:
data.append([method])
event.source.parent.getComponent('Table').data = system.dataset.toDataSet(["Methods"],data)
You can do the same for constructors, fields, etc.
Thank you again Kyle. I am sure this will be very useful in future.
I am interested to see if we can store an instance of a jython class in the client properties of a control. I will try it out as soon as I get some time.
Yeah, you can do something like that. For example, if I wanted to set a global reference to a Java Color or something else, you can do that like this
from java.awt import Color
global testColor
testColor = Color(255,255,255,0)
To use this in another script, you can do the following
Global testColor
print testColor
Color, itself is a Java Object, so this will work for other things, such as JFrames, Ignition components, etc.