pygimp-api.h 3.77 KB
Newer Older
1
/* -*- Mode: C; c-basic-offset: 4 -*-
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
 * Gimp-Python - allows the writing of Gimp plugins in Python.
 * Copyright (C) 2005  Manish Singh <yosh@gimp.org>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 18 19 20 21 22 23 24 25
 */

#ifndef _PYGIMP_API_H_
#define _PYGIMP_API_H_

#include <Python.h>

#include <libgimp/gimp.h>

26 27 28
typedef struct {
    PyObject_HEAD
    gint32 ID;
29
} PyGimpImage, PyGimpItem;
30 31 32 33 34 35 36 37 38 39

typedef struct {
    PyObject_HEAD
    gint32 ID;
} PyGimpDisplay;

typedef struct {
    PyObject_HEAD
    gint32 ID;
    GimpDrawable *drawable;
40
} PyGimpDrawable, PyGimpLayer, PyGimpGroupLayer, PyGimpChannel;
41 42 43 44 45 46

typedef struct {
    PyObject_HEAD
    gint32 ID;
} PyGimpVectors;

47
struct _PyGimp_Functions {
48
    PyTypeObject *Image_Type;
49
    PyObject *(* image_new)(gint32 ID);
50 51

    PyTypeObject *Display_Type;
52
    PyObject *(* display_new)(gint32 ID);
53

54 55 56
    PyTypeObject *Item_Type;
    PyObject *(* item_new)(gint32 ID);

57
    PyTypeObject *Drawable_Type;
58
    PyObject *(* drawable_new)(GimpDrawable *drawable, gint32 ID);
59 60

    PyTypeObject *Layer_Type;
61
    PyObject *(* layer_new)(gint32 ID);
62

63 64 65
    PyTypeObject *GroupLayer_Type;
    PyObject *(* group_layer_new)(gint32 ID);

66
    PyTypeObject *Channel_Type;
67
    PyObject *(* channel_new)(gint32 ID);
68 69

    PyTypeObject *Vectors_Type;
Simon Budig's avatar
Simon Budig committed
70
    PyObject *(* vectors_new)(gint32 ID);
71

72
    PyObject *pygimp_error;
73 74 75 76 77 78 79 80 81 82
};

#ifndef _INSIDE_PYGIMP_

#if defined(NO_IMPORT) || defined(NO_IMPORT_PYGIMP)
extern struct _PyGimp_Functions *_PyGimp_API;
#else
struct _PyGimp_Functions *_PyGimp_API;
#endif

83
#define PyGimpImage_Type        (_PyGimp_API->Image_Type)
84
#define pygimp_image_new        (_PyGimp_API->image_new)
85
#define PyGimpDisplay_Type      (_PyGimp_API->Display_Type)
86
#define pygimp_display_new      (_PyGimp_API->display_new)
87 88
#define PyGimpItem_Type         (_PyGimp_API->Item_Type)
#define pygimp_item_new         (_PyGimp_API->item_new)
89
#define PyGimpDrawable_Type     (_PyGimp_API->Drawable_Type)
90
#define pygimp_drawable_new     (_PyGimp_API->drawable_new)
91
#define PyGimpLayer_Type        (_PyGimp_API->Layer_Type)
92
#define pygimp_layer_new        (_PyGimp_API->layer_new)
93 94
#define PyGimpGroupLayer_Type   (_PyGimp_API->GroupLayer_Type)
#define pygimp_group_layer_new  (_PyGimp_API->group_layer_new)
95
#define PyGimpChannel_Type      (_PyGimp_API->Channel_Type)
96
#define pygimp_channel_new      (_PyGimp_API->channel_new)
97
#define PyGimpVectors_Type      (_PyGimp_API->Vectors_Type)
Simon Budig's avatar
Simon Budig committed
98
#define pygimp_vectors_new      (_PyGimp_API->vectors_new)
99
#define pygimp_error            (_PyGimp_API->pygimp_error)
100 101 102 103

#define init_pygimp() G_STMT_START { \
    PyObject *gimpmodule = PyImport_ImportModule("gimp"); \
    if (gimpmodule != NULL) { \
Simon Budig's avatar
Simon Budig committed
104 105 106 107 108 109 110 111 112
        PyObject *mdict = PyModule_GetDict(gimpmodule); \
        PyObject *cobject = PyDict_GetItemString(mdict, "_PyGimp_API"); \
        if (PyCObject_Check(cobject)) \
            _PyGimp_API = PyCObject_AsVoidPtr(cobject); \
        else { \
            PyErr_SetString(PyExc_RuntimeError, \
                            "could not find _PyGimp_API object"); \
            return; \
        } \
113
    } else { \
Simon Budig's avatar
Simon Budig committed
114 115 116
        PyErr_SetString(PyExc_ImportError, \
                        "could not import gimp"); \
        return; \
117 118 119 120 121 122
    } \
} G_STMT_END

#endif /* ! _INSIDE_PYGIMP_ */

#endif /* _PYGIMP_API_H_ */