16 Feb 2009 lloydwood   » (Journeyer)

Tcl/Tk on Mac OS X

...is complex, bizarre, and quite oddly broken.

I maintain SaVi, which uses Tcl/Tk, and is reasonably crossplatform and portable thanks to relying on the unix C libraries, turning on every useful warning flag, and keeping its decades-old code uptodate with compiler changes etc.

Porting SaVi to Mac OS X 10.4 Tiger meant updating SaVi's ten-year-old menubar code to use newer menu commands which know about the Mac menubar. (This also produced more Windows-like menus under Cygwin's Insight Tcl/Tk.) Workarounds for Mac-only Tk crashes - don't make your listbox too wide or Aqua Tk will hang in an infinite drawing loop! - were found.

Then 10.5 Leopard came out and I bought an Intel Macbook, expecting to run SaVi in style. The Tcl/Tk menuing code that worked in Tiger didn't work in Leopard's Xcode with its Tcl/TK 8.4.7 install. At all. (Other Leopard bugs with OpenGL linking and so on took a while to find workarounds for, but not having working menus is a bit of a showstopper.)

So, I immediately retrofitted my old code, with a command-line flag to select menu drawing methods. Popop menus from the window on a Mac aren't elegant, but they're functional. And I started to look into the menubar problem and Tcl/Tk on the Mac more closely.

Over a year later, I'm giving up. I haven't found a fix for the menubar problem with the default Tcl/Tk 8.4.7 install. I've attempted to update the installed version of Tcl/Tk, using ActiveState, Fink, and reputable Aqua installers. These all install something, but don't dare touch the libraries in /usr/lib, to avoid breaking things. So, SaVi always gets compiled with Tcl/Tk 8.4.7, because /usr/lib is where the compiler looks.

Now, is the menubar problem fixed in later versions of Mac Tcl/Tk? The answer to that question doesn't matter, because the chances of SaVi's Mac Leopard userbase building SaVi with anything but Tcl/Tk 8.4.7 is vanishingly small. Saying 'just double-click this Tcl/Tk installer after you install Xcode' is a non-starter, because those installers don't update any libraries in the default locations that I can link to. Those packages seem to be emphasising the Mac-specific Framework stuff, rather than the crossplatform unix libraries.

(Complicating things slightly is that on the Mac there's the 'Aqua Tk' and the 'X Tk'. SaVi is a unix program, but lost its X dependencies years ago to work with Cygwin's Insight Tcl. So SaVi takes full advantage of Aqua Tk and the Mac interface. Apart from the menubar, of course. I haven't needed to experiment with the X Tk.)

SaVi 1.4.2, released last week, is my admission of failure. It is the first version of SaVi to default to popup menus on the Mac; Tiger users will just have to turn this off.

Cygwin was so much easier and simpler than the Mac.

Update: The menubar problem was fixed in the Mac OS X 10.6 Snow Leopard release.

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!