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 are the window path of the container frame plus 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. So, for a button with an item name of 'foo', in an interface put into the frame '.bar', the widget name is '.bar.foo'.

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 exist, then SpecTcl will try to run:

In this case, the code in example.tcl needs to instantiate the interface by sourcing example.ui.tcl and then calling example_ui.