[pygobject] Gtk overrides: Add TreePath.__getitem__()
- From: Martin Pitt <martinpitt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Gtk overrides: Add TreePath.__getitem__()
- Date: Tue, 24 Jul 2012 13:18:17 +0000 (UTC)
commit 0d729c1534c7f3226b492f549d8f6ad3bb3ac8b7
Author: Simon Feltman <s feltman gmail com>
Date: Fri Jul 20 19:55:46 2012 -0700
Gtk overrides: Add TreePath.__getitem__()
Use pythons sub-script operator for indexing into TreePaths
as was the case in PyGtk. Also changed __iter__ to use
TreePath.get_indices as opposed to formatting and re-parsing
a string for getting an index list.
https://bugzilla.gnome.org/show_bug.cgi?id=680353
gi/overrides/Gtk.py | 5 ++++-
tests/test_overrides.py | 4 ++++
2 files changed, 8 insertions(+), 1 deletions(-)
---
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index 49c2747..68d0f41 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -1227,11 +1227,14 @@ class TreePath(Gtk.TreePath):
return other is None or self.compare(other) >= 0
def __iter__(self):
- return (int(part) for part in str(self).split(':'))
+ return iter(self.get_indices())
def __len__(self):
return self.get_depth()
+ def __getitem__(self, index):
+ return self.get_indices()[index]
+
TreePath = override(TreePath)
__all__.append('TreePath')
diff --git a/tests/test_overrides.py b/tests/test_overrides.py
index 73b17a5..9438add 100644
--- a/tests/test_overrides.py
+++ b/tests/test_overrides.py
@@ -1392,6 +1392,10 @@ class TestGtk(unittest.TestCase):
self.assertFalse(p1 <= None)
self.assertEqual(tuple(p1), (1, 2, 3))
+ self.assertEqual(p1[0], 1)
+ self.assertEqual(p1[1], 2)
+ self.assertEqual(p1[2], 3)
+ self.assertRaises(IndexError, p1.__getitem__, 3)
def test_tree_model(self):
tree_store = Gtk.TreeStore(int, str)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]