The requestFocusInWindow() method only works for simple input controls like a Text Field (single line). When used on more complicated controls such as a Text Area (which can have scrollbars) or a Popup Calendar the focus will end up on the control’s container, rather than the component the user interacts with. From the user’s perspective no component will have focus.
Here is a function to set focus on any input control with a minimum of effort, including compound components. It can be used from any event script.
def focus(event, path):
import system
def requestFocus(event=event):
import system
c = system.gui.getParentWindow(event).getComponentForPath(path)
# Drill down to find a component without any children
while len(c.components) > 0:
# Just grab the first child
c = c.components[0]
c.requestFocusInWindow()
system.util.invokeLater(requestFocus)
Example usage:
- Place the code inside a file called ‘util’ in the script module editor.
- Add a PopupCalendar component called ‘calendarSelect’ to your window
- Add the following to the visionWindowOpened event for the window:
app.util.focus(event, 'Root Container.calendarSelect')