[pygobject] Handle GType properties correctly



commit 84e3471ba4595534cbe6875f1c8b77776e1d1814
Author: Bastian Winkler <buz netbuz org>
Date:   Wed Apr 18 21:44:08 2012 +0200

    Handle GType properties correctly
    
    Fix conversion from/to properties of type G_TYPE_GTYPE
    
    https://bugzilla.gnome.org/show_bug.cgi?id=674351
    
    Signed-off-by: Martin Pitt <martinpitt gnome org>

 gi/_gobject/pygtype.c    |    9 +++++++--
 tests/test_everything.py |   15 +++++++++++++++
 2 files changed, 22 insertions(+), 2 deletions(-)
---
diff --git a/gi/_gobject/pygtype.c b/gi/_gobject/pygtype.c
index 79e9dc6..fa95d13 100644
--- a/gi/_gobject/pygtype.c
+++ b/gi/_gobject/pygtype.c
@@ -923,6 +923,8 @@ pyg_value_from_pyobject(GValue *value, PyObject *obj)
 	    g_value_set_pointer(value, pyg_pointer_get(obj, gpointer));
 	else if (PYGLIB_CPointer_Check(obj))
 	    g_value_set_pointer(value, PYGLIB_CPointer_GetPointer(obj, NULL));
+	else if (G_VALUE_HOLDS_GTYPE (value))
+	    g_value_set_gtype (value, pyg_type_from_object (obj));
 	else
 	    return -1;
 	break;
@@ -1098,8 +1100,11 @@ pyg_value_as_pyobject(const GValue *value, gboolean copy_boxed)
 	    return Py_None;
 	}
     case G_TYPE_POINTER:
-	return pyg_pointer_new(G_VALUE_TYPE(value),
-			       g_value_get_pointer(value));
+	if (G_VALUE_HOLDS_GTYPE (value))
+	    return pyg_type_wrapper_new (g_value_get_gtype (value));
+	else
+	    return pyg_pointer_new(G_VALUE_TYPE(value),
+				   g_value_get_pointer(value));
     case G_TYPE_BOXED: {
 	PyGTypeMarshal *bm;
 
diff --git a/tests/test_everything.py b/tests/test_everything.py
index b363525..9ecbbf9 100644
--- a/tests/test_everything.py
+++ b/tests/test_everything.py
@@ -503,6 +503,10 @@ class TestProperties(unittest.TestCase):
         self.assertTrue(isinstance(object_.props.string, str))
         self.assertEquals(object_.props.string, 'mec')
 
+        self.assertEquals(object_.props.gtype, GObject.TYPE_INVALID)
+        object_.props.gtype = int
+        self.assertEquals(object_.props.gtype, GObject.TYPE_INT)
+
     def test_hash_table(self):
         object_ = Everything.TestObj()
         self.assertEquals(object_.props.hash_table, None)
@@ -530,6 +534,17 @@ class TestProperties(unittest.TestCase):
         self.assertTrue(isinstance(object_.props.boxed, Everything.TestBoxed))
         self.assertEquals(object_.props.boxed.some_int8, 42)
 
+    def test_gtype(self):
+        object_ = Everything.TestObj()
+        self.assertEquals(object_.props.gtype, GObject.TYPE_INVALID)
+        object_.props.gtype = int
+        self.assertEquals(object_.props.gtype, GObject.TYPE_INT)
+
+        Everything.TestObj(gtype=int)
+        self.assertEquals(object_.props.gtype, GObject.TYPE_INT)
+        object_.props.gtype = str
+        self.assertEquals(object_.props.gtype, GObject.TYPE_STRING)
+
 
 class TestTortureProfile(unittest.TestCase):
     def test_torture_profile(self):



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