Re: ComboBoxText and constructor/new issues



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.

----- Original Message -----
> Hi,
> 
> I have been trying to use a Gtk.ComboBoxText and something seems weird
> to me: if I create the combobox with Gtk.ComboBoxText.new(),
> everything
> works as expected, but if I create it with Gtk.ComboBoxText(), the
> class
> seems to be in a state where lots of things will not work afterwards.
> 
> Take this short example:
> 
> -- BEGIN EXAMPLE ------------------------------------------
> from gi.repository import Gtk
> 
> def quit(w):
> Gtk.main_quit()
> 
> w = Gtk.Window()
> w.connect("destroy", quit)
> 
> b = Gtk.Box()
> w.add(b)
> 
> combo1 = Gtk.ComboBoxText.new()
> combo2 = Gtk.ComboBoxText()
> 
> for i in range(10):
> combo1.append("id-%s"%i, "text-%s"%i)
> combo2.append("id-%s"%i, "text-%s"%i)
> 
> combo1.set_active_id("id-3") # Works as expected
> combo2.set_active_id("id-3") # FAIL: Doesn't set anything as active
> 
> print("####")
> print(combo1.get_active_id()) # Prints 'id-3'
> print(combo1.get_active_text()) # Prints 'text-3'
> print(combo2.get_active_id()) # FAIL: Prints 'None'
> print(combo2.get_active_text()) # FAIL: Prints 'None'
> 
> combo1.set_active(3) # Works as expected
> combo2.set_active(3) # This works as expected, yay!
> 
> print("####")
> print(combo1.get_active_id()) # Prints 'id-3'
> print(combo1.get_active_text()) # Prints 'text-3'
> print(combo2.get_active_id()) # FAIL: Still prints 'None'
> print(combo2.get_active_text()) # FAIL: Still prints 'None'
> 
> b.pack_start(combo1, True, True, 0)
> b.pack_start(combo2, True, True, 0)
> w.show_all()
> -- END EXAMPLE --------------------------------------------
> 
> First of all, I derived that from looking at the C example in
> gtk3-demo,
> so I am not even sure of the way I'm using the comboboxes. If I am
> wrong, I would appreciate some pointers on how to do it properly.
> 
> Now to the first question: is this difference of behavior expected?
> Should I never use the constructor but always use .new()?
> 
> Second, when defining the Gtk.ComboBoxText in a .ui file with
> Gtk.Builder, then the widget seems to be created with
> Gtk.ComboBoxText()
> rather than Gtk.ComboBoxText.new(), and everything fails consequently
> (I'm not sure of that, but the observed behavior is consistent with
> what
> happens in the previous example).
> 
> Again, is that expected? Is there something I missed that could make
> the
> combobox work with Gtk.Builder?
> 
> Should I report a bug?
> 
> I didn't find anything about this in the documentation or the wiki
> pages, but I might have overlooked something.
> 
> This is on Fedora 15 with python3-gobject-2.28.4 and
> gobject-introspection-0.10.8.
> 
> Thanks in advance,
> 
> 
> --
> Mathieu
> 
> 
> _______________________________________________
> python-hackers-list mailing list
> python-hackers-list gnome org
> http://mail.gnome.org/mailman/listinfo/python-hackers-list

-- 
--
John (J5) Palmieri
Software Engineer
Red Hat, Inc.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]