-- ! 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. -->
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.
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:
# interface generated from example.ui # root is the parent window for this user interface proc example_ui {root args} { # this treats "." as a special case if {$root == "."} { set base "" } else { set base $root } button $base.button#1 \ -command "puts \"Hello, I'm $base.button#1\"" \ -text hello # Geometry management blt_table $root $base.button#1 1,1 # Resize behavior management blt_table row $root configure all -resize none blt_table row $root configure 1 -height {30 Inf} blt_table column $root configure all -resize none blt_table column $root configure 1 -width {30 Inf} # additional interface code # end additional interface code }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:
tk appname test_example wm title . "SpecTcl - example" source /home/user/project/example.ui.tcl example_ui .If
example.tcl
does exists, then SpecTcl will try
to run:
tk appname test_example wm title . "SpecTcl - example" source /home/user/project/example.ui.tcl source /home/user/project/example.tclIn this case, the code in
example.tcl
needs to instantiate
the interface by calling example.ui.tcl
.