GNOME Bugzilla – Bug 650369
GtkComboboxText is not properly initialized
Last modified: 2014-11-14 02:07:48 UTC
I'm using PyGI on Fedora 15. As I outlined on the mailing-list [0], there is a difference in behavior between using Gtk.ComboBoxText() and Gtk.ComboBoxText.new(). The former leads to a broken widget (see the email [0] for more details). John suggested that this would be a bug in Gtk+ [1] """ I thought this was fixed in Gtk+ but it might just be another object that does its setup in the wrong place. We use g_object_new to instantiate a gobject so if the gobject does any setup code in its constructor, that never gets run. Constructors should be convenience methods. All objects should set sane defaults in their init method. I would file a bug on Gtk+ and just use the new constructor for now. """ [0] http://mail.gnome.org/archives/python-hackers-list/2011-May/msg00001.html [1] http://mail.gnome.org/archives/python-hackers-list/2011-May/msg00007.html Note: I chose component GtkComboBox for this bug as there isn't a GtkComboBoxText one.
All GtkComboBoxText constructors just use g_object_new themselves. So, if there is a problem here, you will have to do some more research what it is.
Is this the same problem as the one described in bug 653579 (gtkmm, C++ language binding)? gtk_combo_box_text_new() sets the GtkComboBox attributes entry-text-column=0, id-column=1. A language binding (or any other user) that uses g_object_new() will not set those attributes, unless they are included in g_object_new's parameter list. They will get their default values as specified in GtkComboBox. Wouldn't it be possible (and better) to set those attributes unconditionally in gtk_combo_box_text_constructor()?
I put a patch for this long ago in bug 612396.
GtkBuilder creates widgets with g_object_newv(). See _gtk_builder_construct(). Therefore a GtkComboBoxText created by GtkBuilder will not work properly unless the user sets entry-text-column = 0 and id-column = 1. No user should have to do that. See also this message to the gtkmm-list: http://mail.gnome.org/archives/gtkmm-list/2011-September/msg00091.html
This bug is still present (at least with the libraries shipped with Ubuntu 11.10). I'm experiencing the same issues as Mathieu Bridon with using the gir gtk3 bindings. Kjell's workaround seems to work for now. This bug should really at least have it's status changed from unconfirmed.
The gtk+ bug 612396 has been fixed. Probably this bug is then also fixed. I have checked 1. Gtk::ComboBoxText in gtkmm (the C++ binding) with the fix in bug 653579 undone, 2. a simple example with Glade and Gtk::Builder (also C++). This bug concerns problems with the Python binding. I don't work with Python. Perhaps someone else can check if the Python problems are fixed, and close this bug if they are.
Problems with python + gtkbuilder is still there, at least with pygtk 2.24.0 in Fedora 16. In my .ui file I have the following: <object class="GtkComboBoxText" id="text_align"> <property name="visible">True</property> <property name="can_focus">False</property> <items> <item translatable="yes">Left</item> <item translatable="yes">Center</item> <item translatable="yes">Right</item> </items> </object> And in my python code I have this line: foo = self.builder.get_object("text_align") Which crashes the thing with the following error: TypeError: Cannot create a consistent method resolution order (MRO) for bases GInterface, CellEditable, CellLayout ** ERROR:pygobject.c:963:pygobject_new_full: assertion failed: (tp != NULL) Aborting And then, if I try the workaround from comment #4 using glade, like so: <object class="GtkComboBoxText" id="text_align"> <property name="visible">True</property> <property name="can_focus">False</property> <property name="active">0</property> <property name="entry_text_column">0</property> <property name="id_column">1</property> <items> <item translatable="yes">Left</item> <item translatable="yes">Center</item> <item translatable="yes">Right</item> </items> </object> ... I get the following: foo.py:90: GtkWarning: Unknown property: GtkComboBoxText.id-column self.builder.add_from_file(os.path.join(get_ui_dir(), "texteditor.ui")) TypeError: Cannot create a consistent method resolution order (MRO) for bases GInterface, CellEditable, CellLayout ** ERROR:pygobject.c:963:pygobject_new_full: assertion failed: (tp != NULL) Aborting Let me know if there's something else I can try or additional information I can provide.
The fix in gtk+ bug 612396 comment 67 is included in gtk+ version 3.4. If there is a version of the Python binding based on gtk+ 3.4, it might be worth testing if this bug has been fixed there. Or in the git master branch. As I said in comment 6, I don't work with the Python binding. I leave such a test to someone else.
THis seems fixed, both with my original reproducer and with Jean François GtkBuilder example. gtk3-3.14.4-1.fc21.x86_64 pygobject3-3.14.0-1.fc21.x86_64