Donal K. Fellows's Tcl Archive

Last updated: 2nd April, 2001


Index:


Welcome

Welcome to my Tcl/Tk archive. Below you'll find listed various things that I've managed to dig out of my collection of tcl scripts and library files, together with (some) documentation which I'll get around to putting online properly sometime. Note that for all the code below, you are free to use it however you wish unless it says otherwise. This includes use as a component of a fully commercial application (I don't think there is anything here that could be sold by itself) and modification and subsequent redistribution (though it would be nice if you credited me with some of the work in that case.)

In addition to the code described below, I also have a quick guide to getting the send command working. This was condensed massively from the info available on the WWW, and is a transcription of the sort of advice I've been giving to people here with insecure displays when they were told to get things working better (all in the name of stopping some users who like to use xmelt, xgrabsc and the like... :^))

The stuff below has been tested with Tcl7.4p3 and Tk4.0p3 and not with Tcl7.5b3 and Tk4.1b3 (with a few exceptions ) even though I have the newer versions installed locally. However, I only really anticipate problems with the directory browser, and then only on non-UNIX platforms (due to filename handling - this will take only a little work to correct, but I haven't had the time to do so yet).

I really ought to edit this page a bit more often. I'm now running Tcl7.6b1/Tk4.2b1 locally, with a copy of the most recent stable versions kept around for (semi-)supported software. I ought to go through and fix everything up here to work nicely with these new versions...

I've even been playing around with Tcl8.0 (nice one John) and much of the stuff here may well work with it. I've got a script lying around that really makes use of the compiling - it isn't worth running without compilation, it uses so much math processing! I'll shove it somewhere on here when I have a few moments.

There is no help for getting things installed, as my local installation is somewhat wierd anyway... :^)


Users of Internet Explorer should note that it is incapable of handling double extensions. As a work-round, they can substitute .tgz for .tar.gz anywhere they wish when downloading from this page.

Personally, I'd recommend that they use Netscape instead, but that's a separate matter entirely... :^)


Fontification

Users of GNU Emacs v19 and v20 are well served by context-sensitive highlighters in C modes and the like, but the default highlighting for Tcl is of little use, offering little real assistance to the developer. In response to this, I had developed a set of highlighting expressions for use in Emacs, but these were unfortunately based on the now-deprecated hilit19 package. Luckily, I've now converted these to work with the font-lock package with the same look and an improved feel over the original. Get the elisp implementation of this and then install it by:

  1. Putting it in a directory on your load-path (I use $(HOME)/emacs)

  2. Byte-compiling it (not strictly necessary, but a good idea)

  3. Adding the line

        (require 'tcl-font)

    to your $(HOME)/.emacs

Once this is done, the next time you load a Tcl file (there are plenty below) after you have restarted emacs, you will get loads of glorious highlighting.

Note that if you use a dark-background for your emacs windows, the highlighting will not be very effective (I'm a light-background person), but this is easy to fix by modifying all the font-lock-make-face lines near the head of the elisp file.


Some people have had problems with this library due to their using older versions of emacs. For these people, I make available a version of the above highlighting which uses hilit-19. This version is unsupported, but is the direct ancestor of the later code that works with Font-Lock mode.

The code has now been adapted for emacs v20 while still maintaining backward compatability (crucial for my own use!) There is still more work to do though, since I feel that the faces ought to be customisable. That is a lot of effort though, so I'm putting it off as much as I can...


Scripts and Extensions

* Drag-n-Drop Mechanism
* Shaped Window Extension

Megawidget and Dialog Stuff including...

* Progress Meter
* Notebook Container Megawidget
* Font Selection Dialog
* Advanced Error Dialog

Obsolete Stuff including...

* Transparent Photo Images
* Directory Browser
* Base64 Decoder


* My Generic Useful Library. Gzipped tarfile.

Assorted useful procedures. Includes a sane mechanism for producing menubars, and a text widget with full undo and redo capability. This may well be required for some of the other packages here as I have this installed here, and I use it virtually all the time in my own applications.

* Canvas Dump/Undump Procedures. Tcl script.

Saves and rebuilds as much of a canvas as it can find, including item configuration options and binding scripts. Does not save or restore any bindings or configuration info for the canvas as a whole (that's easy in comparison).

* Image Pane Generation Procedures. Tcl script.

Especially for toolbars. Take it and buld your own!

If you have Tk4.1 then you should be using the grid geometry manager for this sort of thing, as it is a lot more intuitive (to my mind at least).


* Try/Catch/Finally Command. Tcl Script. Tcl8.0 and later Only

This script makes exception handling easy, allowing you to tackle errors in your scripts in a structured way with a minimum of fuss. For example:

   try {
       set f [open /non/existant/file]
   } catch {POSIX ENOENT *} {
       puts "That file doesn't exist!"
   } catch {POSIX EACCES *} {
       puts "You may not open that file!"
   } finally {
       puts "Wibble..."
   }
  

Note that this code is based on matching (according to the rules of string match) on the contents of the global errorCode variable, which has, IMHO, been unjustly overlooked by script writers for all too long now.


* Fully Justified Text Demo. Tcl Script. Tcl8.0 and later Only

This script demonstrates how to get fully justified text (i.e. text where each line of a paragraph except the last is flush with both margins.) Just run it for the demo to work, or pick it apart to see how it is done and how to use it in your own code. Includes an algorithm that works by inserting spaces and another that works by inserting invisible images (which also works better in a canvas widget.)


* A full OO extension. C source. Tcl 8 (betas) Only

The Tcl/Tk Resource This is a full object system for Tcl8 that provides classes, objects, methods, properties and inheritance - all the things you really need. This uses an enhanced version of the fasteval code above, and compiles cleanly with gcc -O -Wall on all the systems I have access to. Previous versions have been in serious use in an application I'm developing as part of my job, but the introduction of this particular version into a working environment has been delayed until Tcl8 goes into beta.

The system was developed mainly because:

  1. I needed an object system there-and-then.

  2. I didn't want to require other people to have to install foreign extensions or systems that patched the core of Tcl (hello [incr Tcl]!)

  3. I didn't like the tradeoffs in [incr Tcl]. I feel that fancy syntax doesn't help all that much, and copying that used in C++ simply because that is a popular language is plain daft. (I've rammed my head up against that particular brick wall more times than I want to recount) I instead wanted classes, and particularly objects, to be cheap things that I could use a few times and then throw away without ill-effect. I'm not sure that there are that many people on the planet who are boned up on the pros and cons of dynamic classes.

  4. I was stuck inside one snowy weekend. :^)

There are some awful bugs in here. Use the code below instead which has had a lot of effort lavished on it to render it bug-free, mem-leak-free and reasonably fast.

* A full OO extension. Gzipped Tarfile of Sources. Tcl 8 Only
* Alternative version. Zip Archive of Sources. Tcl 8 Only

This has now been updated completely for Tcl8.0 final, and has now had a substanital amount of use internally to hunt down the bugs (including going through with a fine-tooth comb and purify.) It also includes the ability to link a property to a global variable - very useful when building dialog boxes to modify the properties of an object...

I now have a reasonable quantity of documentation for this extension on-line as well. While much work remains to be done on the documentation, I think it is still of use to the interested.


Small C Extensions including...

* Linked Tcl_Obj Variables.
* Turn procedures into functions.
* Major/Minor Commands.
* A faster eval.


* Adjustable fonts in the standard message dialog. Patch to Tcl script. Tk8.0/Unix Only

You will need to apply this patch (using the patch program, of course) to .../tk8.0/msgbox.tcl (where ... represents where you've installed the platform independent library files.)

To set the font used by tk_messageBox, adjust the named font tkMessageBoxFont. This defaults to the font used by Tk before the patch was applied, but can be adjusted to anything you want using the font command. Note that this patch is pointless on the Windows and Macintosh platforms, since the standard dialog font is set elsewhere with them, and is not under the control of Tk.


Tclets and Games

Some fun tclets I've written:

Some games I've written:

A game I've cobbled together (sorry, but it isn't a Tclet at the moment. You'll need to save this one to a file and run it from there...)


For those interested in playing with trains (and also if you lack access to the standard X bitmap program,) I've written a little script that animates a few trains drawn using bitmap images.


If you have any problems, mail me and I'll see what I can do to help you out.

Valid HTML 4.0! Valid CSS!

Donal. K. Fellows, Computer Science, University of Manchester, U.K. / Tcl Core Team

About this page.