[pygobject] gobject: Go through introspection on property setting



commit fd32acdd97f49f086a8ad5cf2b65862c4e6ccc44
Author: Olivier CrÃte <olivier crete collabora com>
Date:   Mon Sep 17 15:37:04 2012 -0400

    gobject: Go through introspection on property setting
    
    Consider introspected properties in object.set_property().
    
    https://bugzilla.gnome.org/show_bug.cgi?id=684062

 gi/_gobject/pygobject.c  |   18 +++++++++++++++++-
 tests/test_properties.py |   13 ++++++++++---
 2 files changed, 27 insertions(+), 4 deletions(-)
---
diff --git a/gi/_gobject/pygobject.c b/gi/_gobject/pygobject.c
index 00444bd..811a20c 100644
--- a/gi/_gobject/pygobject.c
+++ b/gi/_gobject/pygobject.c
@@ -1371,6 +1371,7 @@ pygobject_set_property(PyGObject *self, PyObject *args)
     gchar *param_name;
     GParamSpec *pspec;
     PyObject *pvalue;
+    int ret = -1;
 
     if (!PyArg_ParseTuple(args, "sO:GObject.set_property", &param_name,
 			  &pvalue))
@@ -1387,9 +1388,17 @@ pygobject_set_property(PyGObject *self, PyObject *args)
 	return NULL;
     }
     
+    ret = pygi_set_property_value (self, pspec, pvalue);
+    if (ret == 0)
+	goto done;
+    else if (PyErr_Occurred())
+        return  NULL;
+
     if (!set_property_from_pspec(self->obj, pspec, pvalue))
 	return NULL;
-    
+
+done:
+
     Py_INCREF(Py_None);
     return Py_None;
 }
@@ -1413,6 +1422,7 @@ pygobject_set_properties(PyGObject *self, PyObject *args, PyObject *kwargs)
     while (kwargs && PyDict_Next (kwargs, &pos, &key, &value)) {
 	gchar *key_str = PYGLIB_PyUnicode_AsString(key);
 	GParamSpec *pspec;
+	int ret = -1;
 
 	pspec = g_object_class_find_property(class, key_str);
 	if (!pspec) {
@@ -1425,6 +1435,12 @@ pygobject_set_properties(PyGObject *self, PyObject *args, PyObject *kwargs)
 	    goto exit;
 	}
 
+	ret = pygi_set_property_value (self, pspec, value);
+	if (ret == 0)
+	    goto exit;
+	else if (PyErr_Occurred())
+            goto exit;
+
 	if (!set_property_from_pspec(G_OBJECT(self->obj), pspec, value))
 	    goto exit;
     }
diff --git a/tests/test_properties.py b/tests/test_properties.py
index d19970f..d0552e0 100644
--- a/tests/test_properties.py
+++ b/tests/test_properties.py
@@ -715,7 +715,7 @@ class TestProperty(unittest.TestCase):
         self.assertEqual(b.prop1, 20)
 
     def test_property_subclass_c(self):
-        class A(GIMarshallingTests.PropertiesObject):
+        class A(Regress.TestSubObj):
             prop1 = GObject.Property(type=int)
 
         a = A()
@@ -723,8 +723,15 @@ class TestProperty(unittest.TestCase):
         self.assertEqual(a.prop1, 10)
 
         # also has parent properties
-        a.props.some_int = 20
-        self.assertEqual(a.props.some_int, 20)
+        a.props.int = 20
+        self.assertEqual(a.props.int, 20)
+
+        # Some of which are unusable without introspection
+        a.props.list = ("str1", "str2")
+        self.assertEqual(a.props.list, ["str1", "str2"])
+
+        a.set_property("list", ("str3", "str4"))
+        self.assertEqual(a.props.list, ["str3", "str4"])
 
     def test_property_subclass_custom_setter(self):
         # test for #523352



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