Debian Codegraph @

gi/pyginterface.c

raw
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.
6 *
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.
11 *
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.
16 *
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/>.
19 */
20
21 #include "pygi-type.h"
22 #include "pygi-util.h"
23 #include "pyginterface.h"
24
25 GQuark pyginterface_type_key;
26 GQuark pyginterface_info_key;
27
28 PYGI_DEFINE_TYPE ("gobject.GInterface", PyGInterface_Type, PyObject)
29
30 static int
31 pyg_interface_init (PyObject *self, PyObject *args, PyObject *kwargs)
32 {
33 gchar buf[512];
34
35 if (!PyArg_ParseTuple (args, ":GInterface.__init__")) return -1;
36
37 g_snprintf (buf, sizeof (buf), "%s can not be constructed",
38 Py_TYPE (self)->tp_name);
39 PyErr_SetString (PyExc_NotImplementedError, buf);
40 return -1;
41 }
42
43 static void
44 pyg_interface_free (PyObject *op)
45 {
46 PyObject_Free (op);
47 }
48
49 void
50 pyg_register_interface_info (GType gtype, const GInterfaceInfo *info)
51 {
52 GInterfaceInfo *prev_info = pyg_lookup_interface_info (gtype);
53
54 if (prev_info) {
55 g_free (prev_info);
56 }
57
58 g_type_set_qdata (gtype, pyginterface_info_key,
59 g_memdup2 (info, sizeof (GInterfaceInfo)));
60 }
61
62 const GInterfaceInfo *
63 pyg_lookup_interface_info (GType gtype)
64 {
65 return g_type_get_qdata (gtype, pyginterface_info_key);
66 }
67
68 /**
69 * Returns 0 on success, or -1 and sets an exception.
70 */
71 int
72 pygi_interface_register_types (PyObject *d)
73 {
74 PyObject *pygtype;
75
76 pyginterface_type_key = g_quark_from_static_string ("PyGInterface::type");
77 pyginterface_info_key = g_quark_from_static_string ("PyGInterface::info");
78
79 PyGInterface_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
80 PyGInterface_Type.tp_init = (initproc)pyg_interface_init;
81 PyGInterface_Type.tp_free = (freefunc)pyg_interface_free;
82 PyGInterface_Type.tp_alloc = PyType_GenericAlloc;
83 PyGInterface_Type.tp_new = PyType_GenericNew;
84 if (PyType_Ready (&PyGInterface_Type)) return -1;
85
86 pygtype = pyg_type_wrapper_new (G_TYPE_INTERFACE);
87 PyDict_SetItemString (PyGInterface_Type.tp_dict, "__gtype__", pygtype);
88 Py_DECREF (pygtype);
89
90 PyDict_SetItemString (PyGInterface_Type.tp_dict, "__doc__",
91 pyg_object_descr_doc_get ());
92 PyDict_SetItemString (PyGInterface_Type.tp_dict, "__gdoc__",
93 pyg_object_descr_doc_get ());
94
95 PyDict_SetItemString (d, "GInterface", (PyObject *)&PyGInterface_Type);
96
97 return 0;
98 }