Martin Pool's blog

Glade and Python

Python and Glade is quite a neat little rapid development tool. In about five minutes, without using it very much before, I could write a tiny but handy GUI utility to tweak X11 monitor settings:

#!/usr/bin/env python
import sys, os
import pygtk
pygtk.require('2.0')
import gtk
import gtk.glade

fname = 'gammaknob.glade' xml = gtk.glade.XML(fname)

def gtk_main_quit(*args): gtk.main_quit()

def on_gamma_scale_value_changed(gamma_scale): os.system("xgamma -gamma %f" % gamma_scale.get_value())

xml.signal_autoconnect(locals())

gtk.main()

It still has that Linuxy loosely-coupled feeling: you can't (?) edit Python source directly inside Glade, and you have to copy in a tiny bit of boilerplate to get it going. That's not necessarily a problem; keeping it separate has some advantages.

One very cool thing is that because the user interface description is cleanly separated from the code you can run the exact same XML file with either a Python, C, or other language implementation. So a mockup in Python can directly transform into a release in C. (Although for many things just sticking with Python might be OK.)

Archives 2008: Apr Feb 2007: Jul May Feb Jan 2006: Dec Nov Oct Sep Aug Jul Jun Jan 2005: Sep Aug Jul Jun May Apr Mar Feb Jan 2004: Dec Nov Oct Sep Aug Jul Jun May Apr Mar Feb Jan 2003: Dec Nov Oct Sep Aug Jul Jun May