Tcl/Tk Cookbook - Housekeeping


Purpose

This section gives you information on where to get Tcl/Tk, its extensions, source for this cookbook and its examples and some other information we think worth noting if you are setting out to compile and install Tcl/Tk.

Where to get Tcl and Tk and extensions

The primary site for Tcl and Tk distributions is

ftp://ftp.cs.berkeley.edu/ucb/tcl

but the distributions along with most of the extensions can be obtained from the mirror sites

ftp://ftp.src.doc.ic.ac.uk/packages/tcl/ and ftp://ftp.funet.fi/pub/languages/tcl/

[We found the latter more up to date].

The above form is a Universal Resource Location which you can use in a World Wide Web browser such as mosaic or netscape to access the site. A directory listing will be presented using which you can fetch the files.

Alternatively you can use FTP (File Transfer Protocol) and login to the host whose name follows "ftp://" (e.g., ftp.funet.fi) as anonymous, give your electronic mail address as password and fetch the files from the directories whose pathnames follow the respective host name (e.g., /pub/languages/tcl).

You can use archie service to get a list of other anonymous FTP servers. Send the message Help via an electronic mail to archie@archie.sura.net to get information on how to use this service.

If you do not have direct FTP access please send the message Help by an electronic mail to ftpmail@decwrl.dec.com for directions.

Tcl and Tk on World Wide Web

Readers of this cookbook may also be interested to visit http://www.geog.le.ac.uk/argus/ and http://web.cs.ualberta.ca/~wade/Auto/Tcl.html.

HTML & Latex Documents

Compressed tar file of Tcl/Tk manual pages in Hypertext Markup Language are available from ftp://ftp.funet.fi/pub/languages/tcl/contrib/docs. The Tcl/Tk Reference Guide (latex document) can also be fetched from the same source.

Newsgroups

The comp.lang.tcl is an active forum for Tcl/Tk information exchange. Announcements regarding Tcl/Tk and other extensions are posted regularly in this.

Extensions and Contributed Software

Note: Please refer to the README documents that accompany contributed software for information on authorship and copyrights. The same are acknowledged here.

There is so much of useful and well documented Tcl/Tk extensions, that it is impractical to list them here (let alone use them). There is the inherent danger in this that like XF (see below), some of these may not be maintained for one reason or another. There is also the case of many of the contributed modules address the same issue with different approaches (e.g., hush, itcl, object-tcl all provide a C++ binding). This is proving to be much more difficult to handle in a short-term project like this as the name of the game is to wait and see before taking the plunge. For these reasons, we have selected BLT-1.9, Expect-5.19, itcl2.0 as the three Tcl/Tk extensions we use in this cookbook (apart from a fileselectionbox from earlier days) to show the user how to make use of them.

BLT, an extension library for Tk, contains additional widgets such as the versatile blt-graph and commands such as drag-and-drop. Expect is a Tcl based application for automating routine system adminstration tasks and itcl2.0 provides a C++ binding for Tcl/Tk as well as a set of widgets.

TclX (Extended Tcl), Tcl-DP (Tcl-Distributed Programming) and Tix (set of mega widgets) are also popular. Blt based application xelem (an interactive application about periodic table) is interesting.

The latest versions of all these contributed software, apart from expect, are at ftp.funet.fi. The expect.readme at that ftp site gives instructuions on how to get expect.

Jumping the compilation gun

All the information under this heading can be found (and described in greater detail in relevant README files and also in the later chapters of the books by Ousterhout and Welch. However we felt that it is worthwhile to draw attention to these at the beginning to help the setting up of Tcl/Tk at your site.

Issue 1:

If you are planning on compiling Tcl7.4 and Tk4.0 with several other extensions, it may be useful to note that Tcl/Tk distribution contains the template to integrate the extensions and provide a unified wish shell from which the commands and widgets of the extensions can also invoked along with the core Tcl/Tk commands. If you do not have an integrated wish, then for each extension you want to use, you will find yourself invoking a wish compiled for that extension - for instance blt_wish for using blt based applications or itkwish for itcl. Chapter 9 describes how to achieve this integration.

Another important point to note if you wish to use C++ as your application development language, you would want to use itcl but you may also want to provide blt, expect as well as cater to those wanting to use C as their application language. itcl, to quote their developers,

".... Tcl are procedures and global variables, and all of these building blocks must reside in a single global namespace. There is no support for protection or encapsulation.

[incr Tcl] introduces the notion of objects. Each object is a bag of data with a set of procedures or "methods" that are used to manipulate it. Objects are organized into "classes" with identical characteristics, and classes can inherit functionality from one another. .....

Classes and/or related procedures can also be encapsulated in their own "namespace". A namespace is a collection of commands, variables, classes and other namespaces that is set apart from the usual global scope...............

With vanilla Tcl, each extension must add its commands and variables at the global scope. Extension writers are encouraged to add a unique prefix to all of the names in their package, to avoid naming collisions. Extensions can now sit in their own namespace of commands and variables, and sensitive elements can be protected from accidental access."

Tip 1:

In practice, this would mean that itcl requires its own version of Tcl/Tk with support for namespaces requiring the use of the version of Tcl/Tk that comes in the distribution of itcl. Therefore if you wish to integrate itcl with other Tcl/Tk extensions/applications you have to use the itcl version of Tcl/Tk as the basis for all of them rather than the original.

Issue 2:

Send is a powerful Tk command which allows any Tk application on a display to communicate with any other Tk application on the display. the sending application can either to retrieve information about the target application or change the state of that target application by invoking an arbitrary Tcl script in it . [Chapter 2 provides an example of using send.]

This mechanism provides both the opportunity to build powerful cooperating multimedia hypertools as well as a potential security risk. We recommend the reader to Chapter 23 of Professor Ousterhoust book . In case you have not got access to the book, much of his description on the security issue is quoted here:

" ...any application that uses your display can send scripts to any Tk application on that display, and the scripts can use the full power of Tcl to read and write your files or invoke subprocesses with the authority of your account.....

...you can protect yourself fairly well if you employ a key-based protection scheme for your display such as xauth which generates an obscure authorization string and tells the server not to allow an application to use the display unless it can produce the string. Typically the string is stored in a file that can be read only by a particular user, so this restricts the use of the display to the one user. If you want to allow other users access your display, you can give them a copy of your authorization file or you can change the protection on your authorization file so that it is group-readable.

... many people use xhost program which specifies a a set of machine names to the server and any process running on any of those machines can establish a connection to the server. Anyone with an account on any of those listed machines can connect to your server. To prevent these people from sending to your applications and abusing your account, Tk checks to see if xhost-style protection is used on the display; if so, Tk refuses to accept incoming send commands. If you currently use xhost for protection, you should learn about xauth and switch to it as soon as possible."

Tip 2:

If you want to use the send command even though you are using xhost for protection, before compiling Tk, turn off the security check in the Tk Makefile by commenting out the line SECURITY_FLAGS = -DTK_NO_SECURITY. The Makefile then would have the following
SECURITY_FLAGS =
#SECURITY_FLAGS = -DTK_NO_SECURITY
allowing for send to be used under the xhost protection.

Cookbook Source

Self-contained versions of this cookbook and the source code for the associated examples are available:

The examples in this cookbook are authored using Tcl7.4 and Tk4.0. They are developed and tested on Sun Microsystems Sparcstations running SunOS 5.4, SunOS 5.3 and SunOS 4.1.3.

Note 1: The examples for Chapters 1, 6-9 (inclusive) require compiling parts of the examples. Templates for the Makefile is provided in each chapter. Ensure that any customization you make is reflected in the Tcl source files in that chapter, that invoke the compiled parts.

Note 2: It is assumed that Tcl/Tk in your site is installed under /usr/bin. If that is not the case, you should replace the line #!/usr/bin/wish -f, in the source code of examples with an appropriate pathname {The "-f" option is not required for versions of Tk above 3.6}. If you need to change the pathname to the wish binary, note that some Unix systems cannot handle the first line of a script file when it exceeds 32 characters. To avoid this, follow the trick posted in comp.lang.tcl by Kevin Kenny. Replace the line #!/usr/bin/wish -f with the following two lines:

#!/bin/sh
exec /some/very/long/path/to/wish -f "$0" $(1+"$$@"}

Note 3: Basics of Tcl, Chapter 1 is set up to invoke the mosaic browser to view tcltk-man-html html documents. You will require to set the two variable Hyper(browser) and Hyper(html) in the procedure CreateSynWin ~cookbook/code/BTCL/eb.tcl

Please refer to Getting Started for how to run tclsh, wish as well as the examples.

Tcl7.5a2 and Tk4.1a2

The latest versions of Tcl and Tk are 7.5a2 and Tk4.1a2. The examples in here are simple enough to run on these later versions without modifications. The current release of the distribution also contain ports of both Tcl and Tk for the Windows and Macintosh environments.

Note: Please note that the examples in this cookbook use Unix specific commands exec and date as well as the Tcl file commands which are available only on most Unix workstations. These need to be replaced with appropriate ones available on the Pc and Macintosh platforms. The XBM bitmap format needs to be changed as well.

We hope to make these changes automatic in the next revision.

Tcl7.3 and Tk3.6

The examples should work for the previous release 7.3 of Tcl and 3.6 of Tk too.

XF, a Graphical User Interface(GUI) development tool for Tcl and Tk, developed by Sven Delmas, is available for Tcl7.3 and Tk3.6. We had hoped to include a brief example of how to use XF. Unfortunately XF was not ported to later releases of Tcl and Tk.

XF required familiarity with Tcl and Tk programming and provides its own higher level programming interface much of which is automatically generated. Given that XF is effectively frozen, we are not sure of this adding an additional learning curve.