GNOME Bugzilla – Bug 594231
Glade thinks all GtkVBox elements are horizontal
Last modified: 2010-03-25 20:30:19 UTC
Created attachment 142536 [details] Glade file which causes the error I have .glade files for my program, generated using glade 3.4.5. They load ok with 3.5.2, but show up as a total mess with 3.6.7 (all of them). It seems like every VBox is suddenly a HBox or something. I'm attaching the .glade file and the screenshots.
Created attachment 142537 [details] glade 3.6.7 screenshot (buggy)
Created attachment 142538 [details] glade 3.5.2 screenshot (good)
Theres not really a fix for this to be done in Glade, but I'll mark this one depending on the GTK+ bug just so that we have a flag bug open in the glade3 list.
Thanks, Is there at least a workaround so I can edit the files in 3.6.7? Why does it happen, anyway?
For now if you want to see it vertical in Glade you have to set the property to vertical explicitly, this will leave an explicit property setting to vertical (which is something you wont want if you are shipping to a GTK+ that doesnt know about that property yet). The reason why, is because the glade/gtkbuilder file format definition is that default properties are omitted in the xml, Glade introspects the reported property defaults by GParamSpec to determine the default. So now we have pre-orientable boxes with unset orientation, which is correct, but this means horizontal, because what the GParamSpec reports is inaccurate.
*** Bug 599874 has been marked as a duplicate of this bug. ***
So I have this horrible hack: +static void +fix_vertical_orientation (GObject *object) +{ + /* See bgo#594231 - GTK+ doesn't return the correct property defaults for + * orientable widgets which are vertical, so we have to fix them up. + */ + if (GTK_IS_VBOX (object) + || GTK_IS_VBUTTON_BOX (object) + || GTK_IS_VPANED (object) + || GTK_IS_VRULER (object) + || GTK_IS_VSCALE (object) + || GTK_IS_VSCROLLBAR (object) + || GTK_IS_VSEPARATOR (object)) + gtk_orientable_set_orientation (GTK_ORIENTABLE (object), GTK_ORIENTATION_VERTICAL); +} + ... but I haven't found the right place to call that function in the glade-3 sources. I tried glade_widget_constructor(), glade_widget_build_object(), and somewhere in glade-gtk.c. What would be the right place to do this? I know this is not the 100% correct fix (that would be in GTK+), but glade is unusable in its current state :(
Well, files created (or "fixed") using a GTK+ after the strangely introduced property in GTK+ are not affected. Glade can provide a way to "fix" a broken glade file explicitly, the code would look something like: - Add --fix-orientation option to src/main.c o Simple implementation: Add "fix-orientation" attribute to GladeApp o Cute implementation: Don't show the main window or run the main loop, just ouput the loaded Glade file to stdio - in plugins/gtk+/glade-gtk.c: o Consult read_widget() functions for correct classes o If needed, declare a read_widget() function in gtk+.xml.in for the class o In a function like glade_gtk_box_read_widget() you add: if (glade_app_fix_orientation()) force_subclass_contextual_orientation ();
Well. We can trash the property entirely with zero effort and just not support it in Glade (actually Im not sure why I wasted my brain cells trying in the first place). it will break any existing glade files which rely on manually setting orientation by completely excluding those properties from Glade output. I'm pretty convinced that I dont mind that breakage, usually what we do for false default values is always save them; our policy for completely broken cases like "orientation" can be to just not allow its configuration in Glade until the day the toolkit false default is fixed; then we can expose it for projects targeting GTK+ versions >= false default bug fix. Objections ?
Just to be sure (as I don't quite understand the internals of what's happening here): Will this make the old files (made with 3.4.5) loadable again? Will this affect loading of these files in gtk 2.8 or later through libglade (because I need to support that), or by converting them with gtk-builder-convert for gtk >= 2.12 and loading the converted files through GtkBuilder? Thanks
No this will not create any bugs along those lines, "disabling" the orientations will just make Glade forget about orientation all together. If files specify an orientation, it will be forgotten at load time and omitted at save time. BTW: saving as libglade format and calling gtk-builder-convert script happens to work (its a migration path for GTK+ made when Glade did not support GtkBuilder) - Glade does not explicitly support this conversion, please convert with Glade instead (if you want Glade to read the files after it makes sense to convert them with Glade).
Thanks. I guess I'll be able to finally upgrade my Glade installation then. A bit off topic: I use Glade to generate .glade files, and my configure system generates GtkBuilder files using gtk-builder-convert if gtk >= 2.12 is found (thus avoiding libglade dependency when possible). (Actually, it pre-generates them and includes them in tarball when running "make dist"). I don't need to load the generated files in Glade. So far, this setup works well across many different OS and GTK versions. If I ever drop the gtk < 2.12 support, I'll be sure to convert them using Glade. I can't find any automated way for that though...
The main problem I see can happen at transition time is gtk-builder-convert might make your application addicted to UIManagers. If its a possibility that people need that parallel dual format support, ideally we should just include an option to run the conversion with Glade: %.ui:%.glade glade-3 --target-format=GtkBuilder $< > $@ %.glade:%.ui glade-3 --target-format=libglade $< > $@ I could be pretty easy to implement by not doing gtk_main() and not showing the application, but it will require X to run (GTK+ has to be initialized because at this point GtkWidgets need to be created, that could be avoided for a dry run but it would be quite a bit more work). You could then have the option to do the conversion backwards and optionally use some more advanced GtkBuilder features in >= 2.12.
To avoid making any further off-topic comments here I filed a feature enhancement request at: https://bugzilla.gnome.org/show_bug.cgi?id=613931
Created attachment 157095 [details] [review] glade3-bgo594231-fix-vorientation.diff This disables the "orientation" property for GtkVBox and other vertical widgets. It seems to work correctly for me; old .ui files loaded show up correctly, and the re-saved versions don't have an "orientation" property defined either.
Review of attachment 157095 [details] [review]: Ok great so: its not going to make sense to expose the property for GtkHVariants but not GtkVVariants so we should also disable it for anything horizontal as well - I like that its disabled at the subclass level and not at GtkBox level, as I expect in the future they will be instantiatable and we'll expose them enabled at that point. also, we maintain a ChangeLog in Glade; I dont need to see it in the patch but since many projects nowadays dont maintain one - just a reminder ;-)
Created attachment 157099 [details] [review] glade3-bgo594231-fix-vorientation.diff Oops, you are right; I missed the horizontal widgets. This fixes it.
Review of attachment 157099 [details] [review]: Thanks, it will be great to forget about this for a while.
No problem. Pushed to master as ecac9ea.