Deployment
There are a number of features of the
GUIKit framework that aid deployment of user interface definitions with your own AddOns so that they can be easily executed when needed. Instead of programmatically building up an expression that represents a user interface and calling
GUIRun or
GUIRunModal dynamically, there is also a filesystem directory within every AddOn where user interface definitions will automatically be discovered. Any definitions placed within a subdirectory folder of an AddOn named
"GUI/" can be loaded with a relative pathname beginning with the path within the
"GUI/" directory. This follows the similar convention of Java classes and jars being discovered by
J/Link for files located within the
"Java/" subdirectory of an AddOn.
Upon startup of the
GUIKit` package all AddOns are checked for a
"GUI/" subdirectory and these paths are combined into a stored path list as
$GUIPath. This path list is used when loading user interface definitions from the filesystem. Some typical locations for AddOns applications are shown below.
| • $UserBaseDirectory/Applications |
| • $UserBaseDirectory/Autoload |
| • $BaseDirectory/Applications |
| • $BaseDirectory/Autoload |
Locations for user Mathematica applications which are searched by GUIKit.
This path list is generated on startup of the
GUIKit` package by finding all
"GUI/" subdirectories in all AddOns.
| Out[2]= |  |
The relative path
"Wolfram/Example/Calculator" is all that is needed to load a file located at
"SomeAddOn/GUI/Wolfram/Example/Calculator.xml".
| Out[3]= |  |
GUIKit definitions can be stored on the filesystem and used in either the XML format, GUIKitXML, using an .xml extension, or the
Mathematica expression format using a .m extension. The possible extension of a user interface definition can be excluded when specifying its relative pathname. First, a file with the given relative pathname and extension ".xml" is searched for, followed by a file with extension ".m" if an XML version is not found. This allows you to freely mix XML and
Mathematica definitions when defining interfaces. One implementation detail is that all interface definitions at runtime are converted to the XML form when created so there is some minor benefit of deploying your final AddOn interface definitions in the XML representation. You do not however have to recreate the XML version of your expressions by hand, but can simply use
Export["file.xml", expr, "GUIKitXML"] to let the
GUIKit system create the equivalent XML definition for you, since it automatically registers a "GUIKitXML" format with
Import and
Export when the
GUIKit` package is loaded.
A Sample Application
The layout of a sample application that contains a specialized user interface driven by
GUIKit is shown below.
Compute
Kernel
init.m
Compute.m
GUI
ZoroCorp
ComputeGUI.m
ComputeScript.m
Layout of a sample application.
The application is called
Compute, and the main
Mathematica code lives in the file
Compute.m. This is all in the standard way for
Mathematica applications. The user interface definitions go into the GUI directory and can be accessed from
Mathematica code in
Compute.m. A sample of how this could be arranged is shown below.
Needs["GUIKit`"]
...
Module[ {ref},
ref = GUIRun[ "ZoroCorp/ComputeGUI"] ;
...
]
Running a GUI from application code.
This application could be installed in one of the standard locations for
Mathematica applications, for example
$UserBaseDirectory/Applications, and then it could be used.
As can be seen the GUI definitions are placed in a subdirectory named ZoroCorp, this is done to make sure that there is no conflict if somebody else releases a GUI named ComputeGUI.
To be even more reusable and modular the design has broken out the code used in scripts for the GUI into a separate file
ComputeScript.m. This is loaded from the GUI as shown below.
Widget["Frame",
{
...
Script[{}, ScriptSource -> "ComputeScript.m"]
}
]
Using an external script from inside a GUI definition.
Breaking out the
Mathematica code into a separate script file is most useful when you have more than one GUI component that uses the same code.
The
Wolfram Workbench is a development environment for
Mathematica. It contains a number of useful features for working with
GUIKit. These include creating
Mathematica applications that contain GUI definitions and helping you to develop your GUI with debugging tools. It is described in the tutorial "
Wolfram Workbench Support".