Xic has an interface to Tcl/Tk. Tcl (Tool control language) is a popular open-source scripting language, and Tk is a graphical package addition. Since this capability is dynamically loaded, Xic can use this capability if it has been installed, but does not require the installation. This interface is presently not available under Microsoft Windows.
If the Tcl/Tk libraries are installed in the standard location (/usr/local/lib), the libraries should be found automatically. If these libraries are installed elsewhere, the following variables should be set to indicate the locations to Xic.
!set TclLibrary path_to_tcl
!set TkLibrary path_to_tk
The path_to... are the full paths to the Tcl/Tk shared libraries. These variables can be set in a .xicinit or .xicstart file, or in the technology file.
The !tk command is used to execute a Tcl/Tk script. The language syntax is provided in documentation supplied with Tcl/Tk, and is described in
Tcl and the Tk Toolkit, John K. Ousterhout, Addison-Wesley.
The command syntax is
!tk script_path arguments...where script_path is a path to a file containing the script, and any arguments follow. The script will be executed as if by the wish shell supplied with Tcl/Tk.
The startup file, which can be used to set defaults, is named ``.xic-wishrc'' in the user's home directory. The contents is analogous to the .wishrc file normally used with Tcl/Tk.
The functions for Xic scripts are available in Tcl/Tk in the form
xic function arguments...The function xic is a Tcl function which loads the interface function or user-defined function given in the second argument. User defined functions can be accessed if they are already known to Xic, i.e., they were defined in a library file or were defined in a previously-run Xic script. The arguments to the function follow, and should match the arguments expected by the function. The variable type of the argument is inferred from the argument:
To explicitly coerce a numeric token into a string, backslash escaped double quotes should be used to delimit the token. For example, \"1.234 \" is taken as a string. The backslash prevents Tcl from removing the double quotes before passing the token.
Arrays passed to interface functions must use ``0'', ``1'', etc. as indices, and are ordered accordingly (in Tcl, array indices can be any text token and have no natural order). The ``0'' element (at least) must be set before the array can be passed to a function. If the array is dynamically expanded, new Tcl elements will be created. The initial size of the array is implied by the largest contiguous index assigned. Thus, for example, if the interface function requires an array of size 4, the following Tcl code could be used
set array(0) 0
set array(1) 0
set array(2) 0
set array(3) 0
xic Function &array()
When the function returns, the array values will be updated. Only one-dimensional arrays are available.
There is an additional special Tcl function which has been added.
xwin win_nameThis function returns the X window id of the Tk window given as a widget path in win_name. This is used to obtain the window id of a Tk window to be used for Xic graphics through the GRopen interface. A suggested way to use a Tk window for exported drawing from Xic is given in the example below. The xwin procedure is used to obtain the window id. This window should be configured with `-background ""' which allows redraws to be handled through a procedure bound to the window with the bind command which responds to Expose events. Otherwise, Expose events will cause the window to be redrawn in grey after the event handler is called. A pixmap is used to store the image for redraws.
Example
# This is the window used for drawing by Xic. # Note the '-background ""' directive. This # is necessary for proper redrawing after expose # events. frame .f -width 8c -height 8c -background "" pack .f set win_id [xwin .f] set ghandle [xic GRopen ":0" $win_id] # The win_id is the X id of the drawing window, # the ghandle is the handle value returned from # Xic upon opening graphics on this window. set size(0) 0 set size(1) 0 set size(2) 0 set size(3) 0 xic GetWindowView 0 &size() # The size array contains the displayed area of the # cell in the main Xic window, in order L, B, R, T xic GRdraw $ghandle $size(0) $size(1) $size(2) $size(3) # This draws the Xic view into the Tk window xic GRupdate $ghandle # Due to the way Tk (and X) works, unless GRupdate is # called after drawing, the drawing won't be visible. # The operations are stuck in a cache somewhere waiting. # GRupdate flushes the operations. set dsize(0) 0 set dsize(1) 0 xic GRgetDrawableSize $ghandle $win_id &dsize() # The dsize array contains the size in pixels of the # Tk drawing area. set pixm [xic GRcreatePixmap $ghandle $dsize(0) $dsize(1)] xic GRcopyDrawable $ghandle $pixm $win_id 0 0 $dsize(0) $dsize(1) 0 0 xic GRupdate $ghandle # We have created a pixmap of the same size and depth as # the drawing area, and copied the drawing area into it. # This will be used to redraw the drawing area after an # expose event. bind .f <Expose> { # This sets up a handler for expose events. Expose # events are received when a previously obscured part # of the window is uncovered. The pixmap is copied # into the Tk window. xic GRcopyDrawable $ghandle $win_id $pixm 0 0 $dsize(0) $dsize(1) 0 0 xic GRupdate $ghandle }
The TextCmd script function can be used to launch a Tcl/Tk script. At present, Tcl/Tk scripts are not recognized in the script path, but one can use a native language wrapper to include Tck/Tk scripts in the User Menu.