Part 4: Architecture of the language/GUI interfaceManaging the GUIAll three languages have built-in support for managing the GUI. In Tcl/tk you must specify the full path to a control. The Tcl syntax is fortunately very terse, however, and you can also put the path into a variable and use that to access the control if you'll be referring to it frequently. For example, to set the foreground color of a button:.sample.manager.button configure -foreground blueUnfortunately, not all options of the controls can be set with this mechanism. For example, to set the state of a Tk radio button widget, or to put text into an entry widget, you set a global variable that was specified when the widget was created. The advantage of this approach is that it saves typing since the full widget path doesn't need to be specified each time the value is changed. It also makes maintenance easier since when you rearrange the controls in an application you don't have to change every reference to that control in the scripts. The disadvantages are that it is an inconsistent architecture which makes it more difficult to learn and that it may require that large numbers of global variables be created which increases the chances of name-space collisions. Some settings in Tcl/Tk do not have option names predefined, so you must use a built-in function to set them. For example, it is necessary to call the function tk_list-boxSingleSelect to make a list box object ensure that only a single line is selected at a time. In dtksh, a variable called a widget handle is returned from each command that creates a widget. If not declared to be a local, this global variable can then be used to access the widget from elsewhere in the application. The widget can also be specified using a mechanism similar to that used in the X Resource system where the full path to the object can be specified. This addressing supports using wild cards, which isn't possible with the other two tools. The command XtSetValues is used to set the resources of a dtksh widget: XtSetValues $somewidget set:trueIn MetaTalk, access to the controls from scripts is usually by forming a chunk expression to describe the object. For example, to set the highlight of a button (to show that it's been selected) in a window named sample, the following script would be executed: set the hilite of button "some button"\ of stack "sample" to trueIf the current script is associated with a control in stack sample, the stack specification can be omitted, saving typing and making maintenance easier since the controls can be rearranged without having to change the scripts that refer to them. MetaCard objects can also be accessed by name or by ID, since each object is given a unique and permanent ID when it is created, something that is not possible with the other tools, since widget settings are not persistent across executions of the application. MetaCard, like Tcl, will also automatically recurse if a variable is used to refer to an object. For example, if the variable "it" contained the string "button 3", the following script will move the third button 8 pixels upwards: set the top of it to the top of it - 8
Adding User-Interface ComponentsAdding additional display widgets to Tcl/Tk is relatively easy because the full source code of the other widgets is included, and because the new widgets can be linked directly into the Tcl/Tk executable. Tk doesn't use an object-oriented architecture however, so new widgets must be self contained.It is also possible to add widgets to dtksh. Since it is built on the Xt toolkit, any of the public domain and commercial widgets developed for use with that toolkit can be used with dtksh. Writing your own widgets is not as straightforward, however. Since source code is not included you must first license the Motif source from OSF (at considerable expense). Though it is theoretically possible to create widgets without the source, it is generally regarded as being impractical to do this due to the complexity and inadequate documentation of the underlying structures. Xt is ostensibly an object-oriented architecture, but there are so many deviations from the tenants of that paradigm that it is actually more difficult to subclass Xt/Motif widgets than to write complete widgets for Tcl/Tk. There is no way to add user-defined controls to MetaCard, though in many cases the ability to dynamically modify the graphic and bitmap objects from the scripting language can be used to achieve the same results. There is also an "imagePixmap" property that can be used to draw any type of graphics into an image in real time from a C/C++ function, a feature that can also be used to develop custom controls.
On to Application designBack to Architecture of the languagesUp to Table of Contents |