Accessing Scripting on Window or Root Container from compent

I have a pop-up window that has a custom method (let’s say it’s called foo) and when a user clicks on a component, I want to call foo. For the life of me I can’t find any documentation on how to reference various scripting objects. I’ve watched the help videos but they discuss very basic issues such as referencing a function on the same object that calls it. They mention putting methods on the main template window, but then do not mention how to call them after that.

So how does one reference a custom method higher up the ladder? Conversely, can one reference a custom method on an component from the window (such as the internalFramActivated script)?

Edit: I’m trying to call the window script this way:

event.source.parent.Foo()

and I get an error message

Traceback (most recent call last): File "<event:mouseReleased>", line 1, in <module> TypeError: 'unicode' object is not callable

If you want to create a method to access from various places, it’s best to put it in the script library. And then just call it every time you want to use it.

project.scripts.method()

My reply to CHH in this topic might help you.

[quote="CHH"]If you want to create a method to access from various places, it's best to put it in the script library. And then just call it every time you want to use it.

project.scripts.method()

It's a good idea, but would overly complicate things. I just need to run the script on the window itself. Honestly, I think I understand enough to just put it on the component and execute it when the window opens, but at the point I want to understand how to do it the original way I planned.

Thanks that helps to more fully define what I'm working with, but I still can't access the method on the root container. I tried using getRootContainer(), but maybe I'm executing it at the wrong time because it throws an error saying no such method exists for the level I'm calling it at.

Is it possible to access a custom method on the root container from a component within the container?

Well, I worked it out and found an extremely weird issue. First off, here’s the answer to my question, I found 2 ways of calling the script, foo(), on the root container by clicking on a component (I was using a pop-up window to test everything)

  1. [code]bob = system.gui.getParentWindow(event).getRootContainer()

bob.foo()[/code]

  1. event.source.parent.foo()

The weird problem that took me half a day to track down :laughing:

The actual name of the script I was trying to run is:

LSRun

No matter how I tried to call it, I would get the following error message

[code]Root Container
ERROR [ActionAdapter-AWT-EventQueue-2] Error executing script for event: mouseReleased
on component: Label.
Traceback (most recent call last):
File “event:mouseReleased”, line 5, in
TypeError: ‘unicode’ object is not callable

at org.python.core.Py.TypeError(Py.java:235)
at org.python.core.PyObject.__call__(PyObject.java:316)
at org.python.core.PyObject.__call__(PyObject.java:371)
at org.python.core.PyObject.__call__(PyObject.java:375)
at org.python.pycode._pyx1149.f$0(<event:mouseReleased>:7)
at org.python.pycode._pyx1149.call_function(<event:mouseReleased>)
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1275)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:623)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:168)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.invoke(ActionAdapter.java:265)
at com.inductiveautomation.factorypmi.application.binding.action.RelayInvocationHandler.invoke(RelayInvocationHandler.java:55)
at com.sun.proxy.$Proxy32.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

[/code]

however, if I got rid of just one of the capitol letters i.e. LsRun or LSrun everything works fine or I were to place another letter in front of it (yLSRun) or do just about any other thing it all works. I’m guessing there is some reserved function that starts with LSR (all caps) that it mistakenly thinks I’m calling. That or there’s just some weird bug about a function that starts with LSR (all caps).

One of the NetBeans rules for naming properties and methods is that they start with a lower case letter. Class names are expected to start with a capital letter. While jython doesn’t enforce those rules on pure jython, they could certainly impact Java/Jython blends like this.

Oh, I assure you, I will be remembering this :laughing: Thanks for the help, it got me circling around the ultimate problem (that’ll teach me to be lazy and put foo down for a function I’m having problems with instead of the actual name)