GNOME Bugzilla – Bug 670575
GtkSeparatorMenuItem looks wrong
Last modified: 2012-06-26 04:11:49 UTC
Created attachment 208178 [details] C version looks correct The GtkSeparatorMenuItem widgets in the menubar look wrong. There should be a horizontal line separating the menu items, but instead, there is only an empty space. In other words, there's a space separating the two menu items, but there's no horizontal line. I'm using Gtk 3.2.3 and Python 3.2.2. I'm using the default Gtk theme. I don't see this problem when using Gtk in C. I'll attach two example applications: one in C and one in Python. I wrote them to be as similar to each other as possible. The C version displays correctly and the Python version displays incorrectly. Thank you.
Created attachment 208179 [details] Python version looks incorrect
Workaround for now is to use Gtk.SeparatorMenuItem.new(). This is weird because gtk_seperator_menu_item_new uses g_object_new to create the object so behaviour should be the same. There is definitely a bug somewhere.
Wonder if it has to do with overrides.
I tried this here with both Python 2.7.2 and Python 3.2.2, with pygobject 3.1.1 and GTK 3.3.16 and it works fine. I see the separator even with Gtk.SeparatorMenuItem(), but also with Gtk.SeparatorMenuItem(). gtk_separator_menu_item_new() does not do anything magic, just calls g_object_new(), so the reason is not the GObject vs. the real constructor, and there is no override. The constructor also did not change since GTK 3.2. So I'm afraid I cannot reproduce this.
Can reproduce with pygobject 3.2.0.
Created attachment 217225 [details] [review] Only passes "label" in the Gtk.MenuItem constructor if it is set.
I can reproduce and I have a proposed fix. Anytime the "label" or "use-underline" properties are accessed in GtkMenuItem it calls gtk_menu_item_ensure_label() which creates the child GtkAccelLabel widget. It only renders the menu item as a separator if there is no child widget. The override for Gtk.MenuItem passes `None` for the "label" which results in an empty GtkAccelLabel being created for the label. Thus the widget is not drawn as a separator since it has a child. The same effect happens if you try to get the "label" property on a GtkSeparatorMenuItem (in Python or C). The Gtk.SeparatorMenuItem.new() function obviously does not touch "label" so it works. I'm not sure if this is the *right* fix, but, only using the "label" keyword argument property if it is actually set in the Gtk.MenuItem override seems to work. I'll attached a patch
Nice catch, thank you! Committed.