I’ve been reworking my podcast grabber. When I started putting a GUI frontend on it, I decided to use Glade because I lack any skill whatsoever in GUI development. (Glade is a GUI builder application which stores the structure of an application in XML. It is also a library which interprets the XML file and allows your application code to interact with the GUI you built.) After using Glade to build a usable interface with most of the functionality I wanted, I felt like I lacked the desired level of control over my GUI. It has also been a little bit of a hassle to layer objects in deeper containers than what I would have expected. For example, I have a couple of TreeViews side by side and I wanted them to be embedded in an HPaned (horizontal pane) so I could easily resize them. In order to put my TreeViews inside of an HPaned, I had to add another row to my main VBox, add an HPaned to it, cut and paste each of my TreeViews into it, and then delete the now-empty VBox row. This wasn’t a deal-breaker for me and there is probably an easier way to do it, but it was a little bit of a nuissance.
I have been reading docs and playing with building a GUI app by hand using PyGTK. In my reading, I came across the concepts of Actions, ActionGroups, and UIManagers in PyGTK (actually, they’re gtk constructs which have PyGTK wrappers). You can find some documentation around Actions and ActionGroups in this section of the PyGTK tutorial. Basically, you create an Action for different things a user might want to do such as quit, open a file, edit configuration settings. These actions may have different ways the user can accomplish them such as a button, a menu item, or a keyboard accelerator. You attach an Action to a “proxy object” such as a button or menu item.
The UIManager provides a way to create menus and toolbars using an XML description. Some documentation for the UIManager can be found here.
Actions seem a much more code-maintenance-friendly way of associating actions with objects the user is going to interact with as opposed to the alternative: create an object (such as a button), specify all the attributes of it such as label, tooltips, etc, and (with Glade) create event handlers by name and associate the event name with some function. I guess the alternative isn’t so bad, but it’s nice to see a library provide facilities to make code management a little nicer.
There appears to be a steeper learning curve to building a GUI by hand than using something like Glade, but I’m hoping that it’ll pay off in a tighter level of control as well as ease of maintenance. I’ll post back as I make headway with coding PyGTK by hand.