wrap gimp_vectors_stroke_new_from_points in the form of a

2006-10-27  Manish Singh  <yosh@gimp.org>

        * plug-ins/pygimp/pygimp-vectors.c: wrap
        gimp_vectors_stroke_new_from_points in the form of a
        VectorsBezierStroke constructor.

        * plug-ins/pygimp/gimpmodule.c: wrap gimp_vectors_new_from_file
        and gimp_vectors_new_from_string.

        * plug-ins/pygimp/pygimp-pdb.c: PDB_VECTORS should be translated
        into Vectors objects.
This commit is contained in:
Manish Singh 2006-10-27 07:17:13 +00:00 committed by Manish Singh
parent ce957a3cc4
commit 7d014b4ae2
4 changed files with 179 additions and 10 deletions

View file

@ -1,3 +1,15 @@
2006-10-27 Manish Singh <yosh@gimp.org>
* plug-ins/pygimp/pygimp-vectors.c: wrap
gimp_vectors_stroke_new_from_points in the form of a
VectorsBezierStroke constructor.
* plug-ins/pygimp/gimpmodule.c: wrap gimp_vectors_new_from_file
and gimp_vectors_new_from_string.
* plug-ins/pygimp/pygimp-pdb.c: PDB_VECTORS should be translated
into Vectors objects.
2006-10-26 Kevin Cozens <kcozens@cvs.gnome.org>
* plug-ins/script-fu/scripts/script-fu-compat.init: Return empty

View file

@ -1450,6 +1450,110 @@ pygimp_fonts_get_list(PyObject *self, PyObject *args, PyObject *kwargs)
return ret;
}
static PyObject *
vectors_to_objects(int num_vectors, int *vectors)
{
PyObject *ret;
int i;
ret = PyList_New(num_vectors);
if (ret == NULL)
goto done;
for (i = 0; i < num_vectors; i++)
PyList_SetItem(ret, i, pygimp_vectors_new(vectors[i]));
done:
g_free(vectors);
return ret;
}
static PyObject *
pygimp_vectors_new_from_file(PyObject *self, PyObject *args, PyObject *kwargs)
{
PyGimpImage *img;
PyObject *py_file;
gboolean merge = FALSE, scale = FALSE;
int *vectors, num_vectors;
static char *kwlist[] = { "image", "svg_file", "merge", "scale", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O!O|ii:vectors_new_from_file", kwlist,
&PyGimpImage_Type, &img, &py_file,
&merge, &scale))
return NULL;
if (PyString_Check(py_file)) {
vectors = gimp_vectors_new_from_file(img->ID,
PyString_AsString(py_file),
merge, scale, &num_vectors);
} else {
PyObject *chunk_size = PyInt_FromLong(16 * 1024);
PyObject *buffer = PyString_FromString("");
PyObject *read_method = PyString_FromString("read");
while (1) {
PyObject *chunk;
chunk = PyObject_CallMethodObjArgs(py_file, read_method,
chunk_size, NULL);
if (!chunk || !PyString_Check(chunk)) {
Py_XDECREF(chunk);
Py_DECREF(chunk_size);
Py_DECREF(buffer);
Py_DECREF(read_method);
return NULL;
}
if (PyString_GET_SIZE(chunk) != 0) {
PyObject *newbuffer;
PyString_ConcatAndDel(&newbuffer, chunk);
Py_DECREF(buffer);
buffer = newbuffer;
} else {
Py_DECREF(chunk);
break;
}
}
vectors = gimp_vectors_new_from_string(img->ID,
PyString_AsString(buffer),
PyString_Size(buffer),
merge, scale, &num_vectors);
Py_DECREF(chunk_size);
Py_DECREF(buffer);
Py_DECREF(read_method);
}
return vectors_to_objects(num_vectors, vectors);
}
static PyObject *
pygimp_vectors_new_from_string(PyObject *self, PyObject *args, PyObject *kwargs)
{
PyGimpImage *img;
const char *svg_string;
int length;
gboolean merge = FALSE, scale = FALSE;
int *vectors, num_vectors;
static char *kwlist[] = { "image", "svg_string", "merge", "scale", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O!s#|ii:vectors_new_from_file", kwlist,
&PyGimpImage_Type, &img,
&svg_string, &length,
&merge, &scale))
return NULL;
vectors = gimp_vectors_new_from_string(img->ID, svg_string, length,
merge, scale, &num_vectors);
return vectors_to_objects(num_vectors, vectors);
}
static PyObject *
id2image(PyObject *self, PyObject *args)
{
@ -1576,6 +1680,8 @@ static struct PyMethodDef gimp_methods[] = {
{"fonts_refresh", (PyCFunction)pygimp_fonts_refresh, METH_NOARGS},
{"fonts_get_list", (PyCFunction)pygimp_fonts_get_list, METH_VARARGS | METH_KEYWORDS},
{"checks_get_shades", (PyCFunction)pygimp_checks_get_shades, METH_VARARGS | METH_KEYWORDS},
{"vectors_new_from_file", (PyCFunction)pygimp_vectors_new_from_file, METH_VARARGS | METH_KEYWORDS},
{"vectors_new_from_string", (PyCFunction)pygimp_vectors_new_from_string, METH_VARARGS | METH_KEYWORDS},
{"_id2image", (PyCFunction)id2image, METH_VARARGS},
{"_id2drawable", (PyCFunction)id2drawable, METH_VARARGS},
{"_id2display", (PyCFunction)id2display, METH_VARARGS},

View file

@ -291,7 +291,7 @@ pygimp_param_to_tuple(int nparams, const GimpParam *params)
value = PyInt_FromLong(params[i].data.d_boundary);
break;
case GIMP_PDB_VECTORS:
value = PyInt_FromLong(params[i].data.d_vectors);
value = pygimp_vectors_new(params[i].data.d_vectors);
break;
case GIMP_PDB_PARASITE:
value = pygimp_parasite_new(gimp_parasite_copy(
@ -488,7 +488,7 @@ pygimp_param_from_tuple(PyObject *args, const GimpParamDef *ptype, int nparams)
break;
case GIMP_PDB_DISPLAY:
check(!pygimp_display_check(item));
ret[i].data.d_display=((PyGimpDisplay *)item)->ID;
ret[i].data.d_display = ((PyGimpDisplay *)item)->ID;
break;
case GIMP_PDB_IMAGE:
if (item == Py_None) {
@ -496,7 +496,7 @@ pygimp_param_from_tuple(PyObject *args, const GimpParamDef *ptype, int nparams)
break;
}
check(!pygimp_image_check(item));
ret[i].data.d_image=((PyGimpImage *)item)->ID;
ret[i].data.d_image = ((PyGimpImage *)item)->ID;
break;
case GIMP_PDB_LAYER:
if (item == Py_None) {
@ -504,7 +504,7 @@ pygimp_param_from_tuple(PyObject *args, const GimpParamDef *ptype, int nparams)
break;
}
check(!pygimp_layer_check(item));
ret[i].data.d_layer=((PyGimpLayer *)item)->ID;
ret[i].data.d_layer = ((PyGimpLayer *)item)->ID;
break;
case GIMP_PDB_CHANNEL:
if (item == Py_None) {
@ -512,7 +512,7 @@ pygimp_param_from_tuple(PyObject *args, const GimpParamDef *ptype, int nparams)
break;
}
check(!pygimp_channel_check(item));
ret[i].data.d_channel=((PyGimpChannel *)item)->ID;
ret[i].data.d_channel = ((PyGimpChannel *)item)->ID;
break;
case GIMP_PDB_DRAWABLE:
if (item == Py_None) {
@ -520,19 +520,19 @@ pygimp_param_from_tuple(PyObject *args, const GimpParamDef *ptype, int nparams)
break;
}
check(!pygimp_drawable_check(item));
ret[i].data.d_channel=((PyGimpDrawable *)item)->ID;
ret[i].data.d_channel = ((PyGimpDrawable *)item)->ID;
break;
case GIMP_PDB_SELECTION:
check(!pygimp_layer_check(item));
ret[i].data.d_selection=((PyGimpLayer *)item)->ID;
ret[i].data.d_selection = ((PyGimpLayer *)item)->ID;
break;
case GIMP_PDB_BOUNDARY:
check(!PyInt_Check(item));
ret[i].data.d_boundary = PyInt_AsLong(item);
break;
case GIMP_PDB_VECTORS:
check(!PyInt_Check(item));
ret[i].data.d_vectors = PyInt_AsLong(item);
check(!pygimp_vectors_check(item));
ret[i].data.d_vectors = ((PyGimpVectors *)item)->ID;
break;
case GIMP_PDB_PARASITE:
/* can't do anything, since size of GimpParasite is not known */

View file

@ -375,6 +375,57 @@ vbs_repr(PyGimpVectorsStroke *self)
return s;
}
static int
vbs_init(PyGimpVectorsStroke *self, PyObject *args, PyObject *kwargs)
{
PyGimpVectors *vectors;
double *controlpoints;
gboolean closed = FALSE;
PyObject *py_controlpoints, *item;
int i, num_points;
static char *kwlist[] = { "vectors", "controlpoints", "closed", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O!O|i:gimp.Vectors.__init__",
kwlist,
&PyGimpVectors_Type, &vectors,
&py_controlpoints, &closed));
return -1;
if (!PySequence_Check(py_controlpoints)) {
PyErr_SetString(PyExc_TypeError,
"controlpoints must be a sequence");
return -1;
}
num_points = PySequence_Length(py_controlpoints);
controlpoints = g_new(gdouble, num_points);
for (i = 0; i < num_points; i++) {
item = PySequence_GetItem(py_controlpoints, i);
if (!PyFloat_Check(item)) {
PyErr_SetString(PyExc_TypeError,
"controlpoints must be a sequence of floats");
g_free(controlpoints);
return -1;
}
controlpoints[i] = PyFloat_AsDouble(item);
}
self->vectors_ID = vectors->ID;
self->stroke =
gimp_vectors_stroke_new_from_points(self->vectors_ID,
GIMP_VECTORS_STROKE_TYPE_BEZIER,
num_points, controlpoints, closed);
g_free(controlpoints);
return 0;
}
PyTypeObject PyGimpVectorsBezierStroke_Type = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
@ -413,7 +464,7 @@ PyTypeObject PyGimpVectorsBezierStroke_Type = {
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
(initproc)0, /* tp_init */
(initproc)vbs_init, /* tp_init */
(allocfunc)0, /* tp_alloc */
(newfunc)0, /* tp_new */
};