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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
|
/* -*- Mode: C; c-basic-offset: 4 -*- */
#ifndef _PYGTK_H_
#define _PYGTK_H_
#include <Python.h>
#include <gtk/gtk.h>
struct _PyGtk_FunctionStruct {
char *pygtkVersion;
gboolean fatalExceptions;
void (* blockThreads)(void);
void (* unblockThreads)(void);
GtkDestroyNotify destroyNotify;
GtkCallbackMarshal callbackMarshal;
PyObject *(* argsAsTuple)(int nparams, GtkArg *args);
int (* argsFromSequence)(GtkArg *args, int nparams, PyObject *seq);
int (* argFromPyObject)(GtkArg *arg, PyObject *obj);
PyObject *(* argAsPyObject)(GtkArg *arg);
void (* retFromPyObject)(GtkArg *ret, PyObject *obj);
PyObject *(* retAsPyObject)(GtkArg *ret);
GtkArg *(* dictAsGtkArgs)(PyObject *dict, GtkType type, gint *nargs);
void (* registerBoxed)(GtkType boxed_type,
PyObject *(*from_func)(gpointer boxed),
int (*to_func)(gpointer *boxed, PyObject *obj));
gint (* enum_get_value)(GtkType enum_type, PyObject *obj, int *val);
gint (* flag_get_value)(GtkType enum_type, PyObject *obj, int *val);
PyTypeObject *gtk_type;
PyObject *(* gtk_new)(GtkObject *obj);
PyTypeObject *gtkAccelGroup_type;
PyObject *(*gtkAccelGroup_new)(GtkAccelGroup *ag);
PyTypeObject *gtkStyle_type;
PyObject *(* gtkStyle_new)(GtkStyle *style);
PyTypeObject *gdkFont_type;
PyObject *(* gdkFont_new)(GdkFont *font);
PyTypeObject *gdkColor_type;
PyObject *(* gdkColor_new)(GdkColor *colour);
PyTypeObject *gdkEvent_type;
PyObject *(* gdkEvent_new)(GdkEvent *event);
PyTypeObject *gdkWindow_type;
PyObject *(* gdkWindow_new)(GdkWindow *win);
PyTypeObject *gdkGC_type;
PyObject *(* gdkGC_new)(GdkGC *gc);
PyTypeObject *gdkColormap_type;
PyObject *(* gdkColormap_new)(GdkColormap *colourmap);
PyTypeObject *gdkDragContext_type;
PyObject *(* gdkDragContext_new)(GdkDragContext *ctx);
PyTypeObject *gtkSelectionData_type;
PyObject *(* gtkSelectionData_new)(GtkSelectionData *data);
PyTypeObject *gdkAtom_type;
PyObject *(* gdkAtom_new)(GdkAtom atom);
PyTypeObject *gdkCursor_type;
PyObject *(* gdkCursor_new)(GdkCursor *cursor);
PyTypeObject *gtkCTreeNode_type;
PyObject *(* gtkCTreeNode_new)(GtkCTreeNode *node);
};
/* structure definitions for the various object types in PyGTK */
typedef struct {
PyObject_HEAD
GtkObject *obj;
} PyGtk_Object;
typedef struct {
PyObject_HEAD
GtkAccelGroup *obj;
} PyGtkAccelGroup_Object;
typedef struct {
PyObject_HEAD
GtkStyle *obj;
} PyGtkStyle_Object;
typedef struct {
PyObject_HEAD
GdkFont *obj;
} PyGdkFont_Object;
typedef struct {
PyObject_HEAD
GdkColor obj;
} PyGdkColor_Object;
typedef struct {
PyObject_HEAD
GdkEvent *obj;
PyObject *attrs;
} PyGdkEvent_Object;
typedef struct {
PyObject_HEAD
GdkWindow *obj;
} PyGdkWindow_Object;
typedef struct {
PyObject_HEAD
GdkGC *obj;
} PyGdkGC_Object;
typedef struct {
PyObject_HEAD
GdkColormap *obj;
} PyGdkColormap_Object;
typedef struct {
PyObject_HEAD
GdkDragContext *obj;
} PyGdkDragContext_Object;
typedef struct {
PyObject_HEAD
GtkSelectionData *obj;
} PyGtkSelectionData_Object;
typedef struct {
PyObject_HEAD
gchar *name;
GdkAtom atom;
} PyGdkAtom_Object;
typedef struct {
PyObject_HEAD
GdkCursor *obj;
} PyGdkCursor_Object;
typedef struct {
PyObject_HEAD
GtkCTreeNode *node;
} PyGtkCTreeNode_Object;
/* routines to get the C object value out of the PyObject wrapper */
#define PyGtk_Get(v) (((PyGtk_Object *)(v))->obj)
#define PyGtkAccelGroup_Get(v) (((PyGtkAccelGroup_Object *)(v))->obj)
#define PyGtkStyle_Get(v) (((PyGtkStyle_Object *)(v))->obj)
#define PyGdkFont_Get(v) (((PyGdkFont_Object *)(v))->obj)
#define PyGdkColor_Get(v) (&((PyGdkColor_Object *)(v))->obj)
#define PyGdkEvent_Get(v) (((PyGdkEvent_Object *)(v))->obj)
#define PyGdkWindow_Get(v) (((PyGdkWindow_Object *)(v))->obj)
#define PyGdkGC_Get(v) (((PyGdkGC_Object *)(v))->obj)
#define PyGdkColormap_Get(v) (((PyGdkColormap_Object *)(v))->obj)
#define PyGdkDragContext_Get(v) (((PyGdkDragContext_Object *)(v))->obj)
#define PyGtkSelectionData_Get(v) (((PyGtkSelectionData_Object *)(v))->obj)
#define PyGdkAtom_Get(v) (((PyGdkAtom_Object *)(v))->atom)
#define PyGdkCursor_Get(v) (((PyGdkCursor_Object *)(v))->obj)
#define PyGtkCTreeNode_Get(v) (((PyGtkCTreeNode_Object *)(v))->node)
/* this section is dependent on whether we are being included from gtkmodule.c
* or not. A similar source level interface should be provided in both
* instances. */
#ifdef _INSIDE_PYGTK_
staticforward PyTypeObject PyGtk_Type;
staticforward PyTypeObject PyGtkAccelGroup_Type;
staticforward PyTypeObject PyGtkStyle_Type;
staticforward PyTypeObject PyGdkFont_Type;
staticforward PyTypeObject PyGdkColor_Type;
staticforward PyTypeObject PyGdkEvent_Type;
staticforward PyTypeObject PyGdkWindow_Type;
staticforward PyTypeObject PyGdkGC_Type;
staticforward PyTypeObject PyGdkColormap_Type;
staticforward PyTypeObject PyGdkDragContext_Type;
staticforward PyTypeObject PyGtkSelectionData_Type;
staticforward PyTypeObject PyGdkAtom_Type;
staticforward PyTypeObject PyGdkCursor_Type;
staticforward PyTypeObject PyGtkCTreeNode_Type;
/* check the type of a PyObject */
#define PyGtk_Check(v) ((v)->ob_type == &PyGtk_Type)
#define PyGtkAccelGroup_Check(v) ((v)->ob_type == &PyGtkAccelGroup_Type)
#define PyGtkStyle_Check(v) ((v)->ob_type == &PyGtkStyle_Type)
#define PyGdkFont_Check(v) ((v)->ob_type == &PyGdkFont_Type)
#define PyGdkColor_Check(v) ((v)->ob_type == &PyGdkColor_Type)
#define PyGdkEvent_Check(v) ((v)->ob_type == &PyGdkEvent_Type)
#define PyGdkWindow_Check(v) ((v)->ob_type == &PyGdkWindow_Type)
#define PyGdkGC_Check(v) ((v)->ob_type == &PyGdkGC_Type)
#define PyGdkColormap_Check(v) ((v)->ob_type == &PyGdkColormap_Type)
#define PyGdkDragContext_Check(v) ((v)->ob_type == &PyGdkDragContext_Type)
#define PyGtkSelectionData_Check(v) ((v)->ob_type == &PyGtkSelectionData_Type)
#define PyGdkAtom_Check(v) ((v)->ob_type == &PyGdkAtom_Type)
#define PyGdkCursor_Check(v) ((v)->ob_type == &PyGdkCursor_Type)
#define PyGtkCTreeNode_Check(v) ((v)->ob_type == &PyGtkCTreeNode_Type)
/* constructors for PyObject wrappers ... */
static PyObject *PyGtk_New(GtkObject *obj);
static PyObject *PyGtkAccelGroup_New(GtkAccelGroup *obj);
static PyObject *PyGtkStyle_New(GtkStyle *style);
static PyObject *PyGdkFont_New(GdkFont *font);
static PyObject *PyGdkColor_New(GdkColor *colour);
static PyObject *PyGdkEvent_New(GdkEvent *event);
static PyObject *PyGdkWindow_New(GdkWindow *window);
static PyObject *PyGdkGC_New(GdkGC *gc);
static PyObject *PyGdkColormap_New(GdkColormap *colourmap);
static PyObject *PyGdkDragContext_New(GdkDragContext *ctx);
static PyObject *PyGtkSelectionData_New(GtkSelectionData *data);
static PyObject *PyGdkAtom_New(GdkAtom atom);
static PyObject *PyGdkCursor_New(GdkCursor *cursor);
static PyObject *PyGtkCTreeNode_New(GtkCTreeNode *node);
/* miscelaneous functions */
static void PyGtk_BlockThreads(void);
static void PyGtk_UnblockThreads(void);
static void PyGtk_DestroyNotify(gpointer data);
static void PyGtk_CallbackMarshal(GtkObject *o, gpointer d, guint nargs,
GtkArg *args);
static PyObject *GtkArgs_AsTuple(int nparams, GtkArg *args);
static int GtkArgs_FromSequence(GtkArg *args, int nparams, PyObject *seq);
static int GtkArg_FromPyObject(GtkArg *arg, PyObject *obj);
static PyObject *GtkArg_AsPyObject(GtkArg *arg);
static void GtkRet_FromPyObject(GtkArg *ret, PyObject *py_ret);
static PyObject *GtkRet_AsPyObject(GtkArg *arg);
static GtkArg *PyDict_AsGtkArgs(PyObject *dict, GtkType type, gint *nargs);
static void PyGtk_RegisterBoxed(GtkType boxed_type,
PyObject *(*fromarg)(gpointer boxed),
int (*toarg)(gpointer *boxed, PyObject *obj));
gint PyGtkEnum_get_value(GtkType enum_type, PyObject *obj, int *val);
gint PyGtkFlag_get_value(GtkType enum_type, PyObject *obj, int *val);
static gboolean PyGtk_FatalExceptions = FALSE;
#else
/* for multi file extensions, define one of these in all but the main file
* of the module */
#if defined(NO_IMPORT) || defined(NO_IMPORT_PYGTK)
extern struct _PyGtk_FunctionStruct *_PyGtk_API;
#else
struct _PyGtk_FunctionStruct *_PyGtk_API;
#endif
/* type objects */
#define PyGtk_Type *(_PyGtk_API->gtk_type)
#define PyGtkAccelGroup_Type *(_PyGtk_API->gtkAccelGroup_type)
#define PyGtkStyle_Type *(_PyGtk_API->gtkStyle_type)
#define PyGdkFont_Type *(_PyGtk_API->gdkFont_type)
#define PyGdkColor_Type *(_PyGtk_API->gdkColor_type)
#define PyGdkEvent_Type *(_PyGtk_API->gdkEvent_type)
#define PyGdkWindow_Type *(_PyGtk_API->gdkWindow_type)
#define PyGdkGC_Type *(_PyGtk_API->gdkGC_type)
#define PyGdkColormap_Type *(_PyGtk_API->gdkColormap_type)
#define PyGdkDragContext_Type *(_PyGtk_API->gdkDragContext_type)
#define PyGtkSelectionData_Type *(_PyGtk_API->gtkSelectionData_type)
#define PyGdkAtom_Type *(_PyGtk_API->gdkAtom_type)
#define PyGdkCursor_Type *(_PyGtk_API->gdkCursor_type)
#define PyGtkCTreeNode_Type *(_PyGtk_API->gtkCTreeNode_type)
/* type checking routines */
#define PyGtk_Check(v) ((v)->ob_type == _PyGtk_API->gtk_type)
#define PyGtkAccelGroup_Check(v) ((v)->ob_type == _PyGtk_API->gtkAccelGroup_type)
#define PyGtkStyle_Check(v) ((v)->ob_type == _PyGtk_API->gtkStyle_type)
#define PyGdkFont_Check(v) ((v)->ob_type == _PyGtk_API->gdkFont_type)
#define PyGdkColor_Check(v) ((v)->ob_type == _PyGtk_API->gdkColor_type)
#define PyGdkEvent_Check(v) ((v)->ob_type == _PyGtk_API->gdkEvent_type)
#define PyGdkWindow_Check(v) ((v)->ob_type == _PyGtk_API->gdkWindow_type)
#define PyGdkGC_Check(v) ((v)->ob_type == _PyGtk_API->gdkGC_type)
#define PyGdkColormap_Check(v) ((v)->ob_type == _PyGtk_API->gdkColormap_type)
#define PyGdkDragContext_Check(v) ((v)->ob_type == _PyGtk_API->gdkDragContext_type)
#define PyGtkSelectionData_Check(v) ((v)->ob_type == _PyGtk_API->gtkSelectionData_type)
#define PyGdkAtom_Check(v) ((v)->ob_type == _PyGtk_API->gdkAtom_type)
#define PyGdkCursor_Check(v) ((v)->ob_type == _PyGtk_API->gdkCursor_type)
#define PyGtkCTreeNode_Check(v) ((v)->ob_type == _PyGtk_API->GtkCTreeNode_type)
/* type objects */
#define PyGtk_New (_PyGtk_API->gtk_new)
#define PyGtkAccelGroup_New (_PyGtk_API->gtkAccelGroup_new)
#define PyGtkStyle_New (_PyGtk_API->gtkStyle_new)
#define PyGdkFont_New (_PyGtk_API->gdkFont_new)
#define PyGdkColor_New (_PyGtk_API->gdkColor_new)
#define PyGdkEvent_New (_PyGtk_API->gdkEvent_new)
#define PyGdkWindow_New (_PyGtk_API->gdkWindow_new)
#define PyGdkGC_New (_PyGtk_API->gdkGC_new)
#define PyGdkColormap_New (_PyGtk_API->gdkColormap_new)
#define PyGdkDragContext_New (_PyGtk_API->gdkDragContext_new)
#define PyGtkSelectionData_New (_PyGtk_API->gtkSelectionData_new)
#define PyGdkAtom_New (_PyGtk_API->gdkAtom_new)
#define PyGdkCursor_New (_PyGtk_API->gdkCursor_new)
#define PyGtkCTreeNode_New (_PyGtk_API->gtkCTreeNode_new)
/* miscelaneous other functions */
#define PyGtk_BlockThreads (_PyGtk_API->blockThreads)
#define PyGtk_UnblockThreads (_PyGtk_API->unblockThreads)
#define PyGtk_DestroyNotify (_PyGtk_API->destroyNotify)
#define PyGtk_CallbackMarshal (_PyGtk_API->callbackMarshal)
#define GtkArgs_AsTuple (_PyGtk_API->argsAsTuple)
#define GtkArgs_FromSequence (_PyGtk_API->argsFromSequence)
#define GtkArg_FromPyObject (_PyGtk_API->argFromPyObject)
#define GtkArg_AsPyObject (_PyGtk_API->argAsPyObject)
#define GtkRet_FromPyObject (_PyGtk_API->retFromPyObject)
#define GtkRet_AsPyObject (_PyGtk_API->retAsPyObject)
#define PyDict_AsGtkArgs (_PyGtk_API->dictAsGtkArgs)
#define PyGtk_RegisterBoxed (_PyGtk_API->registerBoxed)
#define PyGtkEnum_get_value (_PyGtk_API->enum_get_value)
#define PyGtkFlag_get_value (_PyGtk_API->flag_get_value)
/* some variables */
#define PyGtk_FatalExceptions (_PyGtk_API->fatalExceptions)
#define PYGTK_VERSION (_PyGtk_API->pygtkVersion)
/* a function to initialise the pygtk functions */
#define init_pygtk() { \
PyObject *pygtk = PyImport_ImportModule("_gtk"); \
if (pygtk != NULL) { \
PyObject *module_dict = PyModule_GetDict(pygtk); \
PyObject *cobject = PyDict_GetItemString(module_dict, "_PyGtk_API"); \
if (PyCObject_Check(cobject)) \
_PyGtk_API = PyCObject_AsVoidPtr(cobject); \
else { \
Py_FatalError("could not find _PyGtk_API object"); \
return; \
} \
} else { \
Py_FatalError("could not import _gtk"); \
return; \
} \
}
#endif
#endif /* !_PYGTK_H_ */
|