pygimp: add public Item.from_id method

Allows the integer IDs returned by the PDB to be promoted to Python
objects. This removes a release blocking factor for pygimp and also
sets base for refactoring pygimp object methods into
pure Python.
This commit is contained in:
João S. O. Bueno 2011-05-16 10:10:41 -04:00
parent 3de6cc5f74
commit 84dcf6281e
2 changed files with 19 additions and 7 deletions

View File

@ -30,8 +30,18 @@
#include <glib-object.h>
PyObject *
item_from_id(PyObject *not_used, PyObject *args)
{
gint32 ID;
if (!PyArg_ParseTuple(args, "i", &ID))
return NULL;
return pygimp_item_new(ID);
}
static PyMethodDef item_methods[] = {
{"from_id", (PyCFunction)item_from_id, METH_VARARGS | METH_STATIC},
{NULL, NULL} /* sentinel */
};
@ -59,7 +69,7 @@ item_repr(PyGimpItem *self)
{
PyObject *s;
s = PyString_FromFormat("<gimp.Item '%s'>", self->ID);
s = PyString_FromFormat("<gimp.Item '%d'>", self->ID);
return s;
}
@ -119,19 +129,21 @@ PyTypeObject PyGimpItem_Type = {
PyObject *
pygimp_item_new(gint32 ID)
{
PyGimpItem *self;
PyObject *self;
if (!gimp_item_is_valid(ID)) {
Py_INCREF(Py_None);
return Py_None;
}
self = PyObject_NEW(PyGimpItem, &PyGimpItem_Type);
/* create the appropriate object type */
if (gimp_item_is_drawable(ID))
self = pygimp_drawable_new(NULL, ID);
else /* Vectors */
self = pygimp_vectors_new(ID);
if (self == NULL)
return NULL;
self->ID = ID;
return (PyObject *)self;
return self;
}

View File

@ -969,7 +969,7 @@ PyTypeObject PyGimpVectors_Type = {
vectors_methods, /* tp_methods */
0, /* tp_members */
vectors_getsets, /* tp_getset */
&PyGimpItem_Type, /* tp_base */
&PyGimpItem_Type, /* tp_base */
(PyObject *)0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */