[pybank] Add to each class the methods from the implemented interfaces



commit 49671ca21cc678f8a011f89e7e281542d116cd5a
Author: Tomeu Vizoso <tomeu sugarlabs org>
Date:   Sat May 23 12:16:40 2009 +0200

    Add to each class the methods from the implemented interfaces
---
 bank/bank-info.c |   22 ++++++++++++++++++++++
 bank/btypes.py   |   10 ++++++++++
 2 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/bank/bank-info.c b/bank/bank-info.c
index 1bff68b..49341c0 100644
--- a/bank/bank-info.c
+++ b/bank/bank-info.c
@@ -836,11 +836,33 @@ _wrap_g_object_info_get_fields(PyGIBaseInfo *self)
     return retval;
 }
 
+static PyObject *
+_wrap_g_object_info_get_interfaces(PyGIBaseInfo *self)
+{
+    int i, length;
+    PyObject *retval;
+
+    g_base_info_ref(self->info);
+    length = g_object_info_get_n_interfaces((GIObjectInfo*)self->info);
+    retval = PyTuple_New(length);
+
+    for (i = 0; i < length; i++) {
+        GIInterfaceInfo *interface;
+        interface = g_object_info_get_interface((GIObjectInfo*)self->info, i);
+        PyTuple_SetItem(retval, i, pyg_info_new(interface));
+        g_base_info_unref((GIBaseInfo*)interface);
+    }
+    g_base_info_unref(self->info);
+
+    return retval;
+}
+
 static PyMethodDef _PyGIObjectInfo_methods[] = {
     { "getParent", (PyCFunction)_wrap_g_object_info_get_parent, METH_NOARGS },
     { "getTypeName", (PyCFunction)_wrap_g_object_info_get_type_name, METH_NOARGS },
     { "getMethods", (PyCFunction)_wrap_g_object_info_get_methods, METH_NOARGS },
     { "getFields", (PyCFunction)_wrap_g_object_info_get_fields, METH_NOARGS },
+    { "getInterfaces", (PyCFunction)_wrap_g_object_info_get_interfaces, METH_NOARGS },
     { NULL, NULL, 0 }
 };
 
diff --git a/bank/btypes.py b/bank/btypes.py
index 7fe0c50..470ca22 100644
--- a/bank/btypes.py
+++ b/bank/btypes.py
@@ -213,6 +213,16 @@ class PyBankMeta(gobject.GObjectMeta):
             else:
                 static_methods.append(method)
 
+        if hasattr(info, 'getInterfaces'):
+            for interface in info.getInterfaces():
+                for method in interface.getMethods():
+                    name = method.getName()
+                    if method.isMethod():
+                        func = Method(method, interface.getName())
+                        setattr(cls, name, new.instancemethod(func, None, cls))
+                    else:
+                        static_methods.append(method)
+
         winner = None
         if needs_constructor:
             if len(constructors) == 1:



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