[pygi] Register interfaces



commit 1dc62a998dd8d2a0a397f8309011a8d79cb56034
Author: Tomeu Vizoso <tomeu sugarlabs org>
Date:   Sun Nov 22 17:25:04 2009 +0100

    Register interfaces
    
    https://bugzilla.gnome.org/show_bug.cgi?id=601181

 gi/gimodule.c |   33 +++++++++++++++++++++++++++++++++
 gi/types.py   |    5 ++++-
 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):



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