I’m working on a Linux application which uses GTK for its user interface. Instead of hard-coding each and every GUI element, it uses a library called libglade which reads a GUI definition file and dynamically creates the GUI elements at runtime. The definition file can be edited by a WYSIWYG editor called Glade.
The application is still using GTK2 instead of the latest-and-greatest GTK3. GTK2 is still supported by most Linux distributions, so no problems here. On the other hand, the Glade editor provided by my Linux distribution does not allow editing GTK2 libglade definition files. And when I say “does not allow”, I mean “nothing happens when I select a GTK2 glade file for opening”. Not a warning, nothing. It just acts like I clicked Cancel in the file open dialog. First WTF.
Fortunately, I found a version of Glade which is able to edit GTK2 definition files, and can be installed on my system without much trouble. Unfortunately, it is recent enough to apparently have some “transitional” features between GTK2 and GTK3.
Instead of allowing the user to put GUI controls anywhere in a window, GTK uses layout management objects. GTK2 provides a container named GtkHBox (Horizontal Box), which lays out its child items horizontally, and a corresponding GtkVBox (Vertical Box). On GTK3, GtkHBox and GtkVBox are deprecated in favor of using GtkBox with a specified orientation.
As it turns out, in my “transitional” Glade editor, the GtkVBox/GtkHBox containers have an “orientation” property, so you can have for instance a vertical horizontal box. Here is what it looks like when you create these items in the editor:
Not only it’s silly, it may also get confusing since the editor trusts the “orientation” property in its WYSIWYG view whereas libglade applications will use the real container type when loading the definition file. So basically, a GtkHBox with a vertical orientation will lay out its items vertically in the Glade editor but horizontally when used in the actual app.
I’m not done yet. Notice that the “Orientation” property of the GtkVBox is in bold. It means that it is not the default setting. Yes, in the context of the editor, the default orientation of a vertical box is horizontal. So guess what happens when I load an old GTK2 definition file which of course does not have orientation properties on the Gtk*Boxes ? It will be fixed automatically, right ? Wrong!
As you may guess, the layout shown in the editor was quite interesting (menubar on the left, followed by the toolbar, etc...)
After briefly looking for better solutions, I opened the definition file in a text editor (it’s an XML file) and inserted <property name="orientation">vertical</property> in each vertical container. Problem solved!