Creating Reusable Definitions
The GUIKit framework makes it relatively easy to reuse interface definitions because of its automatic use of private symbol contexts for each instance of a definition. There are, however, a number of points to keep in mind when writing Wolfram Language script code for user interfaces.
- Use Needs["Package`"] instead of Get["Package`"] to avoid unnecessary package reloading if multiple instances of an interface are possible.
- Avoid explicit use of contexted symbols such as MyPackage`MySymbol, since this will be the same global variable for all instances of the interface. This may, however, be a desired way of creating a global state shared between instances if that is what you intend.
- Consider designing your definition with a root widget of "Panel" and not "Frame". GUIKit` will automatically wrap a panel in a window when it is displayed, and by not forcing a specific frame instance in your definition, another user can load your definition into their own window.
The Counter definition is also written so that multiple instances can be reused in the same window, and by using the ExposeWidgetReferences option of Widget, you can make sure each instance is registered with unique names within the new parent window.