<-- ! SpecTcl, by S. A. Uhler -- -- Copyright (c) 1994-1995 Sun Microsystems, Inc. -- -- See the file "license.txt" for information on usage and redistribution -- of this file, and for a DISCLAIMER OF ALL WARRANTIES. --> Using the User Interface code

Interfacing the Application with the User Interface

Generated code and naming conventions

All of the code that describes the layout for a user interface panel is contained in a single procedure. If the panel is named panel, then the procedure panel_ui will be created, and stored in a file called panel.ui.tcl.

To instantiate the user interface, the application program needs to source the code in panel.ui.tcl and call panel_ui with a single argument, the name of a frame or toplevel that the panel's widgets will be instantiated in. This frame or toplevel should already be created by the application.

The names of the widget commands, which are needed to dynamically change the configuration of any of the widgets within a panel, are obtained by concatenating the name of the frame that the panel was instantiated with the item_name option for that widget. All of the widgets in a panel are siblings in the Tk widget hierarchy, no matter what grid or sub-grid the widget is placed in for layout purposes.

The widget command option field is used to call out from the widget to the application code. The special escape sequences: %R, %B, %W, and %M can be used when entering the text for any command option to refer to the fully resolved names of the widgets, even though the frame it is instantiated in may not be known in advance.

An example application

Suppose we created a sample application, called example that consists of a single button, whose item_name is button#1 (the default name), and whose command option is:

	puts "Hello, I'm, %W"
. The code generated by SpecTcl will be in example.ui.tcl and look like: Notice that the text of the command option is grouped with (")'s, which is required to expand the variable $base which was part of the substitution for %W. In this case, the internal (")'s are appropriately protected.

When SpecTcl tests the application, it will look to see if the file example.tcl exists. If the file does not exist, The follow program is written and run:

If example.tcl does exists, then SpecTcl will try to run: In this case, the code in example.tcl needs to instantiate the interface by calling example.ui.tcl.