[pygobject] Override Container to behave like a sequence
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Override Container to behave like a sequence
- Date: Fri, 3 Dec 2010 22:43:46 +0000 (UTC)
commit 7a8af9e220ee48aa28f6b025c5dae324b14fe128
Author: Paolo Borelli <pborelli gnome org>
Date: Sun Nov 28 13:02:30 2010 +0100
Override Container to behave like a sequence
gi/overrides/Gtk.py | 6 ++++++
tests/test_overrides.py | 11 +++++++++++
2 files changed, 17 insertions(+), 0 deletions(-)
---
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index 376fc39..dd87c78 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -49,6 +49,12 @@ __all__.append('Widget')
class Container(Gtk.Container, Widget):
+ def __len__(self):
+ return len(self.get_children())
+
+ def __contains__(self, child):
+ return child in self.get_children()
+
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 6679623..afd5f3d 100644
--- a/tests/test_overrides.py
+++ b/tests/test_overrides.py
@@ -56,6 +56,17 @@ class TestGdk(unittest.TestCase):
self.assertEquals(event.y_root, 5)
class TestGtk(unittest.TestCase):
+
+ def test_container(self):
+ box = Gtk.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)
+
def test_actiongroup(self):
self.assertEquals(Gtk.ActionGroup, overrides.Gtk.ActionGroup)
self.assertRaises(TypeError, Gtk.ActionGroup)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]