Commit 7a0548db authored by Martin Pitt's avatar Martin Pitt

Fix handling of unicode for GtkTreeModels

The code previously converted an unicode object into unicode, but in Python 2.X
models actually have to specify 'str' (GTK expects a gchararray). So encode to
UTF-8 instead to get what GTK expects.

Add corresponding test case.
parent 09c21c79
......@@ -707,7 +707,7 @@ class TreeModel(Gtk.TreeModel):
value = str(value)
elif sys.version_info < (3, 0):
if isinstance(value, unicode):
value = unicode(value)
value = value.encode('UTF-8')
else:
raise ValueError('Expected string or unicode for row %i but got %s%s' % (i, value, type(value)))
else:
......
......@@ -398,7 +398,7 @@ class TestGtk(unittest.TestCase):
test_pylist = [1,"2", "3"]
list_store = Gtk.ListStore(int, str, 'GIOverrideTreeAPITest', object, object, object)
for i in range(95):
for i in range(94):
label = 'this is row #%d' % i
testobj = TestGtk.TestClass(self, i, label)
parent = list_store.append((i,
......@@ -408,6 +408,16 @@ class TestGtk(unittest.TestCase):
test_pydict,
test_pylist))
# test automatic unicode->str conversion
i = 94
label = u'this is row #94'
treeiter = list_store.append((i,
label,
TestGtk.TestClass(self, i, label),
test_pyobj,
test_pydict,
test_pylist))
# add sorted items out of order to test insert* apis
i = 97
label = 'this is row #97'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment