1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
/* -*- Mode: C; c-basic-offset: 4 -*-
* pygtk- Python bindings for the GTK toolkit.
* Copyright (C) 1998-2003 James Henstridge
*
* pygmaincontext.c: GMainContext wrapper
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <Python.h>
#include <pythread.h>
#include <glib.h>
#include "pygmaincontext.h"
#include "pyglib.h"
#include "pyglib-private.h"
static int
pyg_main_context_init(PyGMainContext *self)
{
self->context = g_main_context_new();
return 0;
}
static void
pyg_main_context_dealloc(PyGMainContext *self)
{
if (self->context != NULL) {
g_main_context_unref(self->context);
self->context = NULL;
}
PyObject_Del(self);
}
static int
pyg_main_context_compare(PyGMainContext *self, PyGMainContext *v)
{
if (self->context == v->context) return 0;
if (self->context > v->context) return -1;
return 1;
}
static PyObject *
_wrap_g_main_context_iteration (PyGMainContext *self, PyObject *args)
{
gboolean ret, may_block = TRUE;
if (!PyArg_ParseTuple(args, "|i:GMainContext.iteration",
&may_block))
return NULL;
pyglib_begin_allow_threads;
ret = g_main_context_iteration(self->context, may_block);
pyglib_end_allow_threads;
return PyBool_FromLong(ret);
}
static PyObject *
_wrap_g_main_context_pending (PyGMainContext *self)
{
return PyBool_FromLong(g_main_context_pending(self->context));
}
static PyMethodDef _PyGMainContext_methods[] = {
{ "iteration", (PyCFunction)_wrap_g_main_context_iteration, METH_VARARGS },
{ "pending", (PyCFunction)_wrap_g_main_context_pending, METH_NOARGS },
{ NULL, NULL, 0 }
};
PyTypeObject PyGMainContext_Type = {
PyObject_HEAD_INIT(NULL)
0,
"glib.MainContext",
sizeof(PyGMainContext),
0,
/* methods */
(destructor)pyg_main_context_dealloc,
(printfunc)0,
(getattrfunc)0,
(setattrfunc)0,
(cmpfunc)pyg_main_context_compare,
(reprfunc)0,
0,
0,
0,
(hashfunc)0,
(ternaryfunc)0,
(reprfunc)0,
(getattrofunc)0,
(setattrofunc)0,
0,
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
NULL,
(traverseproc)0,
(inquiry)0,
(richcmpfunc)0,
0,
(getiterfunc)0,
(iternextfunc)0,
_PyGMainContext_methods,
0,
0,
NULL,
NULL,
(descrgetfunc)0,
(descrsetfunc)0,
0,
(initproc)pyg_main_context_init,
};
void
pyglib_maincontext_register_types(PyObject *d)
{
PYGLIB_REGISTER_TYPE(d, PyGMainContext_Type, "MainContext");
}
|