Common Component Functions

There are a number of functions that are common to all components in Ignition. These functions can called from the components event handlers.

requestFocusInWindow()

This function requests that the designated component be given input focus.

Suppose for example that your window has two buttons. "Button 1" performs some script and you would like the focus in the window to move directly to "Button 2" whereupon the user can simply press the enter button to run the script for "Button 2." The following would be the script that is called from the first button's event handler.

#Previous code for the button that runs before the window's focus changes to Button 2
event.source.parent.getComponent('Button 2').requestFocusInWindow()

setPropertyValue(name, value)

Sets the value attribute of the named property to the specified value.

The following two scripts to the same thing. In this example the property that is being set is the name property but it could be a different property. The first example is the preferred way because it is more in line with the python style. Whereas the second example is more like Java in it's style. Regardless, when you see this in a project be assured that they accomplish the same result.

#This set the value attribute of the components name property to the string "Ignition."
event.source.name = "Ignition"
 
#This also sets the value attribute of the component's name property but just in a different way.
event.source.setPropertyValue("name", "Ignition")

getPropertyValue(name)

Returns the value attribute of the property.

The following two scripts do the same thing. In this example the property that is being changed is the name property but it could be a different property. The first example is the preferred way because it is more in line with the python style. Whereas the second example is more like Java in it's style. Regardless, when you see this in a project be assured that they accomplish the same result.

#This returns the value attribute of the components name property.
name = event.source.name
 
#This also returns the value attribute of the component's name property
name = event.source.getPropertyValue("name")

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("Popup3") window.setSize(250,600) window.setLocation(0,0
except ValueError: 
# ignore error with a pass keyword 
pass