summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu@sugarlabs.org>2009-11-22 17:25:04 +0100
committerTomeu Vizoso <tomeu@sugarlabs.org>2009-11-22 17:25:25 +0100
commit1dc62a998dd8d2a0a397f8309011a8d79cb56034 (patch)
tree328c816eb66a834327d8f83ce6aac5d3223d3617
parent6ccf58afcf58e118903ced0135f0fe69b00e09ad (diff)
downloadpygi-1dc62a998dd8d2a0a397f8309011a8d79cb56034.tar.gz
pygi-1dc62a998dd8d2a0a397f8309011a8d79cb56034.tar.xz
pygi-1dc62a998dd8d2a0a397f8309011a8d79cb56034.zip
Register interfaces
https://bugzilla.gnome.org/show_bug.cgi?id=601181
-rw-r--r--gi/gimodule.c33
-rw-r--r--gi/types.py5
2 files changed, 37 insertions, 1 deletions
diff --git a/gi/gimodule.c b/gi/gimodule.c
index d9ee17b..bc5f9ca 100644
--- a/gi/gimodule.c
+++ b/gi/gimodule.c
@@ -97,12 +97,45 @@ _wrap_pyg_set_object_has_new_constructor (PyObject *self,
Py_RETURN_NONE;
}
+static void
+initialize_interface (GTypeInterface *iface, PyTypeObject *pytype)
+{
+ // pygobject prints a warning if interface_init is NULL
+}
+
+static PyObject *
+_wrap_pyg_register_interface_info(PyObject *self, PyObject *args)
+{
+ PyObject *py_g_type;
+ GType g_type;
+ GInterfaceInfo *info;
+
+ if (!PyArg_ParseTuple(args, "O!:register_interface_info",
+ &PyGTypeWrapper_Type, &py_g_type)) {
+ return NULL;
+ }
+
+ g_type = pyg_type_from_object(py_g_type);
+ if (!g_type_is_a(g_type, G_TYPE_INTERFACE)) {
+ PyErr_SetString(PyExc_TypeError, "must be an interface");
+ return NULL;
+ }
+
+ info = g_new0(GInterfaceInfo, 1);
+ info->interface_init = (GInterfaceInitFunc) initialize_interface;
+
+ pyg_register_interface_info(g_type, info);
+
+ Py_RETURN_NONE;
+}
+
static PyMethodDef _pygi_functions[] = {
{ "enum_add", (PyCFunction)_wrap_pyg_enum_add, METH_VARARGS | METH_KEYWORDS },
{ "flags_add", (PyCFunction)_wrap_pyg_flags_add, METH_VARARGS | METH_KEYWORDS },
{ "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 },
{ NULL, NULL, 0 }
};
diff --git a/gi/types.py b/gi/types.py
index 10d7fde..e32bb72 100644
--- a/gi/types.py
+++ b/gi/types.py
@@ -29,7 +29,8 @@ from ._gi import \
InterfaceInfo, \
ObjectInfo, \
StructInfo, \
- set_object_has_new_constructor
+ set_object_has_new_constructor, \
+ register_interface_info
class Boxed(gobject.GBoxed):
@@ -125,6 +126,8 @@ class GObjectMeta(gobject.GObjectMeta, MetaClassHelper):
cls._setup_fields()
cls._setup_constructors()
set_object_has_new_constructor(cls.__info__.get_g_type())
+ elif (isinstance(cls.__info__, InterfaceInfo)):
+ register_interface_info(cls.__info__.get_g_type())
class StructMeta(type, MetaClassHelper):