1 /* -*- Mode: C; c-set-style: python; c-basic-offset: 4 -*-
2 * pyglib - Python bindings for GLib toolkit.
3 * Copyright (C) 1998-2003 James Henstridge
4 * 2004-2008 Johan Dahlin
6 * glibmodule.c: wrapper for the glib library.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
31 #include "pyglib-private.h"
32 #include "pygoptioncontext.h"
33 #include "pygoptiongroup.h"
34 #include "pygsource.h"
37 /* ---------------- glib module functions -------------------- */
40 pyglib_threads_init(PyObject *unused, PyObject *args, PyObject *kwargs)
42 if (!pyglib_enable_threads())
49 static PyMethodDef _glib_functions[] = {
51 (PyCFunction) pyglib_threads_init, METH_NOARGS,
53 "Initialize GLib for use from multiple threads. If you also use GTK+\n"
54 "itself (i.e. GUI, not just PyGObject), use gtk.gdk.threads_init()\n"
57 (PyCFunction)pyglib_spawn_async, METH_VARARGS|METH_KEYWORDS,
58 "spawn_async(argv, envp=None, working_directory=None,\n"
59 " flags=0, child_setup=None, user_data=None,\n"
60 " standard_input=None, standard_output=None,\n"
61 " standard_error=None) -> (pid, stdin, stdout, stderr)\n"
62 "Execute a child program asynchronously within a glib.MainLoop()\n"
63 "See the reference manual for a complete reference." },
67 /* ----------------- glib module initialisation -------------- */
69 static struct _PyGLib_Functions pyglib_api = {
70 FALSE, /* threads_enabled */
71 NULL, /* gerror_exception */
72 NULL, /* block_threads */
73 NULL, /* unblock_threads */
74 NULL, /* pyg_main_context_new */
75 pyg_option_context_new,
80 pyglib_register_api(PyObject *d)
84 /* for addon libraries ... */
85 PyDict_SetItemString(d, "_PyGLib_API",
86 o=PYGLIB_CPointer_WrapPointer(&pyglib_api,"gi._glib._PyGLib_API"));
89 pyglib_init_internal(o);
93 pyglib_register_error(PyObject *d)
96 PyObject *gerror_class;
98 /* This is a hack to work around the deprecation warning of
99 * BaseException.message in Python 2.6+.
100 * GError has also an "message" attribute.
102 PyDict_SetItemString(dict, "message", Py_None);
103 gerror_class = PyErr_NewException("gi._glib.GError", PyExc_RuntimeError, dict);
106 PyDict_SetItemString(d, "GError", gerror_class);
107 pyglib_api.gerror_exception = gerror_class;
110 PYGLIB_MODULE_START(_glib, "_glib")
112 PyObject *d = PyModule_GetDict(module);
114 pyglib_register_api(d);
115 pyglib_register_error(d);
116 pyglib_source_register_types(d);
117 pyglib_spawn_register_types(d);
118 pyglib_option_context_register_types(d);
119 pyglib_option_group_register_types(d);