system.util.invokeLater()

Hi,

I am wanting to hide w text field until I need it, then make it visible and put it into focus. I am attempting to follow the advice at

https://docs.inductiveautomation.com/display/DOC80/Focus+Manipulation#FocusManipulation-AboutInvokeLater

I made a button on the page, with the following code attached in the onActionPerformed event handler

self.getSibling("Serial1").meta.visible = 1

def focus():
    event.source.parent.getComponent('Serial1').requestFocusInWindow()
 
# Call the function once the event has executed.
import system
logger = system.util.getLogger("Ship_Logger")
logger.info("Invoking later " )
system.util.invokeLater(focus)

I keep getting an error

Error running action ‘component.onActionPerformed’ on ShipConfirm@C/root/Button: Traceback (most recent call last): File “function:runAction”, line 13, in runAction AttributeError: ‘com.inductiveautomation.ignition.common.script.Imm’ object has no attribute ‘invokeLater’

when I try to invoke this. I have tried commenting out various pieces, using import system in various places, etc etc. Using 8.0.14 on Windows. Any advice?

Thanks

invokeLater is only applicable to Vision; Perspective’s single-threaded GUI is running on the frontend, separate from your script’s execution context. requestFocusInWindow() also won’t work - instead, each component has a focus() method that will attempt to call focus to itself.

ok, I didn’t see anything in the help text that said it was only for Vision, thanks for the help.

What I’m hearing is that there is no way in Perspective to tell focus to go to some particular object without that object having an event invoked that can call the focus() method. I can’t say “I want that object to get focus”, only that “I want focus”. Correct?

And there is no event I can see that would be called if I just made the text field visible. Nor can I see any other event that would be applicable to be called from another perspective component. Correct?

Thanks
Ken

In the manual's defense, it's in a 'Scripting in Vision' category, but, yeah, some of the manual is still using old copy from when we only had one visualization system.

Not exactly - you just need a reference to the other component. So you can either broadcast a message, and have a handler on the target component (preferred) or you can do the same thing you'd do in Vision - walk up/down/sideways on the component tree to get to a desired component:
https://docs.inductiveautomation.com/display/DOC80/Perspective+Component+Methods#PerspectiveComponentMethods-ObjectTraversal

Once you have a reference, you just call its focus() method; it's basically analogous to the requestFocusInWindow() builtin Swing method you would call in Vision.

You can add a property change script (right click) to the component's visible (or any other) property.

Yes, I see that there is a separate Perspective page on methods.

I will give that a shot and let you know how it goes. Thanks for the help!

Ken

1 Like

Thanks, I got it figured out. i was having problems understanding that I could reference something that wasn’t a property eg self.getSibling(“Label_1”)

1 Like