| 1 |
/* -*- Mode: C; c-basic-offset: 4 -*- */ |
| 2 |
#ifndef _PYGTK_H_ |
| 3 |
#define _PYGTK_H_ |
| 4 |
|
| 5 |
#define NO_IMPORT_PYGOBJECT |
| 6 |
#include <pygobject.h> |
| 7 |
#include <Python.h> |
| 8 |
#include <gtk/gtk.h> |
| 9 |
|
| 10 |
struct _PyGtk_FunctionStruct { |
| 11 |
char *pygtkVersion; |
| 12 |
|
| 13 |
PyTypeObject *gdkAtom_type; |
| 14 |
PyObject *(* gdkAtom_new)(GdkAtom atom); |
| 15 |
gboolean (* rectangle_from_pyobject)(PyObject *object, |
| 16 |
GdkRectangle *rectangle); |
| 17 |
PyObject * (*tree_path_to_pyobject) (GtkTreePath *path); |
| 18 |
GtkTreePath * (*tree_path_from_pyobject) (PyObject *object); |
| 19 |
}; |
| 20 |
|
| 21 |
/* structure definitions for the various object types in PyGTK */ |
| 22 |
typedef struct { |
| 23 |
PyObject_HEAD |
| 24 |
gchar *name; |
| 25 |
GdkAtom atom; |
| 26 |
} PyGdkAtom_Object; |
| 27 |
|
| 28 |
/* routines to get the C object value out of the PyObject wrapper */ |
| 29 |
#define PyGdkAtom_Get(v) (((PyGdkAtom_Object *)(v))->atom) |
| 30 |
|
| 31 |
/* this section is dependent on whether we are being included from gtkmodule.c |
| 32 |
* or not. A similar source level interface should be provided in both |
| 33 |
* instances. */ |
| 34 |
#ifndef _INSIDE_PYGTK_ |
| 35 |
|
| 36 |
/* for multi file extensions, define one of these in all but the main file |
| 37 |
* of the module */ |
| 38 |
#if defined(NO_IMPORT) || defined(NO_IMPORT_PYGTK) |
| 39 |
extern struct _PyGtk_FunctionStruct *_PyGtk_API; |
| 40 |
#else |
| 41 |
struct _PyGtk_FunctionStruct *_PyGtk_API; |
| 42 |
#endif |
| 43 |
|
| 44 |
/* type objects */ |
| 45 |
#define PyGdkAtom_Type *(_PyGtk_API->gdkAtom_type) |
| 46 |
|
| 47 |
/* type checking routines */ |
| 48 |
#define PyGdkAtom_Check(v) ((v)->ob_type == _PyGtk_API->gdkAtom_type) |
| 49 |
|
| 50 |
/* type objects */ |
| 51 |
#define PyGdkAtom_New (_PyGtk_API->gdkAtom_new) |
| 52 |
|
| 53 |
/* some variables */ |
| 54 |
#define PYGTK_VERSION (_PyGtk_API->pygtkVersion) |
| 55 |
|
| 56 |
/* public functions */ |
| 57 |
#define pygdk_rectangle_from_pyobject (_PyGtk_API->rectangle_from_pyobject) |
| 58 |
#define pygtk_tree_path_to_pyobject (_PyGtk_API->tree_path_to_pyobject) |
| 59 |
#define pygtk_tree_path_from_pyobject (_PyGtk_API->tree_path_from_pyobject) |
| 60 |
|
| 61 |
|
| 62 |
/* a function to initialise the pygtk functions */ |
| 63 |
#define init_pygtk() G_STMT_START { \ |
| 64 |
PyObject *pygtk = PyImport_ImportModule("gtk"); \ |
| 65 |
if (pygtk != NULL) { \ |
| 66 |
PyObject *module_dict = PyModule_GetDict(pygtk); \ |
| 67 |
PyObject *cobject = PyDict_GetItemString(module_dict, "_PyGtk_API"); \ |
| 68 |
if (PyCObject_Check(cobject)) \ |
| 69 |
_PyGtk_API = (struct _PyGtk_FunctionStruct*) \ |
| 70 |
PyCObject_AsVoidPtr(cobject); \ |
| 71 |
else { \ |
| 72 |
PyErr_SetString(PyExc_RuntimeError, \ |
| 73 |
"could not find _PyGtk_API object"); \ |
| 74 |
return; \ |
| 75 |
} \ |
| 76 |
} else { \ |
| 77 |
PyErr_SetString(PyExc_ImportError, \ |
| 78 |
"could not import gtk"); \ |
| 79 |
return; \ |
| 80 |
} \ |
| 81 |
} G_STMT_END |
| 82 |
|
| 83 |
#endif |
| 84 |
|
| 85 |
#endif /* !_PYGTK_H_ */ |