[gimp] pygimp: add public Item.from_id method



commit 84dcf6281e76721d1ec6bc12964c8c2cca623aee
Author: João S. O. Bueno <gwidion gmail com>
Date:   Mon May 16 10:10:41 2011 -0400

    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.

 plug-ins/pygimp/pygimp-item.c    |   24 ++++++++++++++++++------
 plug-ins/pygimp/pygimp-vectors.c |    2 +-
 2 files changed, 19 insertions(+), 7 deletions(-)
---
diff --git a/plug-ins/pygimp/pygimp-item.c b/plug-ins/pygimp/pygimp-item.c
index 9a41d35..7a87114 100644
--- a/plug-ins/pygimp/pygimp-item.c
+++ b/plug-ins/pygimp/pygimp-item.c
@@ -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;
 }
\ No newline at end of file
diff --git a/plug-ins/pygimp/pygimp-vectors.c b/plug-ins/pygimp/pygimp-vectors.c
index c1558aa..fa83ab6 100644
--- a/plug-ins/pygimp/pygimp-vectors.c
+++ b/plug-ins/pygimp/pygimp-vectors.c
@@ -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 */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]