[pygobject] property: support setting flags



commit cfeeaaf69f6d6f777e5f3a17493ff9dcc2bda900
Author: Christoph Reiter <creiter src gnome org>
Date:   Tue Mar 28 17:58:54 2017 +0200

    property: support setting flags
    
    This also adds some tests for setting flags and enum properties
    which depend on some properties being added in g-i's gimarshallingtests:
        https://bugzilla.gnome.org/show_bug.cgi?id=780652
    
    https://bugzilla.gnome.org/show_bug.cgi?id=726484

 gi/pygi-property.c       |    3 +++
 tests/test_properties.py |   34 ++++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 0 deletions(-)
---
diff --git a/gi/pygi-property.c b/gi/pygi-property.c
index a2c3a17..9978585 100644
--- a/gi/pygi-property.c
+++ b/gi/pygi-property.c
@@ -258,6 +258,9 @@ pygi_set_property_value (PyGObject *instance,
                 case GI_INFO_TYPE_ENUM:
                     g_value_set_enum (&value, arg.v_int);
                     break;
+                case GI_INFO_TYPE_FLAGS:
+                    g_value_set_flags (&value, arg.v_uint);
+                    break;
                 case GI_INFO_TYPE_INTERFACE:
                 case GI_INFO_TYPE_OBJECT:
                     g_value_set_object (&value, arg.v_pointer);
diff --git a/tests/test_properties.py b/tests/test_properties.py
index 00e3c56..30586d1 100644
--- a/tests/test_properties.py
+++ b/tests/test_properties.py
@@ -973,6 +973,40 @@ class CPropertiesTestBase(object):
     def set_prop(self, obj, name, value):
         raise NotImplementedError
 
+    # https://bugzilla.gnome.org/show_bug.cgi?id=780652
+    @unittest.skipUnless(
+        "some_flags" in dir(GIMarshallingTests.PropertiesObject.props),
+        "tool old gi")
+    def test_flags(self):
+        self.assertEqual(
+            self.get_prop(self.obj, 'some-flags'),
+            GIMarshallingTests.Flags.VALUE1)
+        self.set_prop(self.obj, 'some-flags', GIMarshallingTests.Flags.VALUE2)
+        self.assertEqual(self.get_prop(self.obj, 'some-flags'),
+                         GIMarshallingTests.Flags.VALUE2)
+
+        obj = GIMarshallingTests.PropertiesObject(
+            some_flags=GIMarshallingTests.Flags.VALUE3)
+        self.assertEqual(self.get_prop(obj, 'some-flags'),
+                         GIMarshallingTests.Flags.VALUE3)
+
+    # https://bugzilla.gnome.org/show_bug.cgi?id=780652
+    @unittest.skipUnless(
+        "some_enum" in dir(GIMarshallingTests.PropertiesObject.props),
+        "tool old gi")
+    def test_enum(self):
+        self.assertEqual(
+            self.get_prop(self.obj, 'some-enum'),
+            GIMarshallingTests.GEnum.VALUE1)
+        self.set_prop(self.obj, 'some-enum', GIMarshallingTests.GEnum.VALUE2)
+        self.assertEqual(self.get_prop(self.obj, 'some-enum'),
+                         GIMarshallingTests.GEnum.VALUE2)
+
+        obj = GIMarshallingTests.PropertiesObject(
+            some_enum=GIMarshallingTests.GEnum.VALUE3)
+        self.assertEqual(self.get_prop(obj, 'some-enum'),
+                         GIMarshallingTests.GEnum.VALUE3)
+
     def test_boolean(self):
         self.assertEqual(self.get_prop(self.obj, 'some-boolean'), False)
         self.set_prop(self.obj, 'some-boolean', True)


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