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/>.
26 #include <glib-object.h>
29 #include "pyginterface.h"
32 GQuark pyginterface_type_key
;
33 GQuark pyginterface_info_key
;
35 PYGLIB_DEFINE_TYPE("gobject.GInterface", PyGInterface_Type
, PyObject
)
38 pyg_interface_init(PyObject
*self
, PyObject
*args
, PyObject
*kwargs
)
42 if (!PyArg_ParseTuple(args
, ":GInterface.__init__"))
45 g_snprintf(buf
, sizeof(buf
), "%s can not be constructed",
46 Py_TYPE(self
)->tp_name
);
47 PyErr_SetString(PyExc_NotImplementedError
, buf
);
52 pyg_interface_free(PyObject
*op
)
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.
69 pyg_register_interface(PyObject
*dict
, const gchar
*class_name
,
70 GType gtype
, PyTypeObject
*type
)
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
);
83 o
= pyg_type_wrapper_new(gtype
);
84 PyDict_SetItemString(type
->tp_dict
, "__gtype__", o
);
88 g_type_set_qdata(gtype
, pyginterface_type_key
, type
);
90 PyDict_SetItemString(dict
, (char *)class_name
, (PyObject
*)type
);
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
);
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());