GUIKIT PACKAGE TUTORIAL

GUIKit Example: Making Progress (Extended)

Code
In[14]:=
Click for copyable input

Example

This example demonstrates various techniques for designing a progress bar dialog and a number of options available to wrap the reusable widget involved.

Basic Implementation

Here is one technique for defining a progress bar using the Mathematica expression syntax.

In[15]:=
Click for copyable input

A progress bar would be most useful in a modeless session where it could be used to update the state of another ongoing kernel evaluation.

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

There are three important widgets in the dialog that have been registered with reference names for easy lookup. Here are the most common properties worth setting during the lifetime of the dialog.

In[17]:=
Click for copyable input
In[18]:=
Click for copyable input
In[19]:=
Click for copyable input

Once the dialog is not needed, you can call ReleaseGUIObject to dispose of the instance.

In[20]:=
Click for copyable input

The following variants also show different techniques for defining a reusable progress dialog within the layout of an AddOn, and discuss the many options available for exposing only a subset of the properties and widgets that make up the user interface.

Example 1 of a Progress Bar Implementation

Here is an example that provides a progress bar implementation similar to the J/Link example.

In this version, you postmanipulate the Java objects in Mathematica by looking up the instances from their names after loading the definition file. After modifying the frame's title and the label's text, you will then call GUIRun, which displays the dialog.

In[21]:=
Click for copyable input

Here is a function that simulates a typical interaction with the GUIObject representing a progress bar dialog.

In[22]:=
Click for copyable input

To use the progress bar in a computation, you call CreateProgressBar1, which loads the user interface definition and returns a GUIObject. Then, while the computation is running, you periodically change the value property to update the bar's appearance. When the computation is done, you call ReleaseGUIObject.

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

You can also expose certain properties as optional arguments to the function to reuse the dialog in multiple situations.

In[25]:=
Click for copyable input
Out[25]=
Example 2A of a Progress Bar Implementation

This example illustrates how you can alternatively create reusable versions of a progress bar or any widget by placeholding dynamic properties that may need to change for each instance. This is done by using WidgetReference["#n"] within a base .m and creating various wrapper .m files that define these needed arguments to the base script externally.

In this example, you use a base user interface called ProgressBar2Base.m that contains uses of WidgetReference["#n"] and expects these values to be passed as initial arguments when called.

The source of ProgressBar2Base.m clarifies what dynamic elements of the progress bar are unique to this instance by only exposing certain properties within ProgressBar2Base.m, but setting all these modifiable properties within the wrapping .m file.

In[27]:=
Click for copyable input

Here is the revised implementation reusing the same .

In[28]:=
Click for copyable input
Out[28]=
In[29]:=
Click for copyable input
Example 2B of a Progress Bar Implementation

Taking this wrapper and base .m a step further, the Mathematica functions that load and run GUIObject instances can also pass script arguments when they are called using an optional second argument. Here you show how the Mathematica code can dynamically pass arguments to the base .m file that you used previously, duplicating the functionality of example 1, but greatly simplifying the interaction with the reusable user interface by not seeing all the individual property processing calls within the CreateProgressBar1 Mathematica code.

Notice how the second argument to GUILoad is simply , which will be registered in the widget name registry as , , and , respectively.

The two-argument call to GUILoad using ProgressBar2Base.m is the equivalent of example 2A of wrapping ProgressBar2Base.m with ProgressBar2.m containing the values desired.

In[30]:=
Click for copyable input

Here is the revised CreateProgressBar2B implementation reusing the same RunProgressBar.

In[31]:=
Click for copyable input
Out[31]=
New to Mathematica? Find your learning path »
Have a question? Ask support »