GUIKIT PACKAGE TUTORIAL

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".

In[1]:=
Click for copyable input

This creates a basic widget that consists of a panel with three buttons. It does not display anything yet.

In[2]:=
Click for copyable input

This runs the widget; now you should see the panel appear on your screen.

In[3]:=
Click for copyable input
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.

In[4]:=
Click for copyable input
Out[4]=

Widget Naming

One of the key features of GUIKit is that you can give widgets names.

In[1]:=
Click for copyable input

This creates and runs a widget, and it gives it a name.

In[2]:=
Click for copyable input

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.

In[3]:=
Click for copyable input
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.

In[1]:=
Click for copyable input

This runs a GUI that has two named widgets.

In[2]:=
Click for copyable input

This shows that there are two named widgets.

In[3]:=
Click for copyable input
Out[3]=

This requests a list of all property names available with the widget referred to by in the dialog.

In[4]:=
Click for copyable input
Out[4]=

You can use ToString and ToExpression with SetPropertyValue to include conversion to String or Wolfram Language expression values, using common optional arguments found with ToString and ToExpression. This changes the text property, and the new value shows up immediately.

In[5]:=
Click for copyable input
In[6]:=
Click for copyable input
Out[6]=

The property value can be extracted directly from the widget reference.

In[7]:=
Click for copyable input
Out[7]=

This shows that the property value that was returned is a string.

In[8]:=
Click for copyable input
Out[8]//InputForm=

Property values that automatically have equivalent Wolfram Language expressions as defined by J/Link can be returned or set using the standard PropertyValue function.

In[9]:=
Click for copyable input
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.

In[7]:=
Click for copyable input

This runs a built-in GUI.

In[8]:=
Click for copyable input
Out[8]=

This shows a dynamic snapshot of the interface.

In[10]:=
Click for copyable input
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.

In[4]:=
Click for copyable input
Out[4]=

This discovers all property names available with the widget registered with the name . You can query and set these values using PropertyValue[{"inputField","propertyName"}] and SetPropertyValue[{"inputField","propertyName"},newValue].

In[5]:=
Click for copyable input
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.

In[6]:=
Click for copyable input
Out[6]=

Additionally, you can discover what event names can be used to cause Wolfram Language code to execute whenever the event occurs by using BindEvent[{"inputField","eventName"},Script[code]].

In[7]:=
Click for copyable input
Out[7]=