Updated 2014-04-08 20:24:27 by pooryorick â–˛

Richard Suchenwirth 2003-01-04: Ever since Michael Jacobson brought Tclworld to a PocketPc, I dreamt of such a little thing, and this Xmas I made that wish come true. I chose a Compaq iPAQ 3760, which is relatively affordable and tiny (about the size of a pack of cigarettes), yet has quite some capacity (64 MB RAM + 6.5 MB FlashROM). No card slots, though - I link it to the outside world with its "docking station" on my PC at work.

Life before Tcl: The supplied software is Windows/CE with more or less stripped-down "pocket versions" of Microsoft Word, Excel, Explorer, IE, Outlook, Media Player, eBook reader, Solitaire. Input can be done by pen-clicking on a virtual keyboard, or three flavors of pen-stroke recognition. The optional word completion quickly adapts to the used vocabulary (Tcl commands too), so I have it on by default. Pocket Excel even offers a Unicode character selector, barely usable due to a too small font, but allowing at least some Greek and Cyrillic input.

Pocket Tcl: Of course, my real goal was to have Tcl on the little box, and after the synchronization worked, this went very smoothly following the download and instructions at Windows/CE - many thanks to Rainer Keuchel for the excellent port (8.4a2, still without lset and 64-bit wide integers)! I only deviated from the instructions by putting celib.dll into the Tcl/bin directory - works equally well, and the File Explorer hides .dll and other file types, so I could not copy it into /Windows. The provided tclsh84d comes in a console window, but without (visible) scrollbars or cursor-up history, so I take TkCon for interactive tests, with the font set to Tahoma 7 (a screen size of 240x320 pixels encourages use of compact fonts...), and enjoy its extras, e.g. the ls -l command. Others can be added for brevity, e.g.
interp alias {} cp {} file copy -force

PocketWord allows plain text editing, but such files must have a .txt extension. One nuisance is that in Tk text widgets the cursor often changes position, so one has to watch out when typing. Therefore I still use PocketWord for Tcl scripts with .txt extension, and execute them from Tkcon. Only when finished they are renamed to the .tcl extension, and can be executed on single click.

Another minor problem: font families returns T C F B (for Tahoma, Courier New, Frutiger, Bookdings), but these single-letter font names are not honored - they all fall back to Tahoma. See font families workaround.

First experiments show that primary colors can well be produced by their usual (English) names. Canvas line objects don't take a -fill color if more than a pixel wide. Tk windows have their own title bar (in addition to the constant bar on top), with hidden minimize and maximize buttons to the left of the X close button, and can be dragged or resized by rather precise pen-pointing. You can win some screen estate (3 lines) by
 tkcon eval wm geometry . 43x17+0+0

which pushes the Tk title bar below the Windows one, thereby hiding its X button. Raising a covered window goes best with the iTask utility - make sure that execs from tkcon are in the background with &, otherwise iTask will not respond (probably because it receives no response from Tkcon - you can kill a hanging program in the Settings/System/Memory menu).

Most of the seven hardware keys are intercepted by CE, so not usable in Tk bindings - except for the big center navigation key (over the speaker) which produces two key events on each push: <Return> when pushed centrally; <Up>/<Down>/<Left>/<Right> in the cursor directions, plus another nondeterministic event from <R1>,<R3>, and some accented Eurolatin letters. I use the command
bind . <Return> {exec wish $argv0 &;exit}

for quick restarts of a script under development. The following scriptlet let me find out the multiple keybindings:
# bindview.tcl
text .t -wrap word -xscr ".y set" -font {f 7} -width 43 -height 17
scrollbar .y -com ".t yview"
pack .y -side right -fill y
pack .t -fill both -expand 1
bind . <Key> {
    .t insert end %K,%N/%A\n
    .t see end

The Tcl/Tk documentation can be conveniently used by downloading the tar.gz-ed HTML pages from AS, and unpacking them (on the desktop box) into a synchronized directory. A link to the toplevel page in the Start menu makes it easily reachable for IE (with font size set to very small).

Tcl development on the little box is harder work than on a big one, but the joys of mobility and rapidity (no shutdown/boot time needed) speak for the handheld (occasionally accompanied by soft music from the MP3 player in the background ;-)...

Expect more Wiki pages out of my little thing in the next time! For starters, here's a little stopwatch:
#stopwatch.tcl - R.Suchenwirth 2003
label .t -textvar t -relief sunken\
    -font {Frutiger 36} -width 8
eval pack [winfo children .] -anchor w
set t 0:00.00
proc every {ms body} {
    eval $body; after $ms [info level 0]
proc tick {} {
    set dt [expr {[clock cli -mi]-$::t0}]
    set ::t [format %d:%05.2f [
        expr {$dt/60000}] [
        expr {($dt%60000)/1000.}]]
bind . <Return> {
    if {$t eq "0:00.00"} {
        set t0 [clock click -mi]
        every 10 tick
    } elseif {[llength [after info]]} {
        after cancel [after info]
    } else {set t 0:00.00}

MPJ: Here is a picture of the stopwatch being run on a pocketpc (in this case a HP Jornada 525).

If you have instead installed Linux on your iPAQ, you can get a Tcl port (8.3.4) from http://members.chello.nl/~k.vangelder/ipaq/feed/

See also http://pockettcl.sourceforge.net/

There's a Tclkit 8.4.1 build at [1].

emukang: I wrote some thing about install tcl on Ipaq linux PDA, and the problems you could meet. Please have a look of Install tcl on ipaq familiar linux PDA with Img package

To start up Tkcon with suitable defaults, I have produced a file /tkcon.cfg (in the toplevel directory) with following contents:
tkcon eval wm geometry . 43x17+0+0
after 1000 {tkcon font Tahoma 7}

Without the after, Tkcon would raise an error of missing tkcon::PRIV(console).

As defaults for all wish applications, I have added the following lines to lib/tk8.3/tk.tcl:
# iPAQ specific:  small font
option add *font {Frutiger 7}
option add *Button*borderWidth 1
option add *padY 0

This way, some valuable pixels are saved...

TkCon is a great console for the little box and offers some unix-like commands (ls, echo..). For shortness in tapping, I added more into the following file Unix.tcl, whose aliases I can "require" by the dummy unix command after a tclIndex has been produced:
# Unix-like commands for TkCon - RS 2003-02-11
# Put this file in Tcl/lib, auto_mkindex there
# Autoloading bait, because aliases are not in auto_index
proc unix {} {return "unix tools 0.1"}
proc cat fn {
    set fp [open $fn]
    set res [read $fp]  
    close $fp
    set res
interp alias {} cp {} file copy -force
interp alias {} mkdir {} file mkdir
interp alias {} mv {} file rename
interp alias {} rm {} file delete -force

Regular polygons shows how we can have ovals, even if not yet supported by Tk on the iPAQ, by approximating them in Tcl. More iPaq fun projects (but the full list is at PocketPC):

http://www.microsoft.com/mobile/pocketpc/downloads/powertoys.asp has

Remote Display Control for Pocket PC: "With the Remote Display Control application, you can display actions on a Pocket PC, including user input, remotely on the display of a desktop or laptop personal computer. This is a great tool for demonstrating the power of the Pocket PC to a large audience. It also allows developers to test their applications for the Pocket PC on a larger screen. Remote Display Control uses TCP/IP, and it can work with ActiveSync® connections via Ethernet or dial-up. This download is intended for English Windows Powered Pocket PC only. (4/27/2001)"

RS: Works charmingly between iPaq and XP - highly recommended for presentations, or UI debugging!

On a weekend trip the catastrophe happened: power ran dry, cold reset, all data lost. I suspect it was that I touched the Record button by accident, so it went on recording until all was too late. Therefore I now associate a harmless action (Calculator) to the button at top left, which follows the power down rules (e.g. after 2 minutes) if accidentally started. (RS)

In German: Tcl/Tk: Programmieren auf dem PocketPC

SEH 2005-01-18: Dave capella has written a suite of Tcl/Tk utilities for his iPaq [2]:

  • tkRolo Cross-platform addressbook written in tcl/Tk. Uses a tab-delimited, flat file for easy import and export.
  • tkpwdb Cross-platform, password manager written in tcl/Tk.
  • tkShop Cross-platform, grocery list manager written in tcl/Tk.
  • tkToDo Utility to keep track of one's Round Toit's. Written in tcl/Tk.

RS: After two and a half years, my iPaq failed to take power from the adaptor, so died a slow death. His successor now is a HTC Magician.

SEH 2006-08-09: Ruby Agenda is an Agenda/Schedule application aimed at use on an iPAQ, but works just as well on your desktop. Ruby Agenda is written in Ruby with Tk bindings.

Available at: [3]

Tk-AppMaster is a Perl/Tk launcher program specifically designed for handhelds (with the focus to familiar linux), but should also work on desktop environments. Included with the launcher is a set of modules for a PIM-like environment.

The set of modules in work is: address book, application lister, audio recorder, calculator, calendar, command launcher, editor, support for the familiar linux menu system, virtual keyboard support, mail reading and sending, process lister, sending SMS via Siemens cellphones, a simple spreadsheet module, ipkg manager, and various system utilities.

Available at: [4]