Commit 84e3471b authored by Bastian Winkler's avatar Bastian Winkler Committed by Martin Pitt
Browse files

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: default avatarMartin Pitt <martinpitt@gnome.org>
parent d1362451
......@@ -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;
......
......@@ -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):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment