After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 684094 - Error when attempting to set a value in a ListStore to None
Error when attempting to set a value in a ListStore to None
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: introspection
3.3.x
Other Linux
: Normal minor
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
: 691660 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2012-09-15 14:57 UTC by Nick Hall
Modified: 2013-01-14 06:37 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Allow setting TreeModel values to None (2.13 KB, patch)
2013-01-14 04:06 UTC, Simon Feltman
committed Details | Review

Description Nick Hall 2012-09-15 14:57:08 UTC
It should be possible to set a value in a ListStore or TreeStore to None using the set_value method, but it gives the following error:

TypeError: Argument 3 does not allow None as a value

It is possible to append a row with None as a value.

>>> from gi.repository import Gtk
>>> l = Gtk.ListStore(str)
>>> r1 = l.append([None])
>>> r2 = l.append(['abc'])
>>> l.set_value(r2, 0, None)

The default for many attributes of cell renderers is None, for example, foreground and background colours and the stock_id of pixbufs.

A set_cell_data_func can be used as a workaround when the Store is used as a model for a TreeView.
Comment 1 Martin Pitt 2012-09-17 10:07:00 UTC
The defaults are, yes, but if you try to call gtk_tree_store_set_value () with a NULL GValue, you get an error like in

  http://git.gnome.org/browse/pygobject/commit/?id=8d85d6639778ec

So we mirror the GTK API which does allow uninitialized cells, but does not have an API to set a cell back to "uninitialized". Or am I missing something in there? (it's rather easy to miss something in TreeView/Model :-) )
Comment 2 Nick Hall 2012-09-17 14:52:33 UTC
Thanks for your quick reply.

I have investigated this further.  In C, gtk_tree_store_set does allow NULL values to be set, but gtk_tree_store_set_value does not.  pygtk allows None in both the set and set_value methods.

The problem is that pygobject does not allow None in either set or set_value.
Comment 3 Simon Feltman 2013-01-13 21:28:39 UTC
*** Bug 691660 has been marked as a duplicate of this bug. ***
Comment 4 Simon Feltman 2013-01-14 04:06:06 UTC
Created attachment 233416 [details] [review]
Allow setting TreeModel values to None

Change TreeModel.set_value to use an empty but initialized GValue when
None is used as the value argument. This allows clearing of cell data
which was not accessible due to auto-coercion.
Comment 5 Martin Pitt 2013-01-14 06:04:59 UTC
Comment on attachment 233416 [details] [review]
Allow setting TreeModel values to None

Looks good, thanks! Please push.