[pygobject] Add override for GLib.Variant.new_tuple
- From: John Palmieri <johnp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Add override for GLib.Variant.new_tuple
- Date: Wed, 8 Sep 2010 17:49:46 +0000 (UTC)
commit 306b792ac97a458ddee59fb86d66453495117f3e
Author: Tomeu Vizoso <tomeu vizoso collabora co uk>
Date: Thu Jul 22 13:48:51 2010 +0100
Add override for GLib.Variant.new_tuple
* gi/gimodule.c: Add _wrap_pyg_variant_new_tuple
* gi/overrides/GLib.py: Override Variant.new_tuple and Variant.get_string
* gi/pygi-type.[hc]: split _pygi_type_import_by_name out from
_pygi_type_import_by_gi_info
* gi/types.py: Never override gobject.TYPE_NONE
* tests/test_everything.py: Add tests for GVariant tuples
https://bugzilla.gnome.org/show_bug.cgi?id=625050
gi/gimodule.c | 38 ++++++++++++++++++++++++++++++++++++++
gi/overrides/Makefile.am | 1 +
gi/pygi-type.c | 15 +++++++++------
gi/pygi-type.h | 2 ++
gi/types.py | 1 +
tests/test_everything.py | 9 +++++++++
6 files changed, 60 insertions(+), 6 deletions(-)
---
diff --git a/gi/gimodule.c b/gi/gimodule.c
index d9cc0f5..42b5f3c 100644
--- a/gi/gimodule.c
+++ b/gi/gimodule.c
@@ -235,6 +235,43 @@ _wrap_pyg_hook_up_vfunc_implementation (PyObject *self, PyObject *args)
Py_RETURN_NONE;
}
+static PyObject *
+_wrap_pyg_variant_new_tuple (PyObject *self, PyObject *args)
+{
+ PyObject *py_values;
+ GVariant **values = NULL;
+ GVariant *variant = NULL;
+ PyObject *py_variant = NULL;
+ PyObject *py_type;
+ gssize i;
+
+ if (!PyArg_ParseTuple (args, "O!:variant_new_tuple",
+ &PyTuple_Type, &py_values)) {
+ return NULL;
+ }
+
+ py_type = _pygi_type_import_by_name ("GLib", "Variant");
+
+ values = g_newa (GVariant*, PyTuple_Size (py_values));
+
+ for (i = 0; i < PyTuple_Size (py_values); i++) {
+ PyObject *value = PyTuple_GET_ITEM (py_values, i);
+
+ if (!PyObject_IsInstance (value, py_type)) {
+ PyErr_Format (PyExc_TypeError, "argument %d is not a GLib.Variant", i);
+ return NULL;
+ }
+
+ values[i] = (GVariant *) ( (PyGPointer *) value)->pointer;
+ }
+
+ variant = g_variant_new_tuple (values, PyTuple_Size (py_values));
+
+ py_variant = _pygi_struct_new ( (PyTypeObject *) py_type, variant, FALSE);
+
+ return py_variant;
+}
+
static PyMethodDef _gi_functions[] = {
{ "enum_add", (PyCFunction) _wrap_pyg_enum_add, METH_VARARGS | METH_KEYWORDS },
{ "flags_add", (PyCFunction) _wrap_pyg_flags_add, METH_VARARGS | METH_KEYWORDS },
@@ -242,6 +279,7 @@ static PyMethodDef _gi_functions[] = {
{ "set_object_has_new_constructor", (PyCFunction) _wrap_pyg_set_object_has_new_constructor, METH_VARARGS | METH_KEYWORDS },
{ "register_interface_info", (PyCFunction) _wrap_pyg_register_interface_info, METH_VARARGS },
{ "hook_up_vfunc_implementation", (PyCFunction) _wrap_pyg_hook_up_vfunc_implementation, METH_VARARGS },
+ { "variant_new_tuple", (PyCFunction) _wrap_pyg_variant_new_tuple, METH_VARARGS },
{ NULL, NULL, 0 }
};
diff --git a/gi/overrides/Makefile.am b/gi/overrides/Makefile.am
index 62f6457..b36c7a5 100644
--- a/gi/overrides/Makefile.am
+++ b/gi/overrides/Makefile.am
@@ -4,6 +4,7 @@ pkgpyexecdir = $(pyexecdir)/gtk-2.0/gi
pygioverridesdir = $(pkgpyexecdir)/overrides
pygioverrides_PYTHON = \
+ GLib.py \
Gtk.py \
Gdk.py \
GIMarshallingTests.py \
diff --git a/gi/pygi-type.c b/gi/pygi-type.c
index bd9804e..129ea98 100644
--- a/gi/pygi-type.c
+++ b/gi/pygi-type.c
@@ -25,17 +25,13 @@
PyObject *
-_pygi_type_import_by_gi_info (GIBaseInfo *info)
+_pygi_type_import_by_name (const char *namespace_,
+ const char *name)
{
- const gchar *namespace_;
- const gchar *name;
gchar *module_name;
PyObject *py_module;
PyObject *py_object;
- namespace_ = g_base_info_get_namespace (info);
- name = g_base_info_get_name (info);
-
module_name = g_strconcat ("gi.repository.", namespace_, NULL);
py_module = PyImport_ImportModule (module_name);
@@ -74,6 +70,13 @@ pygi_type_import_by_g_type_real (GType g_type)
}
PyObject *
+_pygi_type_import_by_gi_info (GIBaseInfo *info)
+{
+ return _pygi_type_import_by_name (g_base_info_get_namespace (info),
+ g_base_info_get_name (info));
+}
+
+PyObject *
_pygi_type_get_from_g_type (GType g_type)
{
PyObject *py_g_type;
diff --git a/gi/pygi-type.h b/gi/pygi-type.h
index 16d5bdc..bb43d19 100644
--- a/gi/pygi-type.h
+++ b/gi/pygi-type.h
@@ -33,6 +33,8 @@ PyObject *pygi_type_import_by_g_type_real (GType g_type);
/* Private */
+PyObject *_pygi_type_import_by_name (const char *namespace_, const char *name);
+
PyObject *_pygi_type_import_by_gi_info (GIBaseInfo *info);
PyObject *_pygi_type_get_from_g_type (GType g_type);
diff --git a/gi/types.py b/gi/types.py
index 4e0e06d..0a8768c 100644
--- a/gi/types.py
+++ b/gi/types.py
@@ -165,6 +165,7 @@ class StructMeta(type, MetaClassHelper):
def override(type_):
g_type = type_.__info__.get_g_type()
+ assert g_type != gobject.TYPE_NONE
if g_type != gobject.TYPE_INVALID:
g_type.pytype = type_
return type_
diff --git a/tests/test_everything.py b/tests/test_everything.py
index 23484aa..3ef5eb3 100644
--- a/tests/test_everything.py
+++ b/tests/test_everything.py
@@ -50,11 +50,20 @@ class TestEverything(unittest.TestCase):
def test_gvariant(self):
variant = GLib.Variant.new_int32(42);
+ self.assertTrue(isinstance(variant, GLib.Variant))
self.assertEquals(variant.get_int32(), 42)
variant = GLib.Variant.new_strv(['mec', 'mac']);
+ self.assertTrue(isinstance(variant, GLib.Variant))
self.assertEquals(variant.get_strv(), ['mec', 'mac'])
+ variant = GLib.Variant.new_tuple(GLib.Variant.new_string('mec'), GLib.Variant.new_string('mac'))
+ self.assertTrue(isinstance(variant, GLib.Variant))
+ self.assertTrue(isinstance(variant.get_child_value(0), GLib.Variant))
+ self.assertTrue(isinstance(variant.get_child_value(1), GLib.Variant))
+ self.assertEquals(variant.get_child_value(0).get_string(), 'mec')
+ self.assertEquals(variant.get_child_value(1).get_string(), 'mac')
+
def test_floating(self):
Everything.TestFloating()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]