summaryrefslogtreecommitdiff
path: root/gi/overrides/Gtk.py
diff options
context:
space:
mode:
authorJohn (J5) Palmieri <johnp@redhat.com>2010-12-02 16:27:04 -0500
committerJohn (J5) Palmieri <johnp@redhat.com>2010-12-03 19:35:18 -0500
commit82689cbf53d92b1b951a459fe3de0e1d3a91791a (patch)
treec8ba6e898bf0f2fbf795ad6cdba49143f8366fa4 /gi/overrides/Gtk.py
parent677490e9402bad7b7c2a832345ef54f7f0c5fc7f (diff)
downloadpygobject-82689cbf53d92b1b951a459fe3de0e1d3a91791a.tar.gz
[gi] handle subtypes when inserting into tree models
* Often modules will give back basic types wrapped in a subtype. This is the case with D-Bus where you may want to keep some of the metadata around. More often than not, the developer is just looking to use the basetype. * This override checks the column type and handles basic types such as gchararrays, ints, longs, floats and doubles, converting them to their base types before sending them to the generic GI type marshaller. * More types may need to be supported but these are the common cases where apps break. https://bugzilla.gnome.org/show_bug.cgi?id=635172
Diffstat (limited to 'gi/overrides/Gtk.py')
-rw-r--r--gi/overrides/Gtk.py38
1 files changed, 36 insertions, 2 deletions
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index b0880386..ca396823 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -664,8 +664,42 @@ class TreeModel(Gtk.TreeModel):
raise ValueError('row sequence has the incorrect number of elements')
for i in range(n_columns):
- if row[i] is not None:
- self.set_value(treeiter, i, row[i])
+ value = row[i]
+
+ if value is None:
+ continue
+
+ # we may need to convert to a basic type
+ type_ = self.get_column_type(i)
+ if type_ == gobject.TYPE_PYOBJECT:
+ pass # short-circut branching
+ elif type_ == gobject.TYPE_STRING:
+ if isinstance(value, str):
+ value = str(value)
+ elif sys.version_info < (3, 0):
+ if isinstance(value, unicode):
+ value = unicode(value)
+ else:
+ raise ValueError('Expected string or unicode for row %i but got %s' % i, type(value))
+ else:
+ raise ValueError('Expected a string for row %i but got %s' % i, type(value))
+ elif type_ == gobject.TYPE_FLOAT or type_ == gobject.TYPE_DOUBLE:
+ if isinstance(value, float):
+ value = float(value)
+ else:
+ raise ValueError('Expected a float for row %i but got %s' % i, type(value))
+ elif type_ == gobject.TYPE_LONG or type_ == gobject.TYPE_INT:
+ if isinstance(value, int):
+ value = int(value)
+ elif sys.version_info < (3, 0):
+ if isinstance(value, long):
+ value = long(value)
+ else:
+ raise ValueError('Expected an long for row %i but got %s' % i, type(value))
+ else:
+ raise ValueError('Expected an interger for row %i but got %s' % i, type(value))
+
+ self.set_value(treeiter, i, value)
def get(self, treeiter, *columns):
n_columns = self.get_n_columns();