GNOME Bugzilla – Bug 720042
Using Gdk.Color and Gdk.RGBA in Gtk.ListStore doesn't work
Last modified: 2018-01-10 20:35:13 UTC
Created attachment 263726 [details] Test case Creating and using Gdk.Color and Gdk.RGBA works fine, but as soon as these are pushed into a TreeStore or ListStore, they lose their actual values. I notice some boxed type changes in 3.9+, so it's possible that this is already fixed. Test case attached. With 3.8.3, Gdk.RGBAs are all (0, 0, 0, 0), and Gdk.Colors are all (0, 0, <some random blue value>).
(In reply to comment #0) > ..I notice > some boxed type changes in 3.9+, so it's possible that this is already fixed. Verified this still seems to be a problem in master. There is a fairly easy workaround though: liststore = Gtk.ListStore(str, object, object, str) This will store boxed refs to the Python objects which wrap the color struct (GObject.TYPE_PYOBJECT).
Thanks for the workaround; at the moment I'm actually using the colour string as in the test case and that's fine too. It would be nice to fix however, just to have more self-documenting code.
I've debugged this and found the problem to be with value retrieval. The RGBA and Color structs make their way into the ListStore properly but getting the value out (via get_value), does not correctly do a boxed copy: https://git.gnome.org/browse/pygobject/tree/gi/pygi-marshal-to-py.c?id=3.11.3#n836 py_obj = pyg_value_as_pyobject (arg->v_pointer, FALSE); This needs to pass something else besides FALSE. Most likely it should be similar to what the _pygi_boxed_new this below does, taking into account transfer mode and is_allocated (and actually a quick check verifies it fixes this specific case). But first we need to add tests for retrieval of a GValue holding a boxed with different combinations of transfer and caller allocation flags to be totally sure.
*** Bug 787814 has been marked as a duplicate of this bug. ***
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/pygobject/issues/59.