[pygobject] Allow setting values through GtkTreeModelFilter
- From: Martin Pitt <martinpitt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Allow setting values through GtkTreeModelFilter
- Date: Mon, 14 Jan 2013 16:22:18 +0000 (UTC)
commit c90ef9dfac7dd51ec82c99c3605915996bea0f73
Author: Simonas Kazlauskas <simonas kazlauskas me>
Date: Tue Dec 4 15:45:00 2012 +0200
Allow setting values through GtkTreeModelFilter
Previously, trying to set a value through filter throwed an exception that the
model has no set_value() method. You had to first retrieve the deepest child
model and set value to it.
https://bugzilla.gnome.org/show_bug.cgi?id=689624
gi/overrides/Gtk.py | 5 +++++
tests/test_overrides_gtk.py | 11 +++++++++++
2 files changed, 16 insertions(+), 0 deletions(-)
---
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index 337bed6..15c0ae6 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -1544,6 +1544,11 @@ class TreeModelFilter(Gtk.TreeModelFilter):
def set_visible_func(self, func, data=None):
super(TreeModelFilter, self).set_visible_func(func, data)
+ def set_value(self, iter, column, value):
+ # Delegate to child model
+ iter = self.convert_iter_to_child_iter(iter)
+ self.get_model().set_value(iter, column, value)
+
TreeModelFilter = override(TreeModelFilter)
__all__.append('TreeModelFilter')
diff --git a/tests/test_overrides_gtk.py b/tests/test_overrides_gtk.py
index 3aced38..d429d4d 100644
--- a/tests/test_overrides_gtk.py
+++ b/tests/test_overrides_gtk.py
@@ -1344,6 +1344,17 @@ class TestTreeModel(unittest.TestCase):
model.row_inserted('3', Gtk.TreeIter())
self.assertEqual(tree_paths[-1], '3')
+ def test_tree_model_filter(self):
+ model = Gtk.ListStore(int, str, float)
+ model.append([1, "one", -0.1])
+ model.append([2, "two", -0.2])
+
+ filtered = Gtk.TreeModelFilter(child_model=model)
+
+ self.assertEqual(filtered[0][1], 'one')
+ filtered[0][1] = 'ONE'
+ self.assertEqual(filtered[0][1], 'ONE')
+
@unittest.skipUnless(Gtk, 'Gtk not available')
class TestTreeView(unittest.TestCase):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]