SCO Visual Tcl Reference Guide
Chapter 3, SCO Visual Tcl - graphical scripting language

Basic program structure

Basic program structure

Here is the general format of a SCO Visual Tcl application:

   #
   #Define Tcl procedures/callbacks
   #
   proc one { } { }
   

proc butCB {cbs} { }

proc textCB {cbs} { }

proc quitCB {cbs} { VtClose exit 0 } . . . # # Start Program # set app [VtOpen myprog] set form [VtFormDialog $app.mainform -ok -okLabel Goodbye \ -okCallback VtClose] set label [VtLabel $form.label -label "Hello World"] VtShow $form VtMainLoop

SCO Visual Tcl programs have two main sections: First, all Tcl procedures need to be defined: this includes all the callbacks and their supporting procedures. These procedures need to be defined first because Tcl is an interpretive language and needs to have its procedures defined before they are called.

Next, the application must establish a connection to the server and put up the first form. This is typically done by making the following four calls:

   set app [VtOpen Example]
   set form [VtForm $app.form]
   VtShow $form
   VtMainLoop
The first call to VtOpen(VTCL) establishes the connection with the server. VtOpen returns a handle to the application which is used when creating the first form. The next thing to do is to put up a form. This is done by calling VtForm(VTCL). VtForm requires a widget name and hierarchy to be passed to it. The format of widget/object names is as follows:
   parent_name.form_name
In this example, the parent of the first form is the application shell (that is, the handle returned from VtOpen).

To add other widgets to this form, the handle returned from VtForm should be used as their parent. For example, to add a button to this form, this call can be made:

   set button [VtPushButton $form.button -label "Push Me"]
After putting up the form, the next thing to do is to call VtShow(VTCL) to display the form. Typically, VtShow is not called until all the widgets on the form have been placed. This is so that the users do not see the form ``building'' before their eyes. VtShow only needs to be called for forms. Widgets within a form are shown by default.

Finally, VtMainLoop(VTCL) is called to hand control over to the user and start processing events. Events are application state changes such as pushing a button, or choosing an item in a list. All widgets have events associated with them, which the program may or may not respond to. To respond to an event, a callback procedure is written. This procedure gets called each time the event occurs. For example, a pushbutton widget callback would get called each time the button is pressed.