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