Event.source or system.gui strange error

I am having a really hard time figuring out what I am doing wrong with my event handlers.

Traceback (most recent call last):
File “event:mouseDragged”, line 7, in
AttributeError: ‘com.inductiveautomation.vision.api.client.componen’ object has no attribute ‘mX’

Ignition v8.1.18 (b2022061518)
Java: Azul Systems, Inc. 11.0.15

I am unable to even pull or target a custom property on a component using the event handlers on almost any component. Am I missing something?

something as simple as

window = system.gui.getParentWindow(event)

on a released event on a title bar throws this. What am I doing wrong?

Install my (free) Simulation Aids module from the Showcase. Then these will magically work. For an in-depth explication of the situation with PyComponentWrapper, see this topic:

Is this my issue?

Is this a bug or a permissions issue when utilizing portions of ignitions API?

A large portion of the snippets on the forum don’t work. Scripting outside of the script builder code from the designers UI is almost unusable. Built ins like event.source.parent are not even able to be parsed correctly.

Please show more code.

If it is your issue, then it isn’t so much a bug as a missing feature.

is there a timeline when this “feature” will be added. seems like a massive limitation.
I can run most of the system calls if I include system in my custom methods but I can’t use .getParentWindow.
Is there a way to pass a valid event object into a custom method that qualifies.
I basically just want to calla custom method that can run .getParentWindow to manipulate its position dynamically.
ON popup

event.source.newMethod(event) #or event object

#IN custom method

include system
window = system.gui.getParentWindow(event) # or (self) or self.actionPerformed.source
print window.name

What is the best practice to store a method (at what level) to help avoid this? Or is there a cleaner way to target the parent window so I can move or adjust it without having hard coded paths?

I am starting to think I should just avoid Ignitions custom methods all together and just create and include everything in librarys on a repo at the server level.

I rarely use custom methods. I am a big fan of well-organized project library scripts. I like delegating events to such scripts with one-liners in each relevant event. Pass anything you need from the event context to the library function as arguments.

Under the hood, getParentWindow uses SwingUtilities.getAncestorOfClass(). You can do the same in a library function if you have a special case.

2 Likes

Oh, and I wouldn’t hold your breath for a PyComponentWrapper fix. Items that a) have a work-around (my Simulation Aids) and b) are Vision have a relatively low priority.

1 Like