|
|
|
This is a follow-up to my earlier memo about user-programmable widgets and the extensible Tcl command language; the subject is timely, considering the recent TPOCC memo about STOL buttons on the Opcom menu bar. Using embedded Tcl, I wrote a user-programmable, TSTOL directive-generating, generic, Motif menu processor in little more than a day, although, if Jeff keeps lambasting my choice of editors, I might stretch its development out over 7 releases.
A Tcl-based menuing system has the following advantages over code- and/or UIL-based systems:
The menu processor, XMENU, reads a Tcl script file (an ASCII file containing Tcl commands) that defines the desired menu configuration and actions. The attached screen print shows the Telemetry System menu bar and pulldowns (in the upper right corner) generated by XMENU from a TS menu script. XMENU fits as follows into the XSAR user interface architecture:
XMENU XTPDSP \ / (Display) TSTOL | State Manager
The XTPDSP display program (which can be automatically started up from XMENU's script program) connects to a TSTOL parser. TSTOL's startup procedure would then have two REMOTE directives that connect the parser both to XMENU and to the state manager. Directives submitted to TSTOL by the XMENU processor are executed as if they were submitted by XTPDSP. For example, on the attached screen print, XSTOL was run in place of XTPDSP:
XMENU XSTOL \ / TSTOL
Picking the TS Status entry of the TS Presentation menu results
in a "page TS_STATUS
" directive being sent to TSTOL; TSTOL parses
the directive and sends a page command to XSTOL/XTPDSP. In the command
history window of the XSTOL panel, you can see an "[NI]
"
(network input) message showing the page directive received from the menu
processor (known to TSTOL as TS_MENU).
The XMENU menu processor is very simple. XMENU goes through the following initialization steps:
XtMainLoop()
.
XMENU extends the Tcl language with the following commands, used to define Motif-based menus:
XtAppAddInput()
is used to put the actual
establishment of a connection in the "background". tstol send
sends the specified string to the TSTOL parser; the string can be a
nested Tcl command that, when evaluated at run-time, returns a string.
tstol call and tstol receive are available, but have
only been used for testing so far.
Using these new commands, the TS menu bar was defined as follows in a Tcl script file:
menu ts -t bar ts add -l " Control " -m control ts add -l " Analysis " -m analysis ts add -l " Presentation " -m presentation ts add -l " Database " -c { puts stderr "-- Not Available --" } ts add -l " " ts add -l " Help " -c { puts stderr "-- Not Available --" }
The "-m
" options on the first three entries link them to the
appropriate pulldown menus. Picking either the Database entry or
the Help entry produces an error message.
The Presentation pulldown menu is defined by the following commands:
menu presentation presentation add -l "Hardcopy" -m hardcopy presentation add -l "Dynamic" -m dynamic presentation add -l "Static" -m static presentation add -l "TS Status" -c { tstol send "page TS_STATUS" }
The first three entries are linked to cascading submenus. The last entry,
TS Status, is used to bring up the Telemetry System status page.
When this entry is selected, a "page TS_STATUS
" directive is
sent to TSTOL, which, in turn, sends a page command to Display (XTPDSP) to
actually bring up the page.
The main and Presentation menus above show the basics of defining the
structure and behavior of menus in the XMENU script file. A couple of other
examples show some additional capabilities of Tcl-defined menus. The
Exit option on the TS Control menu executes two Tcl
commands, one to send an "\exit
" directive to TSTOL and the
second to terminate the XMENU program itself:
control add -l "Exit" -c { tstol send "\\exit" ; exit }
The Command Line option on the TSTOL submenu opens up XMENU's TSTOL command line input window:
tstol_menu add -l "Command Line" -c { manage tstol_window }
This window is simply a Motif command widget, consisting of a command input
line and a scrolling command history list; selecting a line in the history
list transfers the text to the input line, where the directive can be edited
before it is submitted to TSTOL. (Are you sure you want TPOCC's
previous-command-only recall capability?) Messages received by the menu
processor from TSTOL are added, courtesy of XtAppAddInput()
,
to the scrolling history list.
XMENU's input file is primarily intended as, but not restricted to being,
a menu definition file. For example, my current XMENU script,
ts.tcl
, defines the TS menu hierarchy, spawns the display
program (XSTOL in my case, but it could be XTPDSP), and begins listening
for a connection request from TSTOL.
XMENU was very rapidly prototyped. Although XMENU is a functional, working program, enhancements would need to be made in a production version of the software:
-label label
" instead of
"-l label
".
The use of an embedded command language like Tcl allowed the writing of a general-purpose, Motif-based menu display and processing program. This menu processor can handle, without changes to the executable, the TS menus, the CS menus, and other menus that are, as of yet, only a gleam on our system administrator's earring.
Although the XMENU program could work with menus defined via UIL, UIL seems a tedious way of defining a menu hierarchy. The examples in the TPOCC memo on STOL buttons required 10-15 lines of UIL for a menu entry that would be a Tcl one-liner. UIL provides great flexibility in specifying the appearance of a display object, but there are only so many ways you can or would want to change the appearance of a menu. More important is the ability to easily specify the behavior of a menu. The XSAR-extended Tcl gives us this capability without forcing us to write special-purpose callback functions in addition to our menu definitions.