plug-ins/pygimp/pygimp-api.h plug-ins/pygimp/pygimp.h export common object

2006-11-28  Manish Singh  <yosh@gimp.org>

        * plug-ins/pygimp/pygimp-api.h
        * plug-ins/pygimp/pygimp.h
        * plug-ins/pygimp/gimpmodule.c: export common object types via
        _PyGimp_API, and remove the PDBFunction_Type hack. Also define
        the common object structures here.

        * plug-ins/pygimp/pygimp.h: remove hack for Python < 2.3, since
        we require Python 2.3 now.

        * plug-ins/pygimp/gimpui.override
        * plug-ins/pygimp/gimpui.py: create and use specialized wrappers
        for get/set_active methods for GimpIntComboBox and derived types.
        Fixes #376102.
This commit is contained in:
Manish Singh 2006-11-28 09:46:18 +00:00 committed by Manish Singh
parent 2acc124280
commit 473c0c010f
6 changed files with 295 additions and 61 deletions

View File

@ -1,3 +1,19 @@
2006-11-28 Manish Singh <yosh@gimp.org>
* plug-ins/pygimp/pygimp-api.h
* plug-ins/pygimp/pygimp.h
* plug-ins/pygimp/gimpmodule.c: export common object types via
_PyGimp_API, and remove the PDBFunction_Type hack. Also define
the common object structures here.
* plug-ins/pygimp/pygimp.h: remove hack for Python < 2.3, since
we require Python 2.3 now.
* plug-ins/pygimp/gimpui.override
* plug-ins/pygimp/gimpui.py: create and use specialized wrappers
for get/set_active methods for GimpIntComboBox and derived types.
Fixes #376102.
2006-11-27 Sven Neumann <sven@gimp.org>
* app/core/gimpimage-convert.c: applied patch from Aurimas Juška

View File

@ -25,9 +25,6 @@
#include "pygimpcolor-api.h"
#define _INSIDE_PYGIMP_
#include "pygimp-api.h"
#include <sysmodule.h>
#include <glib-object.h>
@ -1742,15 +1739,18 @@ static struct PyMethodDef gimp_methods[] = {
static struct _PyGimp_Functions pygimp_api_functions = {
&PyGimpImage_Type,
pygimp_image_new,
&PyGimpDisplay_Type,
pygimp_display_new,
&PyGimpDrawable_Type,
pygimp_drawable_new,
&PyGimpLayer_Type,
pygimp_layer_new,
&PyGimpChannel_Type,
pygimp_channel_new,
&PyGimpVectors_Type,
pygimp_vectors_new,
&PyGimpPDBFunction_Type,
pygimp_pdb_function_new
};
@ -1876,6 +1876,7 @@ initgimp(void)
PyDict_SetItemString(d, "Vectors", (PyObject *)&PyGimpVectors_Type);
/* for other modules */
pygimp_api_functions.pygimp_error = pygimp_error;
PyDict_SetItemString(d, "_PyGimp_API",
i=PyCObject_FromVoidPtr(&pygimp_api_functions, NULL));
Py_DECREF(i);

View File

@ -148,6 +148,44 @@ _wrap_gimp_drawable_combo_box_new(PyGObject *self, PyObject *args,
return 0;
}
%%
define GimpDrawableComboBox.set_active_drawable kwargs
static PyObject *
_wrap_gimp_drawable_combo_box_set_active_drawable(PyGObject *self, PyObject *args, PyObject *kwargs)
{
PyGimpDrawable *drw;
static char *kwlist[] = { "drawable", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O!:GimpDrawableComboBox.set_active_drawable",
kwlist,
PyGimpDrawable_Type, &drw))
return NULL;
if (!gimp_int_combo_box_set_active(GIMP_INT_COMBO_BOX(self->obj), drw->ID)) {
PyErr_Format(pygimp_error,
"Drawable (ID %d) does not exist in GimpDrawableComboBox",
drw->ID);
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
%%
define GimpDrawableComboBox.get_active_drawable noargs
static PyObject *
_wrap_gimp_drawable_combo_box_get_active_drawable(PyGObject *self)
{
int value;
if (gimp_int_combo_box_get_active(GIMP_INT_COMBO_BOX(self->obj), &value))
return pygimp_drawable_new(NULL, value);
Py_INCREF(Py_None);
return Py_None;
}
%%
override gimp_channel_combo_box_new kwargs
static gboolean
pygimp_channel_constraint_marshal(gint32 image_id, gint32 channel_id,
@ -239,6 +277,44 @@ _wrap_gimp_channel_combo_box_new(PyGObject *self, PyObject *args,
return 0;
}
%%
define GimpChannelComboBox.set_active_channel kwargs
static PyObject *
_wrap_gimp_channel_combo_box_set_active_channel(PyGObject *self, PyObject *args, PyObject *kwargs)
{
PyGimpChannel *chn;
static char *kwlist[] = { "channel", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O!:GimpChannelComboBox.set_active_channel",
kwlist,
PyGimpChannel_Type, &chn))
return NULL;
if (!gimp_int_combo_box_set_active(GIMP_INT_COMBO_BOX(self->obj), chn->ID)) {
PyErr_Format(pygimp_error,
"Channel (ID %d) does not exist in GimpChannelComboBox",
chn->ID);
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
%%
define GimpChannelComboBox.get_active_channel noargs
static PyObject *
_wrap_gimp_channel_combo_box_get_active_channel(PyGObject *self)
{
int value;
if (gimp_int_combo_box_get_active(GIMP_INT_COMBO_BOX(self->obj), &value))
return pygimp_channel_new(value);
Py_INCREF(Py_None);
return Py_None;
}
%%
override gimp_layer_combo_box_new kwargs
static gboolean
pygimp_layer_constraint_marshal(gint32 image_id, gint32 layer_id,
@ -330,6 +406,44 @@ _wrap_gimp_layer_combo_box_new(PyGObject *self, PyObject *args,
return 0;
}
%%
define GimpLayerComboBox.set_active_layer kwargs
static PyObject *
_wrap_gimp_layer_combo_box_set_active_layer(PyGObject *self, PyObject *args, PyObject *kwargs)
{
PyGimpLayer *lay;
static char *kwlist[] = { "layer", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O!:GimpLayerComboBox.set_active_layer",
kwlist,
PyGimpLayer_Type, &lay))
return NULL;
if (!gimp_int_combo_box_set_active(GIMP_INT_COMBO_BOX(self->obj), lay->ID)) {
PyErr_Format(pygimp_error,
"Layer (ID %d) does not exist in GimpLayerComboBox",
lay->ID);
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
%%
define GimpLayerComboBox.get_active_layer noargs
static PyObject *
_wrap_gimp_layer_combo_box_get_active_layer(PyGObject *self)
{
int value;
if (gimp_int_combo_box_get_active(GIMP_INT_COMBO_BOX(self->obj), &value))
return pygimp_layer_new(value);
Py_INCREF(Py_None);
return Py_None;
}
%%
override gimp_vectors_combo_box_new kwargs
static gboolean
pygimp_vectors_constraint_marshal(gint32 image_id, gint32 vectors_id,
@ -421,6 +535,44 @@ _wrap_gimp_vectors_combo_box_new(PyGObject *self, PyObject *args,
return 0;
}
%%
define GimpVectorsComboBox.set_active_vectors kwargs
static PyObject *
_wrap_gimp_vectors_combo_box_set_active_vectors(PyGObject *self, PyObject *args, PyObject *kwargs)
{
PyGimpVectors *vect;
static char *kwlist[] = { "vectors", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O!:GimpVectorsComboBox.set_active_vectors",
kwlist,
PyGimpVectors_Type, &vect))
return NULL;
if (!gimp_int_combo_box_set_active(GIMP_INT_COMBO_BOX(self->obj), vect->ID)) {
PyErr_Format(pygimp_error,
"Vectors (ID %d) does not exist in GimpVectorsComboBox",
vect->ID);
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
%%
define GimpVectorsComboBox.get_active_vectors noargs
static PyObject *
_wrap_gimp_vectors_combo_box_get_active_vectors(PyGObject *self)
{
int value;
if (gimp_int_combo_box_get_active(GIMP_INT_COMBO_BOX(self->obj), &value))
return pygimp_vectors_new(value);
Py_INCREF(Py_None);
return Py_None;
}
%%
override gimp_image_combo_box_new kwargs
static gboolean
pygimp_image_constraint_marshal(gint32 image_id, gpointer user_data)
@ -503,6 +655,44 @@ _wrap_gimp_image_combo_box_new(PyGObject *self, PyObject *args,
return 0;
}
%%
define GimpImageComboBox.set_active_image kwargs
static PyObject *
_wrap_gimp_image_combo_box_set_active_image(PyGObject *self, PyObject *args, PyObject *kwargs)
{
PyGimpImage *img;
static char *kwlist[] = { "image", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O!:GimpImageComboBox.set_active_image",
kwlist,
PyGimpImage_Type, &img))
return NULL;
if (!gimp_int_combo_box_set_active(GIMP_INT_COMBO_BOX(self->obj), img->ID)) {
PyErr_Format(pygimp_error,
"Image (ID %d) does not exist in GimpImageComboBox",
img->ID);
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
%%
define GimpImageComboBox.get_active_image noargs
static PyObject *
_wrap_gimp_image_combo_box_get_active_image(PyGObject *self)
{
int value;
if (gimp_int_combo_box_get_active(GIMP_INT_COMBO_BOX(self->obj), &value))
return pygimp_image_new(value);
Py_INCREF(Py_None);
return Py_None;
}
%%
override gimp_dialog_new kwargs
static void
pygimp_help_func_marshal(const gchar *help_id, gpointer help_data)
@ -694,12 +884,12 @@ _wrap_gimp_brush_select_button_get_brush(PyGObject *self)
GimpLayerModeEffects paint_mode;
brush_name =
gimp_brush_select_button_get_brush(GIMP_BRUSH_SELECT_BUTTON(self->obj),
&opacity, &spacing, &paint_mode);
gimp_brush_select_button_get_brush(GIMP_BRUSH_SELECT_BUTTON(self->obj),
&opacity, &spacing, &paint_mode);
return Py_BuildValue("(sdiN)", brush_name, opacity, spacing,
pyg_enum_from_gtype(GIMP_TYPE_LAYER_MODE_EFFECTS,
paint_mode));
pyg_enum_from_gtype(GIMP_TYPE_LAYER_MODE_EFFECTS,
paint_mode));
}
%%
override gimp_window_set_transient
@ -902,18 +1092,38 @@ _wrap_gimp_int_combo_box_new(PyGObject *self, PyObject *args, PyObject *kwargs)
%%
new-constructor GIMP_TYPE_INT_COMBO_BOX
%%
override gimp_int_combo_box_get_active
override gimp_int_combo_box_get_active noargs
static PyObject *
_wrap_gimp_int_combo_box_get_active(PyGObject *self, PyObject *args)
_wrap_gimp_int_combo_box_get_active(PyGObject *self)
{
int value;
if (!PyArg_ParseTuple(args, ""))
return NULL;
if (gimp_int_combo_box_get_active(GIMP_INT_COMBO_BOX(self->obj), &value))
return PyLong_FromLong(value);
Py_INCREF(Py_None);
return Py_None;
}
%%
override gimp_int_combo_box_set_active kwargs
static PyObject *
_wrap_gimp_int_combo_box_set_active(PyGObject *self, PyObject *args, PyObject *kwargs)
{
int value;
static char *kwlist[] = { "value", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"i:GimpIntComboBox.set_active", kwlist,
&value))
return NULL;
if (!gimp_int_combo_box_set_active(GIMP_INT_COMBO_BOX(self->obj), value)) {
PyErr_Format(pygimp_error,
"Value %d does not exist in GimpIntComboBox",
value);
return NULL;
}
Py_INCREF(Py_None);
return Py_None;

View File

@ -130,41 +130,41 @@ class ImageSelector(ImageComboBox):
def __init__(self, default=None):
ImageComboBox.__init__(self)
if default is not None:
self.set_active(default)
self.set_active_image(default)
def get_value(self):
return self.get_active()
return self.get_active_image()
class LayerSelector(LayerComboBox):
def __init__(self, default=None):
LayerComboBox.__init__(self)
if default is not None:
self.set_active(default)
self.set_active_layer(default)
def get_value(self):
return self.get_active()
return self.get_active_layer()
class ChannelSelector(ChannelComboBox):
def __init__(self, default=None):
ChannelComboBox.__init__(self)
if default is not None:
self.set_active(default)
self.set_active_channel(default)
def get_value(self):
return self.get_active()
return self.get_active_channel()
class DrawableSelector(DrawableComboBox):
def __init__(self, default=None):
DrawableComboBox.__init__(self)
if default is not None:
self.set_active(default)
self.set_active_drawable(default)
def get_value(self):
return self.get_active()
return self.get_active_drawable()
class VectorsSelector(VectorsComboBox):
def __init__(self, default=None):
VectorsComboBox.__init__(self)
if default is not None:
self.set_active(default)
self.set_active_vectors(default)
def get_value(self):
return self.get_active()
return self.get_active_vectors()
class ColorSelector(ColorButton):
def __init__(self, default=gimpcolor.RGB(1.0, 0, 0)):

View File

@ -25,22 +25,47 @@
#include <libgimp/gimp.h>
typedef struct {
PyObject_HEAD
gint32 ID;
} PyGimpImage;
typedef struct {
PyObject_HEAD
gint32 ID;
} PyGimpDisplay;
typedef struct {
PyObject_HEAD
gint32 ID;
GimpDrawable *drawable;
} PyGimpDrawable, PyGimpLayer, PyGimpChannel;
typedef struct {
PyObject_HEAD
gint32 ID;
} PyGimpVectors;
struct _PyGimp_Functions {
PyTypeObject *Image_Type;
PyObject *(* image_new)(gint32 ID);
PyTypeObject *Display_Type;
PyObject *(* display_new)(gint32 ID);
PyTypeObject *Drawable_Type;
PyObject *(* drawable_new)(GimpDrawable *drawable, gint32 ID);
PyTypeObject *Layer_Type;
PyObject *(* layer_new)(gint32 ID);
PyTypeObject *Channel_Type;
PyObject *(* channel_new)(gint32 ID);
PyTypeObject *Vectors_Type;
PyObject *(* vectors_new)(gint32 ID);
PyTypeObject *PDBFunction_Type;
PyObject *(* pdb_function_new)(const char *name, const char *blurb,
const char *help, const char *author,
const char *copyright, const char *date,
GimpPDBProcType proc_type,
int n_params, int n_return_vals,
GimpParamDef *params,
GimpParamDef *return_vals);
PyObject *pygimp_error;
};
#ifndef _INSIDE_PYGIMP_
@ -51,14 +76,19 @@ extern struct _PyGimp_Functions *_PyGimp_API;
struct _PyGimp_Functions *_PyGimp_API;
#endif
#define PyGimpImage_Type (_PyGimp_API->Image_Type)
#define pygimp_image_new (_PyGimp_API->image_new)
#define PyGimpDisplay_Type (_PyGimp_API->Display_Type)
#define pygimp_display_new (_PyGimp_API->display_new)
#define PyGimpDrawable_Type (_PyGimp_API->Drawable_Type)
#define pygimp_drawable_new (_PyGimp_API->drawable_new)
#define PyGimpLayer_Type (_PyGimp_API->Layer_Type)
#define pygimp_layer_new (_PyGimp_API->layer_new)
#define PyGimpChannel_Type (_PyGimp_API->Channel_Type)
#define pygimp_channel_new (_PyGimp_API->channel_new)
#define PyGimpVectors_Type (_PyGimp_API->Vectors_Type)
#define pygimp_vectors_new (_PyGimp_API->vectors_new)
#define PyGimpPDBFunction_Type (_PyGimp_API->PDBFunction_Type)
#define pygimp_pdb_function_new (_PyGimp_API->pdb_function_new)
#define pygimp_error (_PyGimp_API->pygimp_error)
#define init_pygimp() G_STMT_START { \
PyObject *gimpmodule = PyImport_ImportModule("gimp"); \

View File

@ -22,12 +22,11 @@
#include <Python.h>
#if PY_VERSION_HEX < 0x020300F0
#define PyBool_FromLong(v) PyInt_FromLong((v) ? 1L : 0L);
#endif
#include <libgimp/gimp.h>
#define _INSIDE_PYGIMP_
#include "pygimp-api.h"
G_BEGIN_DECLS
extern PyObject *pygimp_error;
@ -51,31 +50,14 @@ PyObject *pygimp_pdb_function_new(const char *name, const char *blurb,
GimpParamDef *params,
GimpParamDef *return_vals);
typedef struct {
PyObject_HEAD
gint32 ID;
} PyGimpImage;
extern PyTypeObject PyGimpImage_Type;
#define pygimp_image_check(v) (PyObject_TypeCheck(v, &PyGimpImage_Type))
PyObject *pygimp_image_new(gint32 ID);
typedef struct {
PyObject_HEAD
gint32 ID;
} PyGimpDisplay;
extern PyTypeObject PyGimpDisplay_Type;
#define pygimp_display_check(v) (PyObject_TypeCheck(v, &PyGimpDisplay_Type))
PyObject *pygimp_display_new(gint32 ID);
typedef struct {
PyObject_HEAD
gint32 ID;
GimpDrawable *drawable;
} PyGimpDrawable, PyGimpLayer, PyGimpChannel;
extern PyTypeObject PyGimpDrawable_Type;
#define pygimp_drawable_check(v) (PyObject_TypeCheck(v, &PyGimpDrawable_Type))
PyObject *pygimp_drawable_new(GimpDrawable *drawable, gint32 ID);
@ -118,11 +100,6 @@ extern PyTypeObject PyGimpParasite_Type;
#define pygimp_parasite_check(v) (PyObject_TypeCheck(v, &PyGimpParasite_Type))
PyObject *pygimp_parasite_new(GimpParasite *para);
typedef struct {
PyObject_HEAD
gint32 ID;
} PyGimpVectors;
extern PyTypeObject PyGimpVectors_Type;
#define pygimp_vectors_check(v) (PyObject_TypeCheck(v, &PyGimpVectors_Type))
PyObject *pygimp_vectors_new(gint32 vectors_ID);