mirror of https://github.com/GNOME/gimp.git
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:
parent
3de6cc5f74
commit
84dcf6281e
|
@ -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;
|
||||
}
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in New Issue