[gimp] Bug 670897: Phython-fu does not return parent layer...



commit c2f68b59a3f3097df185d42b9337c09e6f73decf
Author: Massimo Valentini <mvalentini src gnome org>
Date:   Tue Feb 28 18:20:10 2012 +0100

    Bug 670897: Phython-fu does not return parent layer...
    
    (pdb.gimp_item_get_parent(item))
    
    Adjust param conversions when wrapping pdb functions
    and implement 'children' and 'parent' getter for
    GimpItem Python Object.

 plug-ins/pygimp/pygimp-item.c |   30 ++++++++++++++++++++++++++++--
 plug-ins/pygimp/pygimp-pdb.c  |    6 +++++-
 2 files changed, 33 insertions(+), 3 deletions(-)
---
diff --git a/plug-ins/pygimp/pygimp-item.c b/plug-ins/pygimp/pygimp-item.c
index f698638..d6eaaa2 100644
--- a/plug-ins/pygimp/pygimp-item.c
+++ b/plug-ins/pygimp/pygimp-item.c
@@ -48,12 +48,38 @@ static PyMethodDef item_methods[] = {
 static PyObject *
 item_get_parent(PyGimpLayer *self, void *closure)
 {
-    /*  Not implemented yet */
-    return NULL;
+    gint32 id = gimp_item_get_parent(self->ID);
+
+    if (id == -1) {
+	Py_INCREF(Py_None);
+	return Py_None;
+    }
+
+    return pygimp_item_new(id);
+}
+
+static PyObject *
+item_get_children(PyGimpLayer *self, void *closure)
+{
+    gint32 *children;
+    gint n_children, i;
+    PyObject *ret;
+
+    children = gimp_item_get_children(self->ID, &n_children);
+
+    ret = PyList_New(n_children);
+
+    for (i = 0; i < n_children; i++)
+	PyList_SetItem(ret, i, pygimp_item_new(children[i]));
+
+    g_free(children);
+
+    return ret;
 }
 
 static PyGetSetDef item_getsets[] = {
     { "parent", (getter)item_get_parent, (setter)0 },
+    { "children", (getter) item_get_children, (setter)0 },
     { NULL, (getter)0, (setter)0 }
 };
 
diff --git a/plug-ins/pygimp/pygimp-pdb.c b/plug-ins/pygimp/pygimp-pdb.c
index ecd4208..cdf5299 100644
--- a/plug-ins/pygimp/pygimp-pdb.c
+++ b/plug-ins/pygimp/pygimp-pdb.c
@@ -291,7 +291,7 @@ pygimp_param_to_tuple(int nparams, const GimpParam *params)
 	    value = pygimp_channel_new(params[i].data.d_channel);
 	    break;
 	case GIMP_PDB_ITEM:
-	    value = PyInt_FromLong(params[i].data.d_item);
+	    value = pygimp_item_new(params[i].data.d_item);
 	    break;
 	case GIMP_PDB_DRAWABLE:
 	    value = pygimp_drawable_new(NULL, params[i].data.d_drawable);
@@ -590,6 +590,10 @@ pygimp_param_from_tuple(PyObject *args, const GimpParamDef *ptype, int nparams)
 	    }
 	    break;
 	case GIMP_PDB_VECTORS:
+	    if (item == Py_None) {
+		ret[i].data.d_vectors = -1;
+		break;
+	    }
 	    check(!pygimp_vectors_check(item));
 	    ret[i].data.d_vectors = ((PyGimpVectors *)item)->ID;
 	    break;



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