gimp r24595 - in trunk: . plug-ins/pygimp



Author: yosh
Date: Thu Jan 10 23:39:49 2008
New Revision: 24595
URL: http://svn.gnome.org/viewvc/gimp?rev=24595&view=rev

Log:
2008-01-10  Manish Singh  <yosh gimp org>

        * plug-ins/pygimp/pygimp-pdb.c (pdb_getattro): Handle __members__
        specially to return the current PDB procedure list, and pass-through
        any attributes that start with "_" without looking them up in the
        PDB.


Modified:
   trunk/ChangeLog
   trunk/plug-ins/pygimp/pygimp-pdb.c

Modified: trunk/plug-ins/pygimp/pygimp-pdb.c
==============================================================================
--- trunk/plug-ins/pygimp/pygimp-pdb.c	(original)
+++ trunk/plug-ins/pygimp/pygimp-pdb.c	Thu Jan 10 23:39:49 2008
@@ -638,18 +638,59 @@
 /* -------------------------------------------------------- */
 
 static PyObject *
+build_procedure_list(void)
+{
+    int num, i;
+    char **names, *name, *p;
+    PyObject *ret;
+
+    gimp_procedural_db_query(".*", ".*", ".*", ".*", ".*", ".*", ".*",
+                             &num, &names);
+
+    ret = PyList_New(num);
+
+    for (i = 0; i < num; i++) {
+        name = g_strdup(names[i]);
+        for (p = name; *p != '\0'; p++) {
+            if (*p == '-')
+                *p = '_';
+	}
+        PyList_SetItem(ret, i, PyString_FromString(name));
+        g_free(name);
+    }
+
+    g_free(names);
+
+    return ret;
+}
+
+static PyObject *
 pdb_getattro(PyGimpPDB *self, PyObject *attr)
 {
+    char *attr_name;
     PyObject *ret;
 
-    ret = PyObject_GenericGetAttr((PyObject *)self, attr);
+    attr_name = PyString_AsString(attr);
+    if (!attr_name) {
+         PyErr_Clear();
+         return PyObject_GenericGetAttr((PyObject *)self, attr);
+    }
 
+    if (attr_name[0] == '_') {
+        if (strcmp(attr_name, "__members__")) {
+            return build_procedure_list();
+        } else {
+            return PyObject_GenericGetAttr((PyObject *)self, attr);
+        }
+    }
+
+    ret = PyObject_GenericGetAttr((PyObject *)self, attr);
     if (ret)
-	return ret;
+        return ret;
 
     PyErr_Clear();
 
-    return pygimp_pdb_function_new_from_proc_db(PyString_AsString(attr));
+    return pygimp_pdb_function_new_from_proc_db(attr_name);
 }
 
 PyTypeObject PyGimpPDB_Type = {



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