1 /* -*- Mode: C; c-basic-offset: 4 -*-
2 * pygtk- Python bindings for the GTK toolkit.
3 * Copyright (C) 1998-2003 James Henstridge
5 * pygmaincontext.c: GMainContext wrapper
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, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
30 #include "pygmaincontext.h"
32 #include "pyglib-private.h"
34 PYGLIB_DEFINE_TYPE("gi._glib.MainContext", PyGMainContext_Type, PyGMainContext)
37 * pyg_main_context_new:
38 * @context: a GMainContext.
40 * Creates a wrapper for a GMainContext.
42 * Returns: the GMainContext wrapper.
45 pyg_main_context_new(GMainContext *context)
49 self = (PyGMainContext *)PyObject_NEW(PyGMainContext, &PyGMainContext_Type);
53 self->context = g_main_context_ref(context);
55 return (PyObject *)self;
59 pyg_main_context_init(PyGMainContext *self)
61 self->context = g_main_context_new();
66 pyg_main_context_dealloc(PyGMainContext *self)
68 if (self->context != NULL) {
69 g_main_context_unref(self->context);
77 pyg_main_context_richcompare(PyObject *self, PyObject *other, int op)
79 if (Py_TYPE(self) == Py_TYPE(other) && Py_TYPE(self) == &PyGMainContext_Type)
80 return _pyglib_generic_ptr_richcompare(((PyGMainContext*)self)->context,
81 ((PyGMainContext*)other)->context,
84 Py_INCREF(Py_NotImplemented);
85 return Py_NotImplemented;
90 _wrap_g_main_context_iteration (PyGMainContext *self, PyObject *args)
92 gboolean ret, may_block = TRUE;
94 if (!PyArg_ParseTuple(args, "|i:GMainContext.iteration",
98 pyglib_begin_allow_threads;
99 ret = g_main_context_iteration(self->context, may_block);
100 pyglib_end_allow_threads;
102 return PyBool_FromLong(ret);
106 _wrap_g_main_context_pending (PyGMainContext *self)
108 return PyBool_FromLong(g_main_context_pending(self->context));
111 static PyMethodDef _PyGMainContext_methods[] = {
112 { "iteration", (PyCFunction)_wrap_g_main_context_iteration, METH_VARARGS },
113 { "pending", (PyCFunction)_wrap_g_main_context_pending, METH_NOARGS },
118 pyglib_maincontext_register_types(PyObject *d)
120 PyGMainContext_Type.tp_dealloc = (destructor)pyg_main_context_dealloc;
121 PyGMainContext_Type.tp_richcompare = pyg_main_context_richcompare;
122 PyGMainContext_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
123 PyGMainContext_Type.tp_methods = _PyGMainContext_methods;
124 PyGMainContext_Type.tp_init = (initproc)pyg_main_context_init;
125 PYGLIB_REGISTER_TYPE(d, PyGMainContext_Type, "MainContext");