[pygobject] Support GParamSpec signal arguments from Python



commit f9429192cb1002725a11a75a7b8f9300375b9caf
Author: Martin Pitt <martinpitt gnome org>
Date:   Mon Jan 14 12:15:27 2013 +0100

    Support GParamSpec signal arguments from Python
    
    In pyg_value_from_pyobject(), recognize both the real GI GObject.ParamSpec type
    as well as the statically wrapped _gobject.GParamSpec type.
    
    This fixes marshalling GObject.ParamSpec signal/vfunc arguments.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=683099

 gi/_gobject/pygtype.c    |    6 +++++-
 tests/test_signal.py     |   12 ++++++++++++
 tests/testhelpermodule.c |   13 +++++++++++++
 3 files changed, 30 insertions(+), 1 deletions(-)
---
diff --git a/gi/_gobject/pygtype.c b/gi/_gobject/pygtype.c
index 8be601b..227178f 100644
--- a/gi/_gobject/pygtype.c
+++ b/gi/_gobject/pygtype.c
@@ -1048,7 +1048,11 @@ pyg_value_from_pyobject(GValue *value, PyObject *obj)
 	break;
     }
     case G_TYPE_PARAM:
-	if (PyGParamSpec_Check(obj))
+        /* we need to support both the wrapped _gobject.GParamSpec and the GI
+         * GObject.ParamSpec */
+        if (G_IS_PARAM_SPEC (pygobject_get (obj)))
+	    g_value_set_param(value, G_PARAM_SPEC (pygobject_get (obj)));
+        else if (PyGParamSpec_Check(obj))
 	    g_value_set_param(value, PYGLIB_CPointer_GetPointer(obj, NULL));
 	else
 	    return -1;
diff --git a/tests/test_signal.py b/tests/test_signal.py
index 9ae499d..8f31c35 100644
--- a/tests/test_signal.py
+++ b/tests/test_signal.py
@@ -362,6 +362,7 @@ class CM(GObject.GObject):
         test_string=(GObject.SignalFlags.RUN_LAST, str, (str,)),
         test_object=(GObject.SignalFlags.RUN_LAST, object, (object,)),
         test_paramspec=(GObject.SignalFlags.RUN_LAST, GObject.ParamSpec, ()),
+        test_paramspec_in=(GObject.SignalFlags.RUN_LAST, GObject.ParamSpec, (GObject.ParamSpec, )),
         test_gvalue=(GObject.SignalFlags.RUN_LAST, GObject.Value, (GObject.Value,)),
         test_gvalue_ret=(GObject.SignalFlags.RUN_LAST, GObject.Value, (GObject.TYPE_GTYPE,)),
     )
@@ -418,6 +419,17 @@ class _TestCMarshaller:
         self.assertEqual(rv.name, "test-param")
         self.assertEqual(rv.nick, "test")
 
+    @unittest.skipUnless(hasattr(GObject, 'param_spec_boolean'),
+                         'too old gobject-introspection')
+    def test_paramspec_in(self):
+        rv = GObject.param_spec_boolean('mybool', 'test-bool', 'do something',
+                                        True, GObject.ParamFlags.READABLE)
+
+        rv2 = self.obj.emit("test-paramspec-in", rv)
+        self.assertEqual(type(rv), type(rv2))
+        self.assertEqual(rv2.name, "mybool")
+        self.assertEqual(rv2.nick, "test-bool")
+
     def test_C_paramspec(self):
         self.notify_called = False
 
diff --git a/tests/testhelpermodule.c b/tests/testhelpermodule.c
index d82a3c2..9ca82bc 100644
--- a/tests/testhelpermodule.c
+++ b/tests/testhelpermodule.c
@@ -402,6 +402,15 @@ test_gvalue_ret_callback (GObject *object, GType type)
   return ret;
 }
 
+static GParamSpec *
+test_paramspec_in_callback (GObject *object, GParamSpec *p)
+{
+  g_return_val_if_fail (G_IS_OBJECT (object), NULL);
+  g_return_val_if_fail (G_IS_PARAM_SPEC (p), NULL);
+
+  return p;
+}
+
 static void
 connectcallbacks (GObject *object)
 {
@@ -460,6 +469,10 @@ connectcallbacks (GObject *object)
                     "test_gvalue_ret",
                     G_CALLBACK (test_gvalue_ret_callback), 
                     NULL);
+  g_signal_connect (G_OBJECT (object),
+                    "test_paramspec_in",
+                    G_CALLBACK (test_paramspec_in_callback), 
+                    NULL);
 }
 
 static PyObject *



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