[pygobject] Add support for properties of type GInterface



commit b96a6dc968566d339a2dfd7dd631ae52d812302a
Author: Garrett Regier <garrettregier gmail com>
Date:   Tue Jul 2 06:07:15 2013 -0700

    Add support for properties of type GInterface
    
    Add support for G_TYPE_INTERFACE/GInterface to switch
    statement which handles G_TYPE_OBJECT based properties.
    
    Signed-off-by: Simon Feltman <sfeltman src gnome org>
    
    https://bugzilla.gnome.org/show_bug.cgi?id=703456

 gi/_gobject/gobjectmodule.c   |    1 +
 gi/_gobject/propertyhelper.py |    3 ++-
 tests/test_properties.py      |   16 ++++++++++++++++
 3 files changed, 19 insertions(+), 1 deletions(-)
---
diff --git a/gi/_gobject/gobjectmodule.c b/gi/_gobject/gobjectmodule.c
index 1e1cbd8..81dc44b 100644
--- a/gi/_gobject/gobjectmodule.c
+++ b/gi/_gobject/gobjectmodule.c
@@ -623,6 +623,7 @@ create_property (const gchar  *prop_name,
            pspec = g_param_spec_pointer (prop_name, nick, blurb, flags);
        break;
     case G_TYPE_OBJECT:
+    case G_TYPE_INTERFACE:
        if (!PyArg_ParseTuple(args, ""))
            return NULL;
        pspec = g_param_spec_object (prop_name, nick, blurb, prop_type, flags);
diff --git a/gi/_gobject/propertyhelper.py b/gi/_gobject/propertyhelper.py
index e8ccb35..41be81d 100644
--- a/gi/_gobject/propertyhelper.py
+++ b/gi/_gobject/propertyhelper.py
@@ -261,7 +261,8 @@ class Property(object):
               issubclass(type_, (_gobject.GObject,
                                  _gobject.GEnum,
                                  _gobject.GFlags,
-                                 _gobject.GBoxed))):
+                                 _gobject.GBoxed,
+                                 _gobject.GInterface))):
             return type_.__gtype__
         elif type_ in (TYPE_NONE, TYPE_INTERFACE, TYPE_CHAR, TYPE_UCHAR,
                        TYPE_INT, TYPE_UINT, TYPE_BOOLEAN, TYPE_LONG,
diff --git a/tests/test_properties.py b/tests/test_properties.py
index 4b128f3..ef6b867 100644
--- a/tests/test_properties.py
+++ b/tests/test_properties.py
@@ -69,6 +69,9 @@ class PropertyObject(GObject.GObject):
         type=TYPE_VARIANT, flags=PARAM_READWRITE | PARAM_CONSTRUCT,
         default=GLib.Variant('i', 42))
 
+    interface = GObject.Property(
+        type=Gio.File, flags=PARAM_READWRITE | PARAM_CONSTRUCT)
+
 
 class PropertyInheritanceObject(Regress.TestObj):
     # override property from the base class, with a different type
@@ -133,6 +136,7 @@ class TestPropertyObject(unittest.TestCase):
                                      'enum',
                                      'flags',
                                      'gtype',
+                                     'interface',
                                      'normal',
                                      'strings',
                                      'uint64',
@@ -389,6 +393,17 @@ class TestPropertyObject(unittest.TestCase):
         obj = new(PropertyObject, variant_def=GLib.Variant('u', 5))
         self.assertEqual(obj.props.variant_def.print_(True), 'uint32 5')
 
+    def test_interface(self):
+        obj = new(PropertyObject)
+
+        file = Gio.File.new_for_path('/some/path')
+        obj.props.interface = file
+        self.assertEqual(obj.props.interface.get_path(), '/some/path')
+        self.assertEqual(obj.interface.get_path(), '/some/path')
+
+        self.assertRaises(TypeError, setattr, obj, 'interface', 'foo')
+        self.assertRaises(TypeError, setattr, obj, 'interface', object())
+
     def test_range(self):
         # kiwi code
         def max(c):
@@ -827,6 +842,7 @@ class TestProperty(unittest.TestCase):
         self.assertEqual(tester._type_from_python(GObject.GEnum), GObject.GEnum.__gtype__)
         self.assertEqual(tester._type_from_python(GObject.GFlags), GObject.GFlags.__gtype__)
         self.assertEqual(tester._type_from_python(GObject.GBoxed), GObject.GBoxed.__gtype__)
+        self.assertEqual(tester._type_from_python(GObject.GInterface), GObject.GInterface.__gtype__)
 
         for type_ in [TYPE_NONE, TYPE_INTERFACE, TYPE_CHAR, TYPE_UCHAR,
                       TYPE_INT, TYPE_UINT, TYPE_BOOLEAN, TYPE_LONG,


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