Glade is an interface
builder for the open-source GTK toolkit library for
Glade allows you to develop a
GUI interface by interactively picking, placing, and modifying widgets
on an interface panel. The GUI editor produces an XML file describing
the interface; this, in turn, can be fed to one of several code
generators that will actually grind out C,
Perl code for
the interface. The generated code then calls functions you write to
supply behavior to the interface.
Glade's XML format for
describing GUIs is a good example of a simple domain-specific
minilanguage. See Example8.1 for
world!” GUI in Glade format.
Example8.1.Glade “Hello, World”.
A valid specification in Glade format implies a repertoire of actions
by the GUI in response to user behavior. The
Glade GUI treats these specifications as
structured data files; Glade code
generators, on the other hand, use them to write programs implementing
a GUI. For some languages (including Python), there are runtime libraries that
allow you to skip the code-generation step and simply instantiate the
GUI directly at runtime from the XML specification (interpreting Glade
markup, rather than compiling it to the host language). Thus, you get
the choice of trading space efficiency for startup speed or
Once you get past the verbosity of XML,
Glade markup is a fairly simple language.
It does just two things: declare GUI-widget hierarchies and associate
properties with widgets. You don't actually have to know a lot about
how glade works to read the specification
above. In fact, if you have any experience programming in GUI
toolkits, reading it will immediately give you a fairly good
visualization of what glade does with the
specification. (Hands up everyone who predicted that this particular
specification will give you a single button widget in a window
This kind of transparency and simplicity is the mark of a good
design. The mapping between the notation and
domain objects is very clear. The relationships between objects are
expressed directly, rather than through name references or some other
sort of indirection that you have to think to follow.
The ultimate functional test of a minilanguage like this one is
simple: can I hack it without reading the manual? For a significant
range of cases, the Glade answer
is yes. For example, if you know the C-level constants that GTK uses
to describe window-positioning hints, you'll recognize GTK_WIN_POS_NONE as one and instantly be able to
change the positioning hint associated with this GUI.
The advantage of using Glade should be clear. It specializes in
code generation so you don't have to. That's one less routine task
you have to hand-code, and one fewer source of hand-coded bugs.
More information, including source code and documentation and
links to sample applications, is available at the Glade project page.
Glade has been ported to