GNOME Bugzilla – Bug 684094
Error when attempting to set a value in a ListStore to None
Last modified: 2013-01-14 06:37:50 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.
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 :-) )
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.
*** Bug 691660 has been marked as a duplicate of this bug. ***
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 on attachment 233416 [details] [review] Allow setting TreeModel values to None Looks good, thanks! Please push.