[pygobject/gsoc2009: 84/160] Add gobject.flags_from_g_type



commit c882113bbfef084348a4c26ab5a8155518006ccc
Author: Simon van der Linden <svdlinden src gnome org>
Date:   Fri Jul 31 12:29:11 2009 +0200

    Add gobject.flags_from_g_type
    
    Add gobject.flags_from_g_type for the same reason as gobject.enum_from_g_type.

 gobject/gobjectmodule.c |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)
---
diff --git a/gobject/gobjectmodule.c b/gobject/gobjectmodule.c
index 5fbc994..e877711 100644
--- a/gobject/gobjectmodule.c
+++ b/gobject/gobjectmodule.c
@@ -2017,6 +2017,38 @@ _wrap_pyg_enum_from_g_type(PyObject *self, PyObject *args, PyObject *kwargs)
     return type;
 }
 
+static PyObject *
+_wrap_pyg_flags_from_g_type(PyObject *self, PyObject *args, PyObject *kwargs)
+{
+    static char *kwlist[] = { "type", NULL };
+    PyObject *py_g_type;
+    GType g_type;
+    PyObject *type;
+
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+                                     "O!:gobject.flags_from_g_type",
+                                     kwlist, &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_FLAGS)) {
+        PyErr_SetString(PyExc_TypeError,
+            "gobject.flags_from_g_type() argument 0: Must be a subtype of gobject.TYPE_FLAGS");
+        return NULL;
+    }
+
+    type = (PyObject *)g_type_get_qdata(g_type, pygflags_class_key);
+    if (type == NULL) {
+        type = pyg_flags_add(NULL, g_type_name(g_type), NULL, g_type);
+    } else {
+        Py_INCREF(type);
+    }
+
+    return type;
+}
+
 static PyMethodDef _gobject_functions[] = {
     { "type_name", pyg_type_name, METH_VARARGS },
     { "type_from_name", pyg_type_from_name, METH_VARARGS },
@@ -2052,6 +2084,8 @@ static PyMethodDef _gobject_functions[] = {
       (PyCFunction)pyg__install_metaclass, METH_O },
     { "enum_from_g_type",
       (PyCFunction)_wrap_pyg_enum_from_g_type, METH_VARARGS|METH_KEYWORDS },
+    { "flags_from_g_type",
+      (PyCFunction)_wrap_pyg_flags_from_g_type, METH_VARARGS|METH_KEYWORDS },
 
     { NULL, NULL, 0 }
 };



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