[pygobject] overrides: Add Gtk.Container.child_get/set overrides



commit d0b23f08eebd4377f066a4483900fe6d09e3795e
Author: Simon Feltman <sfeltman src gnome org>
Date:   Sun May 25 23:03:35 2014 -0700

    overrides: Add Gtk.Container.child_get/set overrides
    
    Add overrides for child_get and child_set to Gtk.Container since these
    are not introspectable methods.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=685076

 gi/overrides/Gtk.py         |   10 ++++++++++
 tests/test_overrides_gtk.py |   16 ++++++++++++++++
 2 files changed, 26 insertions(+), 0 deletions(-)
---
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index 2a55040..561bdf0 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -132,6 +132,16 @@ class Container(Gtk.Container, Widget):
         Gtk.Container.child_get_property(self, child, property_name, value)
         return value.get_value()
 
+    def child_get(self, child, *prop_names):
+        """Returns a list of child property values for the given names."""
+        return [self.child_get_property(child, name) for name in prop_names]
+
+    def child_set(self, child, **kwargs):
+        """Set a child properties on the given child to key/value pairs."""
+        for name, value in kwargs.items():
+            name = name.replace('_', '-')
+            self.child_set_property(child, name, value)
+
 
 Container = override(Container)
 __all__.append('Container')
diff --git a/tests/test_overrides_gtk.py b/tests/test_overrides_gtk.py
index b7fc5ee..d339adf 100644
--- a/tests/test_overrides_gtk.py
+++ b/tests/test_overrides_gtk.py
@@ -1872,3 +1872,19 @@ class TestContainer(unittest.TestCase):
         box.pack_start(child, expand=False, fill=True, padding=42)
         with self.assertRaises(ValueError):
             box.child_get_property(child, 'not-a-valid-child-property')
+
+    def test_child_get_and_set(self):
+        box = Gtk.Box()
+        child = Gtk.Button()
+        box.pack_start(child, expand=True, fill=True, padding=42)
+
+        expand, fill, padding = box.child_get(child, 'expand', 'fill', 'padding')
+        self.assertEqual(expand, True)
+        self.assertEqual(fill, True)
+        self.assertEqual(padding, 42)
+
+        box.child_set(child, expand=False, fill=False, padding=21, pack_type=1)
+        expand, fill, padding, pack_type = box.child_get(child, 'expand', 'fill', 'padding', 'pack-type')
+        self.assertEqual(expand, False)
+        self.assertEqual(fill, False)
+        self.assertEqual(padding, 21)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]