add getsets for common drawable attributes. (PyGimpLayer_Type): convert

2002-08-30  James Henstridge  <james@daa.com.au>

    * pygimp-drawable.c (PyGimpDrawable_Type): add getsets for common
    drawable attributes.
    (PyGimpLayer_Type): convert getattr and setattr to getsets.
    (PyGimpChannel_Type): convert to getsets.

    * gimpmodule.c (new_parasite): remove.  Superceded by
    gimp.Parasite constructor.
    (pygimp_image_list): rename to match actual API.

    * pygimp-parasite.c (PyGimpParasite_Type): switch to getsets.
    (para_init): add constructor.
This commit is contained in:
James Henstridge
2002-08-30 12:46:27 +00:00
committed by James Henstridge
parent 430a9f5d55
commit 29aa6f5037
9 changed files with 547 additions and 438 deletions

View File

@ -1,5 +1,17 @@
2002-08-30 James Henstridge <james@daa.com.au>
* pygimp-drawable.c (PyGimpDrawable_Type): add getsets for common
drawable attributes.
(PyGimpLayer_Type): convert getattr and setattr to getsets.
(PyGimpChannel_Type): convert to getsets.
* gimpmodule.c (new_parasite): remove. Superceded by
gimp.Parasite constructor.
(pygimp_image_list): rename to match actual API.
* pygimp-parasite.c (PyGimpParasite_Type): switch to getsets.
(para_init): add constructor.
* pygimp-tile.c (PyGimpPixelRgn_Type): convert to use getsets.
(PyGimpTile_Type): convert to use getsets.

View File

@ -295,12 +295,12 @@ pygimp_progress_update(PyObject *self, PyObject *args)
}
static PyObject *
pygimp_query_images(PyObject *self, PyObject *args)
pygimp_image_list(PyObject *self, PyObject *args)
{
gint32 *imgs;
int nimgs, i;
PyObject *ret;
if (!PyArg_ParseTuple(args, ":query_images"))
if (!PyArg_ParseTuple(args, ":image_list"))
return NULL;
imgs = gimp_image_list(&nimgs);
ret = PyList_New(nimgs);
@ -719,17 +719,6 @@ pygimp_extension_process(PyObject *self, PyObject *args)
return Py_None;
}
static PyObject *
new_parasite(PyObject *self, PyObject *args)
{
char *name, *data;
int flags, size;
if (!PyArg_ParseTuple(args, "sis#:parasite", &name, &flags,
&data, &size))
return NULL;
return pygimp_parasite_new(gimp_parasite_new(name, flags, size, data));
}
static PyObject *
pygimp_parasite_find(PyObject *self, PyObject *args)
{
@ -828,7 +817,7 @@ static struct PyMethodDef gimp_methods[] = {
{"get_data", (PyCFunction)pygimp_get_data, METH_VARARGS},
{"progress_init", (PyCFunction)pygimp_progress_init, METH_VARARGS},
{"progress_update", (PyCFunction)pygimp_progress_update, METH_VARARGS},
{"query_images", (PyCFunction)pygimp_query_images, METH_VARARGS},
{"image_list", (PyCFunction)pygimp_image_list, METH_VARARGS},
{"install_procedure", (PyCFunction)pygimp_install_procedure, METH_VARARGS},
{"install_temp_proc", (PyCFunction)pygimp_install_temp_proc, METH_VARARGS},
{"uninstall_temp_proc", (PyCFunction)pygimp_uninstall_temp_proc, METH_VARARGS},
@ -855,7 +844,6 @@ static struct PyMethodDef gimp_methods[] = {
{"tile_height", (PyCFunction)pygimp_tile_height, METH_VARARGS},
{"extension_ack", (PyCFunction)pygimp_extension_ack, METH_VARARGS},
{"extension_process", (PyCFunction)pygimp_extension_process, METH_VARARGS},
{"parasite", (PyCFunction)new_parasite, METH_VARARGS},
{"parasite_find", (PyCFunction)pygimp_parasite_find, METH_VARARGS},
{"parasite_attach", (PyCFunction)pygimp_parasite_attach, METH_VARARGS},
{"attach_new_parasite",(PyCFunction)pygimp_attach_new_parasite,METH_VARARGS},

View File

@ -33,7 +33,7 @@ def _createMenu(items, callback, data):
def ImageMenu(constraint=None, callback=None, data=None):
items = []
for img in gimp.query_images():
for img in gimp.image_list():
if constraint and not constraint(img):
continue
items.append((img.filename, img))
@ -42,7 +42,7 @@ def ImageMenu(constraint=None, callback=None, data=None):
def LayerMenu(constraint=None, callback=None, data=None):
items = []
for img in gimp.query_images():
for img in gimp.image_list():
filename = img.filename
for layer in img.layers:
if constraint and not constraint(img, layer):
@ -54,7 +54,7 @@ def LayerMenu(constraint=None, callback=None, data=None):
def ChannelMenu(constraint=None, callback=None, data=None):
items = []
for img in gimp.query_images():
for img in gimp.image_list():
filename = img.filename
for channel in img.channels:
if constraint and not constraint(img, channel):
@ -66,7 +66,7 @@ def ChannelMenu(constraint=None, callback=None, data=None):
def DrawableMenu(constraint=None, callback=None, data=None):
items = []
for img in gimp.query_images():
for img in gimp.image_list():
filename = img.filename
for drawable in img.layers + img.channels:
if constraint and not constraint(img, drawable):

View File

@ -22,7 +22,7 @@
#endif
#include "pygimp.h"
static struct PyMethodDef disp_methods[] = {
static PyMethodDef disp_methods[] = {
{NULL, NULL} /* sentinel */
};

View File

@ -158,34 +158,6 @@ drw_parasite_detach(PyGimpDrawable *self, PyObject *args)
return Py_None;
}
static void
drw_dealloc(PyGimpLayer *self)
{
if (self->drawable)
gimp_drawable_detach(self->drawable);
PyObject_DEL(self);
}
static PyObject *
drw_repr(PyGimpLayer *self)
{
PyObject *s;
gchar *name;
name = gimp_drawable_name(self->ID);
s = PyString_FromFormat("<gimp.Drawable %s>", name);
g_free(name);
return s;
}
static int
drw_cmp(PyGimpLayer *self, PyGimpLayer *other)
{
if (self->ID == other->ID) return 0;
if (self->ID > other->ID) return -1;
return 1;
}
/* for inclusion with the methods of layer and channel objects */
static PyMethodDef drw_methods[] = {
{"flush", (PyCFunction)drw_flush, METH_VARARGS},
@ -202,6 +174,129 @@ static PyMethodDef drw_methods[] = {
{NULL, NULL, 0}
};
static PyObject *
drw_get_ID(PyGimpDrawable *self, void *closure)
{
return PyInt_FromLong(self->ID);
}
static PyObject *
drw_get_bpp(PyGimpDrawable *self, void *closure)
{
return PyInt_FromLong(gimp_drawable_bpp(self->ID));
}
static PyObject *
drw_get_has_alpha(PyGimpDrawable *self, void *closure)
{
return PyInt_FromLong(gimp_drawable_has_alpha(self->ID));
}
static PyObject *
drw_get_height(PyGimpDrawable *self, void *closure)
{
return PyInt_FromLong(gimp_drawable_height(self->ID));
}
static PyObject *
drw_get_is_rgb(PyGimpDrawable *self, void *closure)
{
return PyInt_FromLong(gimp_drawable_is_rgb(self->ID));
}
static PyObject *
drw_get_is_gray(PyGimpDrawable *self, void *closure)
{
return PyInt_FromLong(gimp_drawable_is_gray(self->ID));
}
static PyObject *
drw_get_is_indexed(PyGimpDrawable *self, void *closure)
{
return PyInt_FromLong(gimp_drawable_is_indexed(self->ID));
}
static PyObject *
drw_get_is_layer_mask(PyGimpDrawable *self, void *closure)
{
return PyInt_FromLong(gimp_drawable_is_layer_mask(self->ID));
}
static PyObject *
drw_get_mask_bounds(PyGimpDrawable *self, void *closure)
{
gint x1, y1, x2, y2;
gimp_drawable_mask_bounds(self->ID, &x1, &y1, &x2, &y2);
return Py_BuildValue("(iiii)", x1, y1, x2, y2);
}
static PyObject *
drw_get_offsets(PyGimpDrawable *self, void *closure)
{
gint x, y;
gimp_drawable_offsets(self->ID, &x, &y);
return Py_BuildValue("(ii)", x, y);
}
static PyObject *
drw_get_type(PyGimpDrawable *self, void *closure)
{
return PyInt_FromLong(gimp_drawable_type(self->ID));
}
static PyObject *
drw_get_width(PyGimpDrawable *self, void *closure)
{
return PyInt_FromLong(gimp_drawable_width(self->ID));
}
static PyGetSetDef drw_getsets[] = {
{ "ID", (getter)drw_get_ID, (setter)0 },
{ "bpp", (getter)drw_get_bpp, (setter)0 },
{ "has_alpha", (getter)drw_get_has_alpha, (setter)0 },
{ "height", (getter)drw_get_height, (setter)0 },
{ "is_rgb", (getter)drw_get_is_rgb, (setter)0 },
{ "is_gray", (getter)drw_get_is_gray, (setter)0 },
{ "is_grey", (getter)drw_get_is_gray, (setter)0 },
{ "is_indexed", (getter)drw_get_is_indexed, (setter)0 },
{ "is_layer_mask", (getter)drw_get_is_layer_mask, (setter)0 },
{ "mask_bounds", (getter)drw_get_mask_bounds, (setter)0 },
{ "offsets", (getter)drw_get_offsets, (setter)0 },
{ "type", (getter)drw_get_type, (setter)0 },
{ "width", (getter)drw_get_width, (setter)0 },
{ NULL, (getter)0, (setter)0 }
};
static void
drw_dealloc(PyGimpLayer *self)
{
if (self->drawable)
gimp_drawable_detach(self->drawable);
PyObject_DEL(self);
}
static PyObject *
drw_repr(PyGimpLayer *self)
{
PyObject *s;
gchar *name;
name = gimp_drawable_name(self->ID);
s = PyString_FromFormat("<gimp.Drawable '%s'>", name);
g_free(name);
return s;
}
static int
drw_cmp(PyGimpLayer *self, PyGimpLayer *other)
{
if (self->ID == other->ID) return 0;
if (self->ID > other->ID) return -1;
return 1;
}
PyTypeObject PyGimpDrawable_Type = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
@ -234,7 +329,7 @@ PyTypeObject PyGimpDrawable_Type = {
(iternextfunc)0, /* tp_iternext */
drw_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
drw_getsets, /* tp_getset */
(PyTypeObject *)0, /* tp_base */
(PyObject *)0, /* tp_dict */
0, /* tp_descr_get */
@ -385,7 +480,7 @@ lay_get_tattoo(PyGimpLayer *self, PyObject *args)
return PyInt_FromLong(gimp_layer_get_tattoo(self->ID));
}
static struct PyMethodDef lay_methods[] = {
static PyMethodDef lay_methods[] = {
{"copy", (PyCFunction)lay_copy, METH_VARARGS},
{"add_alpha", (PyCFunction)lay_add_alpha, METH_VARARGS},
{"create_mask", (PyCFunction)lay_create_mask, METH_VARARGS},
@ -397,194 +492,221 @@ static struct PyMethodDef lay_methods[] = {
{NULL, NULL} /* sentinel */
};
static PyObject *
lay_get_image(PyGimpLayer *self, void *closure)
{
gint32 id = gimp_layer_get_image_id(self->ID);
if (id == -1) {
Py_INCREF(Py_None);
return Py_None;
}
return pygimp_image_new(id);
}
static PyObject *
lay_getattr(PyGimpLayer *self, char *attr)
lay_get_is_floating_selection(PyGimpLayer *self, void *closure)
{
gint32 id;
if (!strcmp(attr, "__members__"))
return Py_BuildValue("[ssssssssssssssssssss]", "ID", "apply_mask",
"bpp", "edit_mask", "has_alpha", "height",
"image", "is_color", "is_colour",
"is_floating_selection", "is_gray", "is_grey",
"is_indexed", "is_rgb", "mask", "mask_bounds",
"mode", "name", "offsets", "opacity",
"preserve_transparency", "show_mask", "type",
"visible", "width");
if (!strcmp(attr, "ID"))
return PyInt_FromLong(self->ID);
if (!strcmp(attr, "bpp"))
return PyInt_FromLong((long) gimp_drawable_bpp(self->ID));
if (!strcmp(attr, "has_alpha"))
return PyInt_FromLong(gimp_drawable_has_alpha(self->ID));
if (!strcmp(attr, "height"))
return PyInt_FromLong((long) gimp_drawable_height(self->ID));
if (!strcmp(attr, "image")) {
id = gimp_layer_get_image_id(self->ID);
if (id == -1) {
Py_INCREF(Py_None);
return Py_None;
}
return pygimp_image_new(id);
}
if (!strcmp(attr, "is_color") || !strcmp(attr, "is_colour") ||
!strcmp(attr, "is_rgb"))
return PyInt_FromLong(gimp_drawable_is_rgb(self->ID));
if (!strcmp(attr, "is_floating_selection"))
return PyInt_FromLong(
gimp_layer_is_floating_selection(self->ID));
if (!strcmp(attr, "is_gray") || !strcmp(attr, "is_grey"))
return PyInt_FromLong(gimp_drawable_is_gray(self->ID));
if (!strcmp(attr, "is_indexed"))
return PyInt_FromLong(gimp_drawable_is_indexed(self->ID));
if (!strcmp(attr, "mask")) {
id = gimp_layer_get_mask_id(self->ID);
if (id == -1) {
Py_INCREF(Py_None);
return Py_None;
}
return pygimp_channel_new(id);
}
if (!strcmp(attr, "mask_bounds")) {
gint x1, y1, x2, y2;
gimp_drawable_mask_bounds(self->ID, &x1, &y1, &x2, &y2);
return Py_BuildValue("(iiii)", x1, y1, x2, y2);
}
if (!strcmp(attr, "apply_mask"))
return PyInt_FromLong((long) gimp_layer_get_apply_mask(
self->ID));
if (!strcmp(attr, "edit_mask"))
return PyInt_FromLong((long) gimp_layer_get_edit_mask(
self->ID));
if (!strcmp(attr, "mode"))
return PyInt_FromLong((long) gimp_layer_get_mode(self->ID));
if (!strcmp(attr, "name"))
return PyString_FromString(gimp_layer_get_name(self->ID));
if (!strcmp(attr, "offsets")) {
gint x, y;
gimp_drawable_offsets(self->ID, &x, &y);
return Py_BuildValue("(ii)", x, y);
}
if (!strcmp(attr, "opacity"))
return PyFloat_FromDouble((double) gimp_layer_get_opacity(
self->ID));
if (!strcmp(attr, "preserve_transparency"))
return PyInt_FromLong((long)
gimp_layer_get_preserve_transparency(self->ID));
if (!strcmp(attr, "show_mask"))
return PyInt_FromLong((long) gimp_layer_get_show_mask(
self->ID));
if (!strcmp(attr, "type"))
return PyInt_FromLong((long) gimp_drawable_type(self->ID));
if (!strcmp(attr, "visible"))
return PyInt_FromLong((long) gimp_layer_get_visible(self->ID));
if (!strcmp(attr, "width"))
return PyInt_FromLong((long) gimp_drawable_width(self->ID));
{
PyObject *name = PyString_FromString(attr);
PyObject *ret = PyObject_GenericGetAttr((PyObject *)self, name);
Py_DECREF(name);
return ret;
return PyInt_FromLong(gimp_layer_is_floating_selection(self->ID));
}
static PyObject *
lay_get_mask(PyGimpLayer *self, void *closure)
{
gint32 id = gimp_layer_get_mask_id(self->ID);
if (id == -1) {
Py_INCREF(Py_None);
return Py_None;
}
return pygimp_channel_new(id);
}
static PyObject *
lay_get_apply_mask(PyGimpLayer *self, void *closure)
{
return PyInt_FromLong(gimp_layer_get_apply_mask(self->ID));
}
static int
lay_setattr(PyGimpLayer *self, char *attr, PyObject *v)
lay_set_apply_mask(PyGimpLayer *self, PyObject *value, void *closure)
{
if (v == NULL) {
PyErr_SetString(PyExc_TypeError, "can not delete attributes.");
if (value == NULL) {
PyErr_SetString(PyExc_TypeError, "can not delete apply_mask.");
return -1;
}
if (!PyInt_Check(value)) {
PyErr_SetString(PyExc_TypeError, "type mis-match.");
return -1;
}
/* Set attribute 'name' to value 'v'. v==NULL means delete */
if (!strcmp(attr, "apply_mask")) {
if (!PyInt_Check(v)) {
PyErr_SetString(PyExc_TypeError, "type mis-match.");
return -1;
}
gimp_layer_set_apply_mask(self->ID, PyInt_AsLong(v));
return 0;
}
if (!strcmp(attr, "edit_mask")) {
if (!PyInt_Check(v)) {
PyErr_SetString(PyExc_TypeError, "type mis-match.");
return -1;
}
gimp_layer_set_edit_mask(self->ID, PyInt_AsLong(v));
return 0;
}
if (!strcmp(attr, "mode")) {
if (!PyInt_Check(v)) {
PyErr_SetString(PyExc_TypeError, "type mis-match.");
return -1;
}
gimp_layer_set_mode(self->ID, (GimpLayerModeEffects)PyInt_AsLong(v));
return 0;
}
if (!strcmp(attr, "name")) {
if (!PyString_Check(v)) {
PyErr_SetString(PyExc_TypeError, "type mis-match.");
return -1;
}
gimp_layer_set_name(self->ID, PyString_AsString(v));
return 0;
}
if (!strcmp(attr, "opacity")) {
if (!PyFloat_Check(v)) {
PyErr_SetString(PyExc_TypeError, "type mis-match.");
return -1;
}
gimp_layer_set_opacity(self->ID, PyFloat_AsDouble(v));
return 0;
}
if (!strcmp(attr, "preserve_transparency")) {
if (!PyInt_Check(v)) {
PyErr_SetString(PyExc_TypeError, "type mis-match.");
return -1;
}
gimp_layer_set_preserve_transparency(self->ID,
PyInt_AsLong(v));
return 0;
}
if (!strcmp(attr, "show_mask")) {
if (!PyInt_Check(v)) {
PyErr_SetString(PyExc_TypeError, "type mis-match.");
return -1;
}
gimp_layer_set_show_mask(self->ID, PyInt_AsLong(v));
return 0;
}
if (!strcmp(attr, "visible")) {
if (!PyInt_Check(v)) {
PyErr_SetString(PyExc_TypeError, "type mis-match.");
return -1;
}
gimp_layer_set_visible(self->ID, PyInt_AsLong(v));
return 0;
}
if (!strcmp(attr, "ID") ||
!strcmp(attr, "bpp") || !strcmp(attr, "height") ||
!strcmp(attr, "image") || !strcmp(attr, "mask") ||
!strcmp(attr, "type") || !strcmp(attr, "width") ||
!strcmp(attr, "is_floating_selection") ||
!strcmp(attr, "offsets") || !strcmp(attr, "mask_bounds") ||
!strcmp(attr, "has_alpha") || !strcmp(attr, "is_color") ||
!strcmp(attr, "is_colour") || !strcmp(attr, "is_rgb") ||
!strcmp(attr, "is_gray") || !strcmp(attr, "is_grey") ||
!strcmp(attr, "is_indexed") || !strcmp(attr, "__members__")) {
PyErr_SetString(PyExc_TypeError, "read-only attribute.");
return -1;
}
{
PyObject *name = PyString_FromString(attr);
int ret = PyObject_GenericSetAttr((PyObject *)self, name, v);
Py_DECREF(name);
return ret;
}
gimp_layer_set_apply_mask(self->ID, PyInt_AsLong(value));
return 0;
}
static PyObject *
lay_get_edit_mask(PyGimpLayer *self, void *closure)
{
return PyInt_FromLong(gimp_layer_get_edit_mask(self->ID));}
static int
lay_set_edit_mask(PyGimpLayer *self, PyObject *value, void *closure)
{
if (value == NULL) {
PyErr_SetString(PyExc_TypeError, "can not delete edit_mask.");
return -1;
}
if (!PyInt_Check(value)) {
PyErr_SetString(PyExc_TypeError, "type mis-match.");
return -1;
}
gimp_layer_set_edit_mask(self->ID, PyInt_AsLong(value));
return 0;
}
static PyObject *
lay_get_mode(PyGimpLayer *self, void *closure)
{
return PyInt_FromLong(gimp_layer_get_mode(self->ID));
}
static int
lay_set_mode(PyGimpLayer *self, PyObject *value, void *closure)
{
if (value == NULL) {
PyErr_SetString(PyExc_TypeError, "can not delete mode.");
return -1;
}
if (!PyInt_Check(value)) {
PyErr_SetString(PyExc_TypeError, "type mis-match.");
return -1;
}
gimp_layer_set_mode(self->ID, (GimpLayerModeEffects)PyInt_AsLong(value));
return 0;
}
static PyObject *
lay_get_name(PyGimpLayer *self, void *closure)
{
return PyString_FromString(gimp_layer_get_name(self->ID));
}
static int
lay_set_name(PyGimpLayer *self, PyObject *value, void *closure)
{
if (value == NULL) {
PyErr_SetString(PyExc_TypeError, "can not delete name.");
return -1;
}
if (!PyString_Check(value)) {
PyErr_SetString(PyExc_TypeError, "type mis-match.");
return -1;
}
gimp_layer_set_name(self->ID, PyString_AsString(value));
return 0;
}
static PyObject *
lay_get_opacity(PyGimpLayer *self, void *closure)
{
return PyFloat_FromDouble(gimp_layer_get_opacity(self->ID));
}
static int
lay_set_opacity(PyGimpLayer *self, PyObject *value, void *closure)
{
if (value == NULL) {
PyErr_SetString(PyExc_TypeError, "can not delete opacity.");
return -1;
}
if (!PyFloat_Check(value)) {
PyErr_SetString(PyExc_TypeError, "type mis-match.");
return -1;
}
gimp_layer_set_opacity(self->ID, PyFloat_AsDouble(value));
return 0;
}
static PyObject *
lay_get_preserve_transparency(PyGimpLayer *self, void *closure)
{
return PyInt_FromLong(gimp_layer_get_preserve_transparency(self->ID));
}
static int
lay_set_preserve_transparency(PyGimpLayer *self, PyObject *value,
void *closure)
{
if (value == NULL) {
PyErr_SetString(PyExc_TypeError,
"can not delete preserve_transparency.");
return -1;
}
if (!PyInt_Check(value)) {
PyErr_SetString(PyExc_TypeError, "type mis-match.");
return -1;
}
gimp_layer_set_preserve_transparency(self->ID, PyInt_AsLong(value));
return 0;
}
static PyObject *
lay_get_show_mask(PyGimpLayer *self, void *closure)
{
return PyInt_FromLong(gimp_layer_get_show_mask(self->ID));
}
static int
lay_set_show_mask(PyGimpLayer *self, PyObject *value, void *closure)
{
if (value == NULL) {
PyErr_SetString(PyExc_TypeError, "can not delete show_mask.");
return -1;
}
if (!PyInt_Check(value)) {
PyErr_SetString(PyExc_TypeError, "type mis-match.");
return -1;
}
gimp_layer_set_show_mask(self->ID, PyInt_AsLong(value));
return 0;
}
static PyObject *
lay_get_visible(PyGimpLayer *self, void *closure)
{
return PyInt_FromLong(gimp_layer_get_visible(self->ID));
}
static int
lay_set_visible(PyGimpLayer *self, PyObject *value, void *closure)
{
if (value == NULL) {
PyErr_SetString(PyExc_TypeError, "can not delete visible.");
return -1;
}
if (!PyInt_Check(value)) {
PyErr_SetString(PyExc_TypeError, "type mis-match.");
return -1;
}
gimp_layer_set_visible(self->ID, PyInt_AsLong(value));
return 0;
}
static PyGetSetDef lay_getsets[] = {
{ "image", (getter)lay_get_image, (setter)0 },
{ "is_floating_selection", (getter)lay_get_is_floating_selection,
(setter)0 },
{ "mask", (getter)lay_get_mask, (setter)0 },
{ "apply_mask", (getter)lay_get_apply_mask, (setter)lay_set_apply_mask },
{ "edit_mask", (getter)lay_get_edit_mask, (setter)lay_set_edit_mask },
{ "mode", (getter)lay_get_mode, (setter)lay_set_mode },
{ "name", (getter)lay_get_name, (setter)lay_set_name },
{ "opacity", (getter)lay_get_opacity, (setter)lay_set_opacity },
{ "preserve_transparency", (getter)lay_get_preserve_transparency,
(setter)lay_set_preserve_transparency },
{ "show_mask", (getter)lay_get_show_mask, (setter)lay_set_show_mask },
{ "visible", (getter)lay_get_visible, (setter)lay_set_visible },
{ NULL, (getter)0, (setter)0 }
};
static PyObject *
lay_repr(PyGimpLayer *self)
{
@ -592,7 +714,7 @@ lay_repr(PyGimpLayer *self)
gchar *name;
name = gimp_layer_get_name(self->ID);
s = PyString_FromFormat("<gimp.Layer %s>", name);
s = PyString_FromFormat("<gimp.Layer '%s'>", name);
g_free(name);
return s;
}
@ -631,8 +753,8 @@ PyTypeObject PyGimpLayer_Type = {
/* methods */
(destructor)drw_dealloc, /* tp_dealloc */
(printfunc)0, /* tp_print */
(getattrfunc)lay_getattr, /* tp_getattr */
(setattrfunc)lay_setattr, /* tp_setattr */
(getattrfunc)0, /* tp_getattr */
(setattrfunc)0, /* tp_setattr */
(cmpfunc)drw_cmp, /* tp_compare */
(reprfunc)lay_repr, /* tp_repr */
0, /* tp_as_number */
@ -654,7 +776,7 @@ PyTypeObject PyGimpLayer_Type = {
(iternextfunc)0, /* tp_iternext */
lay_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
lay_getsets, /* tp_getset */
&PyGimpDrawable_Type, /* tp_base */
(PyObject *)0, /* tp_dict */
0, /* tp_descr_get */
@ -709,192 +831,149 @@ chn_get_tattoo(PyGimpChannel *self, PyObject *args)
return PyInt_FromLong(gimp_channel_get_tattoo(self->ID));
}
static struct PyMethodDef chn_methods[] = {
static PyMethodDef chn_methods[] = {
{"copy", (PyCFunction)chn_copy, METH_VARARGS},
{"get_tattoo", (PyCFunction)chn_get_tattoo, METH_VARARGS},
{NULL, NULL} /* sentinel */
};
static PyObject *
chn_getattr(PyGimpChannel *self, char *attr)
chn_get_color(PyGimpChannel *self, void *closure)
{
gint32 id;
if (!strcmp(attr, "__members__"))
return Py_BuildValue("[ssssssssssssssssssssssss]", "ID",
"bpp", "color", "colour", "has_alpha", "height",
"image", "is_color", "is_colour", "is_gray",
"is_grey", "is_indexed", "is_layer_mask",
"is_rgb", "layer", "layer_mask", "mask_bounds",
"name", "offsets", "opacity", "show_masked",
"type", "visible", "width");
if (!strcmp(attr, "ID"))
return PyInt_FromLong(self->ID);
if (!strcmp(attr, "bpp"))
return PyInt_FromLong(gimp_drawable_bpp(self->ID));
if (!strcmp(attr, "color") || !strcmp(attr, "colour")) {
GimpRGB colour;
guchar r, g, b;
GimpRGB colour;
guchar r, g, b;
gimp_channel_get_color(self->ID, &colour);
gimp_rgb_get_uchar(&colour, &r, &g, &b);
return Py_BuildValue("(iii)", (long)r, (long)g, (long)b);
}
if (!strcmp(attr, "has_alpha"))
return PyInt_FromLong(gimp_drawable_has_alpha(self->ID));
if (!strcmp(attr, "height"))
return PyInt_FromLong((long)gimp_drawable_height(self->ID));
if (!strcmp(attr, "image")) {
id = gimp_channel_get_image_id(self->ID);
if (id == -1) {
Py_INCREF(Py_None);
return Py_None;
}
return pygimp_image_new(id);
}
if (!strcmp(attr, "is_color") || !strcmp(attr, "is_colour") ||
!strcmp(attr, "is_rgb"))
return PyInt_FromLong(gimp_drawable_is_rgb(self->ID));
if (!strcmp(attr, "is_gray") || !strcmp(attr, "is_grey"))
return PyInt_FromLong(gimp_drawable_is_gray(self->ID));
if (!strcmp(attr, "is_indexed"))
return PyInt_FromLong(gimp_drawable_is_indexed(self->ID));
if (!strcmp(attr, "layer")) {
/* id = gimp_channel_get_layer_id(self->ID); */
/* It isn't quite clear what that was supposed to achieve, but
the gimp_channel_get_layer_id call no longer exists, which
was breaking everything that tried to load gimpmodule.so.
With no-one apparently maintaing it, the options seem to be:
A) remove this "layer" attribute entirely, as it doesn't
seem to make much sense.
B) Just return the channel ID.
The latter seems more conservative, so that's what I'll do.
-- acapnotic@users.sourceforge.net (08/09/2000) */
id = self->ID;
if (id == -1) {
Py_INCREF(Py_None);
return Py_None;
}
return pygimp_layer_new(id);
}
if (!strcmp(attr, "layer_mask") || !strcmp(attr, "is_layer_mask"))
return PyInt_FromLong(gimp_drawable_is_layer_mask(self->ID));
if (!strcmp(attr, "mask_bounds")) {
gint x1, y1, x2, y2;
gimp_drawable_mask_bounds(self->ID, &x1, &y1, &x2, &y2);
return Py_BuildValue("(iiii)", x1, y1, x2, y2);
}
if (!strcmp(attr, "name"))
return PyString_FromString(gimp_channel_get_name(self->ID));
if (!strcmp(attr, "offsets")) {
gint x, y;
gimp_drawable_offsets(self->ID, &x, &y);
return Py_BuildValue("(ii)", x, y);
}
if (!strcmp(attr, "opacity"))
return PyFloat_FromDouble(gimp_channel_get_opacity(self->ID));
if (!strcmp(attr, "show_masked"))
return PyInt_FromLong(gimp_channel_get_show_masked(self->ID));
if (!strcmp(attr, "type"))
return PyInt_FromLong(gimp_drawable_type(self->ID));
if (!strcmp(attr, "visible"))
return PyInt_FromLong(gimp_channel_get_visible(self->ID));
if (!strcmp(attr, "width"))
return PyInt_FromLong(gimp_drawable_width(self->ID));
{
PyObject *name = PyString_FromString(attr);
PyObject *ret = PyObject_GenericGetAttr((PyObject *)self, name);
Py_DECREF(name);
return ret;
}
gimp_channel_get_color(self->ID, &colour);
gimp_rgb_get_uchar(&colour, &r, &g, &b);
return Py_BuildValue("(iii)", (long)r, (long)g, (long)b);
}
static int
chn_setattr(PyGimpChannel *self, char *attr, PyObject *v)
chn_set_color(PyGimpChannel *self, PyObject *value, void *closure)
{
if (v == NULL) {
PyErr_SetString(PyExc_TypeError, "can not delete attributes.");
return -1;
}
if (!strcmp(attr, "color") || !strcmp(attr, "colour")) {
PyObject *r, *g, *b;
GimpRGB colour;
guchar r, g, b;
GimpRGB colour;
if (!PySequence_Check(v) || PySequence_Length(v) < 3) {
PyErr_SetString(PyExc_TypeError, "type mis-match.");
return -1;
}
r = PySequence_GetItem(v, 0);
g = PySequence_GetItem(v, 1);
b = PySequence_GetItem(v, 2);
if (!PyInt_Check(r) || !PyInt_Check(g) || !PyInt_Check(b)) {
PyErr_SetString(PyExc_TypeError, "type mis-match.");
Py_DECREF(r); Py_DECREF(g); Py_DECREF(b);
return -1;
}
gimp_rgb_set_uchar(&colour, PyInt_AsLong(r),
PyInt_AsLong(g), PyInt_AsLong(b));
Py_DECREF(r); Py_DECREF(g); Py_DECREF(b);
gimp_channel_set_color(self->ID, &colour);
return 0;
if (value == NULL) {
PyErr_SetString(PyExc_TypeError, "can not delete colour.");
return -1;
}
if (!strcmp(attr, "name")) {
if (!PyString_Check(v)) {
PyErr_SetString(PyExc_TypeError, "type mis-match.");
return -1;
}
gimp_channel_set_name(self->ID, PyString_AsString(v));
return 0;
}
if (!strcmp(attr, "opacity")) {
if (!PyFloat_Check(v)) {
PyErr_SetString(PyExc_TypeError, "type mis-match.");
return -1;
}
gimp_channel_set_opacity(self->ID, PyFloat_AsDouble(v));
return 0;
}
/* if (!strcmp(attr, "show_masked")) {
if (!PyInt_Check(v)) {
if (!PyTuple_Check(value) || !PyArg_ParseTuple(value, "(BBB)", &r,&g,&b)) {
PyErr_Clear();
PyErr_SetString(PyExc_TypeError, "type mis-match.");
return -1;
}
gimp_channel_set_show_masked(self->ID, PyInt_AsLong(v));
return 0;
}
*/ if (!strcmp(attr, "visible")) {
if (!PyInt_Check(v)) {
PyErr_SetString(PyExc_TypeError, "type mis-match.");
return -1;
}
gimp_channel_set_visible(self->ID, PyInt_AsLong(v));
return 0;
}
if (!strcmp(attr, "height") || !strcmp(attr, "image") ||
!strcmp(attr, "layer") || !strcmp(attr, "width") ||
!strcmp(attr, "ID") || !strcmp(attr, "bpp") ||
!strcmp(attr, "layer_mask") || !strcmp(attr, "mask_bounds") ||
!strcmp(attr, "offsets") || !strcmp(attr, "type") ||
!strcmp(attr, "has_alpha") || !strcmp(attr, "is_color") ||
!strcmp(attr, "is_colour") || !strcmp(attr, "is_rgb") ||
!strcmp(attr, "is_gray") || !strcmp(attr, "is_grey") ||
!strcmp(attr, "is_indexed") || !strcmp(attr, "is_layer_mask") ||
!strcmp(attr, "__members__")) {
PyErr_SetString(PyExc_TypeError, "read-only attribute.");
gimp_rgb_set_uchar(&colour, r, g, b);
gimp_channel_set_color(self->ID, &colour);
return 0;
}
static PyObject *
chn_get_image(PyGimpChannel *self, void *closure)
{
gint32 id = gimp_channel_get_image_id(self->ID);
if (id == -1) {
Py_INCREF(Py_None);
return Py_None;
}
return pygimp_image_new(id);
}
static PyObject *
chn_get_name(PyGimpChannel *self, void *closure)
{
return PyString_FromString(gimp_channel_get_name(self->ID));
}
static int
chn_set_name(PyGimpChannel *self, PyObject *value, void *closure)
{
if (value == NULL) {
PyErr_SetString(PyExc_TypeError, "can not delete name.");
return -1;
}
if (!PyString_Check(value)) {
PyErr_SetString(PyExc_TypeError, "type mis-match.");
return -1;
}
{
PyObject *name = PyString_FromString(attr);
int ret = PyObject_GenericSetAttr((PyObject *)self, name, v);
Py_DECREF(name);
return ret;
}
gimp_channel_set_name(self->ID, PyString_AsString(value));
return 0;
}
static PyObject *
chn_get_opacity(PyGimpLayer *self, void *closure)
{
return PyFloat_FromDouble(gimp_channel_get_opacity(self->ID));
}
static int
chn_set_opacity(PyGimpLayer *self, PyObject *value, void *closure)
{
if (value == NULL) {
PyErr_SetString(PyExc_TypeError, "can not delete opacity.");
return -1;
}
if (!PyFloat_Check(value)) {
PyErr_SetString(PyExc_TypeError, "type mis-match.");
return -1;
}
gimp_channel_set_opacity(self->ID, PyFloat_AsDouble(value));
return 0;
}
static PyObject *
chn_get_show_masked(PyGimpLayer *self, void *closure)
{
return PyInt_FromLong(gimp_channel_get_show_masked(self->ID));
}
static int
chn_set_show_masked(PyGimpLayer *self, PyObject *value, void *closure)
{
if (value == NULL) {
PyErr_SetString(PyExc_TypeError, "can not delete show_masked.");
return -1;
}
if (!PyInt_Check(value)) {
PyErr_SetString(PyExc_TypeError, "type mis-match.");
return -1;
}
gimp_channel_set_show_masked(self->ID, PyInt_AsLong(value));
return 0;
}
static PyObject *
chn_get_visible(PyGimpLayer *self, void *closure)
{
return PyInt_FromLong(gimp_channel_get_visible(self->ID));
}
static int
chn_set_visible(PyGimpLayer *self, PyObject *value, void *closure)
{
if (value == NULL) {
PyErr_SetString(PyExc_TypeError, "can not delete visible.");
return -1;
}
if (!PyInt_Check(value)) {
PyErr_SetString(PyExc_TypeError, "type mis-match.");
return -1;
}
gimp_channel_set_visible(self->ID, PyInt_AsLong(value));
return 0;
}
static PyGetSetDef chn_getsets[] = {
{ "color", (getter)chn_get_color, (setter)chn_set_color },
{ "colour", (getter)chn_get_color, (setter)chn_set_color },
{ "image", (getter)chn_get_image, (setter)0 },
{ "name", (getter)chn_get_name, (setter)chn_set_name },
{ "opacity", (getter)chn_get_opacity, (setter)chn_set_opacity },
{ "show_masked", (getter)chn_get_show_masked, (setter)chn_set_show_masked},
{ "visible", (getter)chn_get_visible, (setter)chn_set_visible },
{ NULL, (getter)0, (setter)0 }
};
static PyObject *
chn_repr(PyGimpChannel *self)
{
@ -902,7 +981,7 @@ chn_repr(PyGimpChannel *self)
gchar *name;
name = gimp_channel_get_name(self->ID);
s = PyString_FromFormat("<gimp.Channel %s>", name);
s = PyString_FromFormat("<gimp.Channel '%s'>", name);
g_free(name);
return s;
}
@ -940,8 +1019,8 @@ PyTypeObject PyGimpChannel_Type = {
/* methods */
(destructor)drw_dealloc, /* tp_dealloc */
(printfunc)0, /* tp_print */
(getattrfunc)chn_getattr, /* tp_getattr */
(setattrfunc)chn_setattr, /* tp_setattr */
(getattrfunc)0, /* tp_getattr */
(setattrfunc)0, /* tp_setattr */
(cmpfunc)drw_cmp, /* tp_compare */
(reprfunc)chn_repr, /* tp_repr */
0, /* tp_as_number */
@ -963,7 +1042,7 @@ PyTypeObject PyGimpChannel_Type = {
(iternextfunc)0, /* tp_iternext */
chn_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
chn_getsets, /* tp_getset */
&PyGimpDrawable_Type, /* tp_base */
(PyObject *)0, /* tp_dict */
0, /* tp_descr_get */

View File

@ -432,7 +432,7 @@ img_get_guide_position(PyGimpImage *self, PyObject *args)
return PyInt_FromLong(gimp_image_get_guide_position(self->ID, guide));
}
static struct PyMethodDef img_methods[] = {
static PyMethodDef img_methods[] = {
{"add_channel", (PyCFunction)img_add_channel, METH_VARARGS},
{"add_layer", (PyCFunction)img_add_layer, METH_VARARGS},
{"add_layer_mask", (PyCFunction)img_add_layer_mask, METH_VARARGS},
@ -704,7 +704,7 @@ img_set_unit(PyGimpImage *self, PyObject *value, void *closure)
return 0;
}
static struct PyGetSetDef img_getsets[] = {
static PyGetSetDef img_getsets[] = {
{ "ID", (getter)img_get_ID, (setter)0 },
{ "active_channel", (getter)img_get_active_channel,
(setter)img_set_active_channel },
@ -758,7 +758,7 @@ img_repr(PyGimpImage *self)
gchar *name;
name = gimp_image_get_filename(self->ID);
s = PyString_FromFormat("<gimp.image %s>", name?name:"(null)");
s = PyString_FromFormat("<gimp.image '%s'>", name?name:"(null)");
g_free(name);
return s;
}

View File

@ -50,7 +50,7 @@ para_has_flag(PyGimpParasite *self, PyObject *args)
static struct PyMethodDef para_methods[] = {
static PyMethodDef para_methods[] = {
{"copy", (PyCFunction)para_copy, METH_VARARGS},
{"is_type", (PyCFunction)para_is_type, METH_VARARGS},
{"has_flag",(PyCFunction)para_has_flag, METH_VARARGS},
@ -58,6 +58,45 @@ static struct PyMethodDef para_methods[] = {
{NULL, NULL} /* sentinel */
};
static PyObject *
para_get_is_persistent(PyGimpParasite *self, void *closure)
{
return PyInt_FromLong(gimp_parasite_is_persistent(self->para));
}
static PyObject *
para_get_is_undoable(PyGimpParasite *self, void *closure)
{
return PyInt_FromLong(gimp_parasite_is_undoable(self->para));
}
static PyObject *
para_get_flags(PyGimpParasite *self, void *closure)
{
return PyInt_FromLong(gimp_parasite_flags(self->para));
}
static PyObject *
para_get_name(PyGimpParasite *self, void *closure)
{
return PyString_FromString(gimp_parasite_name(self->para));
}
static PyObject *
para_get_data(PyGimpParasite *self, void *closure)
{
return PyString_FromStringAndSize(gimp_parasite_data(self->para),
gimp_parasite_data_size(self->para));
}
static PyGetSetDef para_getsets[] = {
{ "is_persistent", (getter)para_get_is_persistent, (setter)0 },
{ "is_undoable", (getter)para_get_is_undoable, (setter)0 },
{ "flags", (getter)para_get_flags, (setter)0 },
{ "name", (getter)para_get_name, (setter)0 },
{ "data", (getter)para_get_data, (setter)0 },
{ NULL, (getter)0, (setter)0 },
};
static void
para_dealloc(PyGimpParasite *self)
@ -66,33 +105,6 @@ para_dealloc(PyGimpParasite *self)
PyObject_DEL(self);
}
static PyObject *
para_getattr(PyGimpParasite *self, char *attr)
{
if (!strcmp(attr, "__members__")) {
return Py_BuildValue("[sssss]", "data", "flags", "is_persistent",
"is_undoable", "name");
}
if (!strcmp(attr, "is_persistent"))
return PyInt_FromLong(gimp_parasite_is_persistent(self->para));
if (!strcmp(attr, "is_undoable"))
return PyInt_FromLong(gimp_parasite_is_undoable(self->para));
if (!strcmp(attr, "flags"))
return PyInt_FromLong(gimp_parasite_flags(self->para));
if (!strcmp(attr, "name"))
return PyString_FromString(gimp_parasite_name(self->para));
if (!strcmp(attr, "data"))
return PyString_FromStringAndSize(gimp_parasite_data(self->para),
gimp_parasite_data_size(self->para));
{
PyObject *name = PyString_FromString(attr);
PyObject *ret = PyObject_GenericGetAttr((PyObject *)self, name);
Py_DECREF(name);
return ret;
}
}
static PyObject *
para_repr(PyGimpParasite *self)
{
@ -109,6 +121,24 @@ para_str(PyGimpParasite *self)
gimp_parasite_data_size(self->para));
}
static int
para_init(PyGimpParasite *self, PyObject *args, PyObject *kwargs)
{
char *name, *data;
int flags, size;
if (!PyArg_ParseTuple(args, "sis#:gimp.Parasite.__init__", &name, &flags,
&data, &size))
return -1;
self->para = gimp_parasite_new(name, flags, size, data);
if (!self->para) {
PyErr_SetString(pygimp_error, "could not create parasite");
return -1;
}
return 0;
}
PyTypeObject PyGimpParasite_Type = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
@ -141,13 +171,13 @@ PyTypeObject PyGimpParasite_Type = {
(iternextfunc)0, /* tp_iternext */
para_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
para_getsets, /* tp_getset */
(PyTypeObject *)0, /* tp_base */
(PyObject *)0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
(initproc)0, /* tp_init */
(initproc)para_init, /* tp_init */
(allocfunc)0, /* tp_alloc */
(newfunc)0, /* tp_new */
};

View File

@ -548,7 +548,7 @@ pdb_query(PyGimpPDB *self, PyObject *args)
return ret;
}
static struct PyMethodDef pdb_methods[] = {
static PyMethodDef pdb_methods[] = {
{"query", (PyCFunction)pdb_query, METH_VARARGS},
{NULL, NULL} /* sentinel */
};
@ -752,7 +752,7 @@ static struct PyMemberDef pf_members[] = {
static PyObject *
pf_repr(PyGimpPDBFunction *self)
{
return PyString_FromFormat("<pdb function %s>",
return PyString_FromFormat("<pdb function '%s'>",
PyString_AsString(self->proc_name));
}

View File

@ -37,7 +37,7 @@ tile_flush(PyGimpTile *self, PyObject *args)
}
static struct PyMethodDef tile_methods[] = {
static PyMethodDef tile_methods[] = {
{"flush", (PyCFunction)tile_flush, METH_VARARGS},
{NULL, NULL} /* sentinel */
};
@ -124,9 +124,9 @@ tile_repr(PyGimpTile *self)
name = gimp_drawable_name(self->tile->drawable->drawable_id);
if (self->tile->shadow)
s = PyString_FromFormat("<gimp.Tile for drawable %s (shadow)>", name);
s = PyString_FromFormat("<gimp.Tile for drawable '%s' (shadow)>",name);
else
s = PyString_FromFormat("<gimp.Tile for drawable %s>", name);
s = PyString_FromFormat("<gimp.Tile for drawable '%s'>", name);
g_free(name);
return s;
}
@ -279,7 +279,7 @@ pr_resize(PyGimpPixelRgn *self, PyObject *args)
static struct PyMethodDef pr_methods[] = {
static PyMethodDef pr_methods[] = {
{"resize", (PyCFunction)pr_resize, METH_VARARGS},
{NULL, NULL} /* sentinel */
@ -606,7 +606,7 @@ pr_repr(PyGimpPixelRgn *self)
gchar *name;
name = gimp_drawable_name(self->drawable->drawable->drawable_id);
s = PyString_FromFormat("<gimp.PixelRgn for drawable %s>", name);
s = PyString_FromFormat("<gimp.PixelRgn for drawable '%s'>", name);
g_free(name);
return s;
}