[pygobject] Override TreeSelection.select_path and TreeView.scroll_to_cell
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Override TreeSelection.select_path and TreeView.scroll_to_cell
- Date: Fri, 3 Dec 2010 22:43:56 +0000 (UTC)
commit 677490e9402bad7b7c2a832345ef54f7f0c5fc7f
Author: Paolo Borelli <pborelli gnome org>
Date: Fri Dec 3 23:39:50 2010 +0100
Override TreeSelection.select_path and TreeView.scroll_to_cell
The "path" argument may also be a string or a tuple
gi/overrides/Gtk.py | 10 ++++++++++
tests/test_overrides.py | 29 +++++++++++++++++++++++++++++
2 files changed, 39 insertions(+), 0 deletions(-)
---
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index 37f8c95..b088038 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -945,6 +945,10 @@ class TreeView(Gtk.TreeView, Container):
len(target_entries),
actions)
+ def scroll_to_cell(self, path, column=None, use_align=False, row_align=0.0, col_align=0.0):
+ if not isinstance(path, Gtk.TreePath):
+ path = TreePath(path)
+ super(TreeView, self).scroll_to_cell(path, column, use_align, row_align, col_align)
TreeView = override(TreeView)
@@ -966,11 +970,17 @@ class TreeViewColumn(Gtk.TreeViewColumn):
if success:
return (start_pos, width,)
+
TreeViewColumn = override(TreeViewColumn)
__all__.append('TreeViewColumn')
class TreeSelection(Gtk.TreeSelection):
+ def select_path(self, path):
+ if not isinstance(path, Gtk.TreePath):
+ path = TreePath(path)
+ super(TreeSelection, self).select_path(path)
+
def get_selected(self):
success, model, aiter = super(TreeSelection, self).get_selected()
if success:
diff --git a/tests/test_overrides.py b/tests/test_overrides.py
index 5f2955a..4afc921 100644
--- a/tests/test_overrides.py
+++ b/tests/test_overrides.py
@@ -613,6 +613,35 @@ class TestGtk(unittest.TestCase):
text=0,
style=2)
+ def test_tree_selection(self):
+ store = Gtk.ListStore(int, str)
+ for i in range(10):
+ store.append((i, "foo"))
+ view = Gtk.TreeView()
+ view.set_model(store)
+ firstpath = store.get_path(store.get_iter_first())
+ sel = view.get_selection()
+
+ sel.select_path(firstpath)
+ (m, s) = sel.get_selected()
+ self.assertEqual(m, store)
+ self.assertEqual(store.get_path(s), firstpath)
+
+ sel.select_path(0)
+ (m, s) = sel.get_selected()
+ self.assertEqual(m, store)
+ self.assertEqual(store.get_path(s), firstpath)
+
+ sel.select_path("0:0")
+ (m, s) = sel.get_selected()
+ self.assertEqual(m, store)
+ self.assertEqual(store.get_path(s), firstpath)
+
+ sel.select_path((0,0))
+ (m, s) = sel.get_selected()
+ self.assertEqual(m, store)
+ self.assertEqual(store.get_path(s), firstpath)
+
def test_text_buffer(self):
self.assertEquals(Gtk.TextBuffer, overrides.Gtk.TextBuffer)
buffer = Gtk.TextBuffer()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]