Widget Basics
Widgets are the basic component of GUIs built with
GUIKit. This tutorial discusses some of the basics of widgets and how they work. More detailed information on widgets can be found in
"Definition Building Blocks".
This creates a basic widget that consists of a panel with three buttons. It does not display anything yet.
This runs the widget, now you should see the panel appear on your screen.
| Out[3]= |  |
The result of
GUIRun is a
GUIObject expression; this can be used as a handle to the executing GUI.
GUIScreenShot takes a
GUIObject expression and returns a picture that shows how the GUI appears on screen. The image you see may be more appropriate for your system.
| Out[4]= |  |
Widget Naming
One of the key features of
GUIKit is that you can give widgets names.
This creates and runs a widget, and it gives it a name.
GUIInformation takes a
GUIObject expression and returns information about its internals. This example extracts all the named widgets from the
GUIObject. There is only one name:
MyWidget.
| Out[3]= |  |
Widget names will be used in many places for scripting GUIs.
Widget Properties
Manipulation of widgets through their properties is a key concept of
GUIKit. There are a number of property-based functions that aid in discovering what properties exist on widgets in an interface and also querying and modifying their current values.
This runs a GUI that has two named widgets.
This shows that there are two named widgets.
| Out[3]= |  |
This requests a list of all property names available with the widget referred to by
"button1" in the dialog.
| Out[4]= |  |
You can use
ToString and
ToExpression with
SetPropertyValue to include conversion to
String, or
Mathematica expression values using common optional arguments found with
ToString and
ToExpression. This changes the text property, and the new value shows up immediately.
| Out[6]= |  |
The property value can be extracted directly from the widget reference.
| Out[7]= |  |
This shows that the property value that was returned is a string.
Out[8]//InputForm= |
| |  |
Property values that automatically have equivalent
Mathematica expressions as defined by
J/Link can be returned or set using the standard
PropertyValue function.
| Out[9]= |  |
Further Widget Details
In addition to names and properties widgets have a number of other details that are important for creating GUIs. These can be investigated using the
GUIObject reference.
This runs a built-in GUI.
| Out[8]= |  |
This shows a dynamic snapshot of the interface.
| Out[10]= |  |
You can retrieve a list of all widgets in the interface that have been registered with unique string names and reference these widget instances by these reference names.
| Out[4]= |  |
This discovers all property names available with the widget registered with the name
"inputField". You can query and set these values using
PropertyValue[{"inputField", "propertyName"}] and
SetPropertyValue[{"inputField", "propertyName"}, newValue].
| Out[5]= |  |
You can also find out what method names exist that can be executed on this widget with
InvokeMethod[{"inputField", "methodName"}, arguments] and even filter these names using string patterns.
| Out[6]= |  |
Additionally, you can discover what event names can be used to cause
Mathematica code to execute whenever the event occurs by using
BindEvent[{"inputField", "eventName"}, Script[code]].
| Out[7]= |  |