Abstract |
Python is proving to be a popular scripting language for implementing system functions for the linux operating system. GTK is the toolkit used by the Gimp and a number of other programs including GNOME. Glade is a GUI builder that allows for rapid GUI prototyping for GTK. James Henstridge has produced python bindings for GTK as well as a runtime library for glade xml files. The python code generator is a compile time approach to the same end. It parses a glade xml file and produces runnable python code that uses the python bindings for GTK. This code is freely distributed under the GPL. |
Usage |
python glc.py test.glade test.pyTakes test.glade as an input file and produces test.py as an output. Additionally, if signals are defined it will produce a file named by concatenating the name of the top level widget and "Handlers.py". Thus if the top level widget is window1, a file called "window1Handlers.py" will be produced if it does not already exist. As each handler is encountered, the handler file will be searched for a handler of the given name. If found, nothing more is done. Otherwise, if not found a function of the proper signature that does nothing will be produced. One can thus implement each signal handler in the handlers file. This implementation will never be overwritten. Click here for details on signal handling. |
Requirements |
More or less in the order given. |
Notes on this implementation |
|
Download |
You can download the python glade code generator here. |
Installation and testing. |
The download is simply a python script. This can be placed anywhere on your system that you like to place
python scripts. To test your installation, you can try the glade files found in the examples directory of the
pygtk distribution. You will also find glade.py in that directory which uses James' runtime approach.
For example, python glc.py test.glade test.py will produce test.py and window1Handlers.py. You can run the resulting files with python test.py window1Handlers.py should look like: from gtk import mainquit def mainfunc(window1Widget): window1Widget.window1.connect("delete_event", mainquit) def close_window(widget, mainObj): pass def on_hscale1_state_changed(widget, mainObj): passNote that you may freely add code or edit any of the existing handlers. In subsequent runs the code generator will never overwrite or edit any existing code in the handlers file even if changes are made to the glade file. If you remove widgets you must hand remove the handlers from the handlers file, since the code generator won't touch existing code. |