Felix Rambles

Another step to taking back control

GtkDialog and missed chances

06 November 2019 — Felix Ple┼čoianu

After rediscovering Puppy Linux earlier this autumn, I got the chance to re-evaluate a number of technologies I had run into before and forgotten about. One of them is BaCon, a.k.a. the Basic Converter, that I already used successfully for half a dozen game ports and a little utility, with more to come. Another is GtkDialog.

Wait, what's GtkDialog? You can think of it as a powerful alternative to Xdialog, but it's really much more. Thanks to a markup language that resembles XML (but apparently isn't), you can tell it to make any kind of GUI, even with a menubar, and it will reply with everything the user entered when they press OK. That's not where GtkDialog shines though; among other things, you can make buttons run some shell command then refresh another widget, which itself reads from the shell:

<window title="Hello, GtkDialog!">
 <vbox>
  <entry>
   <variable>OUTPUT</variable>
   <input>cat /tmp/gtk-date</input>
  </entry>
  <hbox>
   <button>
    <label>Refresh</label>
    <input file stock="gtk-refresh"></input>
    <action>date > /tmp/gtk-date</action>
    <action>refresh:OUTPUT</action>
   </button>
   <button>
    <label>Quit</label>
    <input file stock="gtk-quit"></input>
    <action>EXIT:OUTPUT</action>
   </button>
  </hbox>
 </vbox>
</window>

Feed this to GtkDialog, e.g. via the --filename or --stdin options, and you've got yourself a graphical front-end to a command-line utility that was never meant to have one.

So why have you never heard of this little wonder?


That's a good question. Turns out, as of this writing GtkDialog hasn't been maintained for 6 or 7 years, and most Linux distributions have dropped it from their repositories. Sure enough, the most detailed resource appears to be this thread on the Puppy Linux forums, where its only users can (still) be found. And it looks like a missed opportunity. As someone in the same forums points out, this tool really should be part of the Gtk framework. Doubly so as it also reads Glade files.

The answer, in my opinion, is as simple as it is sad: you can do all the same things much more cleanly with Tcl/Tk.

#!/usr/bin/env wish

package require Tk

wm title . "Hello, Tcl/Tk!"

ttk::entry .output -textvariable output
pack .output -side top -padx 4 -pady 4 -ipady 4

ttk::button .quit -text Quit -command exit
pack .quit -side right -padx 4 -pady 4

ttk::button .refresh -text Refresh -command {set output [exec date]}
pack .refresh -side right -padx 4 -pady 4

Note how this version is shorter by a third, and I got it right almost on first try, despite barely touching Tcl/Tk for the past two decades. Even better, Tcl/Tk is actively maintained and widely deployed for a change. And because it's a proper programming language rather than some ad-hoc configuration format, you can use it to solve many problems directly instead of calling out to external commands, balancing the two any way you like.

GtkDialog however has one big advantage: it doesn't look like programming. And that happens to be important nowadays. Never mind that having alternatives is always a good thing, for several reasons.

I won't be needing GtkDialog, to be honest. I can however mourn yet another cool technology that missed its chance, and think of useful ideas to maybe rescue from it. Empowering computer users to solve their own problems again would be worth it.

P.S. Just for kicks, I also coded a version of the same exercise in BaCon:

INCLUDE "hug.bac"

HUGOPTIONS("TABLE 10 2")

top = WINDOW("Hello, HUG!", 300, 60)
output = ENTRY("", 10, 1)
ATTACH(top, output, 0, 0)

b_refresh = STOCK("gtk-refresh", 4, 1)
ATTACH(top, b_refresh, 2, 1)
CALLBACK(b_refresh, do_refresh)

b_quit = STOCK("gtk-quit", 4, 1)
ATTACH(top, b_quit, 6, 1)
CALLBACK(b_quit, QUIT)

SUB do_refresh
    TEXT(output, EXEC$("date"))
END SUB

DISPLAY

As it turns out, it's exactly as long as the GtkDialog version, except much more readable. You do need to know how layout works here, but otherwise? I'd say we have a winner. And that's a big hint if you're in charge of a Linux distro and have to pick one language in which to write you system configuration tools.

Tags: Linux, programming

Comments? Tweet