Component Scripting

Event handling allows you to use scripting to respond to a wide variety of events that components fire. This lets you configure windows that are very interactive, and are an important part of project design in the Vision module.

Events

An event can be many things, like a mouse click, a key press, or simply a property changing. Whenever these events occur, a script can be called to "handle" the event. Different components can fire different types of events. For example, mouse events are very common and are fired by almost all components. The cellEdited event, on the other hand, is only fired by the Table component.

Configuring Handlers

To configure event handlers for a component, right-click on the component and choose the Scripting from the pop-up window. You can also get to this button from the toolbar ( images/download/attachments/1704176/image2015-5-1_16_54_24.png ) or the Component menu. From the component scripting window, you can pick the appropriate event handler.

Script Builders

All events are handled with scripting, but you frequently don't need to write the scripts by hand. This is where the Script Builders come in. For each event, you can choose a common way of handling the event. This can be a navigation action, setting a tag value, and so on. To write an arbitrary script, choose the Script Editor tab.

For example, one of the most common uses of event handlers is to open a window when a button is pushed. To do this, simply select the actionPerformed event, and select the Navigation tab. Here you can simply pick the navigation action Open, and choose the window to open. If you're curious, you can peek over at the Script Editor tab to see the underlying code that makes this action work, but you certainly don't have to.

Common Component Functions

The following functions are common to all components in Ignition:

requestFocusInWindow() - requests that the component be given input focus . See also: focus Events.
setPropertyValue(name, value) - sets the value of a component's Custom property.
getPropertyValue(name) - gets the value of a Custom property.

Moving/Resizing Components and Windows

You can use scripting to move and resize a component at runtime. The functions system.gui.moveComponent, system.gui.reshapeComponent and system.gui.resizeComponent are used for this.

They simply take a component, and a new size, location, or both. Locations are always measured in pixels from the upper left point of the component's parent container.

Note that if you're moving a component that is set to relative layout, your coordinates will act as if they were coordinates to the sizes of the relevant containers last time they were saved in the Designer, not the current real coordinates of the runtime. This is very helpful for creating animations. In effect what this means is that the coordinates fed into these functions "respect" the relative layout system automatically.
You can move and resize windows as well. If you have a reference to a window, you can set its size and location directly. For example, if you wanted to move the floating window Popup3 to certain
location, you could do so like this:

try:
window = system.gui.getWindow("Popup")
window.setSize(250,600)
window.setLocation(0,0)
except ValueError:
pass # ignore error with a pass keyword pass

In this section ...