[pygobject] Container should be iterable.
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Container should be iterable.
- Date: Tue, 7 Dec 2010 16:23:06 +0000 (UTC)
commit f4f7fb35af1b41598dc050f5df155a01c370a920
Author: Dmitry Morozov <dmitry a morozov yandex ru>
Date: Sat Dec 4 19:19:19 2010 +0600
Container should be iterable.
gi/overrides/Gtk.py | 9 +++++++++
tests/test_overrides.py | 6 +++++-
2 files changed, 14 insertions(+), 1 deletions(-)
---
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index 1509fd8..c8233e7 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -54,6 +54,15 @@ class Container(Gtk.Container, Widget):
def __contains__(self, child):
return child in self.get_children()
+ def __iter__(self):
+ return iter(self.get_children())
+
+ def __bool__(self):
+ return True
+
+ # alias for Python 2.x object protocol
+ __nonzero__ = __bool__
+
def get_focus_chain(self):
success, widgets = super(Container, self).get_focus_chain()
if success:
diff --git a/tests/test_overrides.py b/tests/test_overrides.py
index e7e0632..45be0b8 100644
--- a/tests/test_overrides.py
+++ b/tests/test_overrides.py
@@ -59,13 +59,17 @@ class TestGtk(unittest.TestCase):
def test_container(self):
box = Gtk.Box()
+ self.assertTrue(box)
label = Gtk.Label()
label2 = Gtk.Label()
box.add(label)
box.add(label2)
self.assertTrue(label in box)
self.assertTrue(label2 in box)
- self.assertEqual(len(box),2)
+ self.assertEqual(len(box), 2)
+ self.assertTrue(box)
+ l = [x for x in box]
+ self.assertEqual(l, [label, label2])
def test_actiongroup(self):
self.assertEquals(Gtk.ActionGroup, overrides.Gtk.ActionGroup)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]