tests: Remove TestMainLoop.test_concurrency
[pygobject.git] / gi / pyginterface.c
blob1737de5ae62fa639863e054f7c65fa8a7ccf1c2e
1 /* -*- Mode: C; c-basic-offset: 4 -*-
2 * pygtk- Python bindings for the GTK toolkit.
3 * Copyright (C) 1998-2003 James Henstridge
4 * 2004-2008 Johan Dahlin
5 * pyginterface.c: wrapper for the gobject library.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
21 #ifdef HAVE_CONFIG_H
22 # include <config.h>
23 #endif
25 #include <Python.h>
26 #include <glib-object.h>
27 #include "pyglib.h"
29 #include "pyginterface.h"
30 #include "pygtype.h"
32 GQuark pyginterface_type_key;
33 GQuark pyginterface_info_key;
35 PYGLIB_DEFINE_TYPE("gobject.GInterface", PyGInterface_Type, PyObject)
37 static int
38 pyg_interface_init(PyObject *self, PyObject *args, PyObject *kwargs)
40 gchar buf[512];
42 if (!PyArg_ParseTuple(args, ":GInterface.__init__"))
43 return -1;
45 g_snprintf(buf, sizeof(buf), "%s can not be constructed",
46 Py_TYPE(self)->tp_name);
47 PyErr_SetString(PyExc_NotImplementedError, buf);
48 return -1;
51 static void
52 pyg_interface_free(PyObject *op)
54 PyObject_FREE(op);
57 /**
58 * pyg_register_interface:
59 * @dict: a module dictionary.
60 * @class_name: the class name for the wrapper class.
61 * @gtype: the GType of the interface.
62 * @type: the wrapper class for the interface.
64 * Registers a Python class as the wrapper for a GInterface. As a
65 * convenience it will also place a reference to the wrapper class in
66 * the provided module dictionary.
68 void
69 pyg_register_interface(PyObject *dict, const gchar *class_name,
70 GType gtype, PyTypeObject *type)
72 PyObject *o;
74 Py_TYPE(type) = &PyType_Type;
75 type->tp_base = &PyGInterface_Type;
77 if (PyType_Ready(type) < 0) {
78 g_warning("could not ready `%s'", type->tp_name);
79 return;
82 if (gtype) {
83 o = pyg_type_wrapper_new(gtype);
84 PyDict_SetItemString(type->tp_dict, "__gtype__", o);
85 Py_DECREF(o);
88 g_type_set_qdata(gtype, pyginterface_type_key, type);
90 PyDict_SetItemString(dict, (char *)class_name, (PyObject *)type);
94 void
95 pyg_register_interface_info(GType gtype, const GInterfaceInfo *info)
97 g_type_set_qdata(gtype, pyginterface_info_key, (gpointer) info);
100 const GInterfaceInfo *
101 pyg_lookup_interface_info(GType gtype)
103 return g_type_get_qdata(gtype, pyginterface_info_key);
106 void
107 pygobject_interface_register_types(PyObject *d)
109 pyginterface_type_key = g_quark_from_static_string("PyGInterface::type");
110 pyginterface_info_key = g_quark_from_static_string("PyGInterface::info");
112 PyGInterface_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
113 PyGInterface_Type.tp_init = (initproc)pyg_interface_init;
114 PyGInterface_Type.tp_free = (freefunc)pyg_interface_free;
116 PYGOBJECT_REGISTER_GTYPE(d, PyGInterface_Type, "GInterface", G_TYPE_INTERFACE)
118 PyDict_SetItemString(PyGInterface_Type.tp_dict, "__doc__",
119 pyg_object_descr_doc_get());
120 PyDict_SetItemString(PyGInterface_Type.tp_dict, "__gdoc__",
121 pyg_object_descr_doc_get());