Custom properties as PyObjects

As far as I see there’s no possibility to pass a variable to a page through the Custom Properties mechanism that is a PyObject. That would be of use if I need to pass a reference to the current popup window to a new popup window, which I open from the first one - at the moment I store a reference of the first popup window in a python script variable.
Any suggestion?

Thanks in advance, regards

The only safe place to put a pyobject is using Swing’s ‘Client Properties’ of jcomponents and jframes.

If you put a parent window reference in a popup’s client properties, be sure to use a weak reference instead of the window object itself. Otherwise you risk leaking memory.

Thanks pturmel! I'm trying to elaborate on your valuable suggestion, but I'm facing the problem I describe next. I've defined Popup1 and Popup2: a button on Popup1 opens Popup2 and calls putClientProperty on the newly created Popup2

window = system.nav.openWindow('Popup2')
window.putClientProperty("winRef",system.gui.getParentWindow(event))

On Popup1 I've also defined a Custom Method sayHello(): if I try to call sayHello() from a button on Popup2

system.gui.getParentWindow(event).getClientProperty("winRef").sayHello()

I get the exception:
AttributeError: 'com.inductiveautomation.factorypmi.application.FPM' object has no attribute 'sayHello'

Any idea?

Thanks in advance

UPDATE
If I pass the reference to Popup1 through a shared.test.win variable in the shared test script, then Popup2 will manage to call sayHello() on Popup1.

UPDATE2
Same effect if the sayHello() Custom Method is defined at the Root Container level, instead of the Window level. It behaves as the reference stored in the Client Property looses the Custom Methods. Do I have to cast the object I get with the getClientProperty call?

You are suffering from a limitation of Ignition’s python wrappers. See this topic and try the most recent release candidate of Simulation Aids.

1 Like