gimp r25821 - in branches/soc-2008-python: . plug-ins/pygimp



Author: larsc
Date: Mon May 26 21:51:54 2008
New Revision: 25821
URL: http://svn.gnome.org/viewvc/gimp?rev=25821&view=rev

Log:
2008-05-26  Lars-Peter Clausen  <lars metafoo de>

	* plug-ins/pygimp/gimpenumsmodule.c: Use GEnum objects rather then
	integer values for enums
	* plug-ins/pygimp/ pygimp-pdb.c:
	Added docstrings for the properties of a GimpPDBFunction object.
	(pygimp_pdb_function_new): Set the docstring of a GimpPDBFunction
	object to proc_help.
	When gimpenums is available set the type of the arguments to a
	GimpPDBArgType enum instead of a integer value.
	(pdb_getattro): Fix a bug where a pdb object returned a list of all pdb
	functions instead of the actual value for all properties starting with
	a underscore.

Modified:
   branches/soc-2008-python/ChangeLog
   branches/soc-2008-python/plug-ins/pygimp/gimpenumsmodule.c
   branches/soc-2008-python/plug-ins/pygimp/pygimp-pdb.c

Modified: branches/soc-2008-python/plug-ins/pygimp/gimpenumsmodule.c
==============================================================================
--- branches/soc-2008-python/plug-ins/pygimp/gimpenumsmodule.c	(original)
+++ branches/soc-2008-python/plug-ins/pygimp/gimpenumsmodule.c	Mon May 26 21:51:54 2008
@@ -100,7 +100,7 @@
     pyg_enum_add_constants(m, GIMP_TYPE_CHECK_TYPE, "GIMP_");
 
     for (i = 0; i < num_names; i++)
-	pyg_enum_add_constants(m, g_type_from_name(names[i]), "GIMP_");
+	pyg_enum_add(m, names[i], "GIMP_", g_type_from_name(names[i]));
 }
 
 

Modified: branches/soc-2008-python/plug-ins/pygimp/pygimp-pdb.c
==============================================================================
--- branches/soc-2008-python/plug-ins/pygimp/pygimp-pdb.c	(original)
+++ branches/soc-2008-python/plug-ins/pygimp/pygimp-pdb.c	Mon May 26 21:51:54 2008
@@ -677,7 +677,7 @@
     }
 
     if (attr_name[0] == '_') {
-        if (strcmp(attr_name, "__members__")) {
+        if (strcmp(attr_name, "__members__") == 0) {
             return build_procedure_list();
         } else {
             return PyObject_GenericGetAttr((PyObject *)self, attr);
@@ -785,17 +785,36 @@
 
 #define OFF(x) offsetof(PyGimpPDBFunction, x)
 static struct PyMemberDef pf_members[] = {
-    {"proc_name",      T_OBJECT, OFF(proc_name),      RO},
-    {"proc_blurb",     T_OBJECT, OFF(proc_blurb),     RO},
-    {"proc_help",      T_OBJECT, OFF(proc_help),      RO},
-    {"proc_author",    T_OBJECT, OFF(proc_author),    RO},
-    {"proc_copyright", T_OBJECT, OFF(proc_copyright), RO},
-    {"proc_date",      T_OBJECT, OFF(proc_date),      RO},
-    {"proc_type",      T_OBJECT, OFF(proc_type),      RO},
-    {"nparams",        T_INT,    OFF(nparams),        RO},
-    {"nreturn_vals",   T_INT,    OFF(nreturn_vals),   RO},
-    {"params",         T_OBJECT, OFF(py_params),      RO},
-    {"return_vals",    T_OBJECT, OFF(py_return_vals), RO},
+    {"proc_name",      T_OBJECT, OFF(proc_name),      RO,
+     "The name of the procedure."},
+    {"proc_blurb",     T_OBJECT, OFF(proc_blurb),     RO,
+     "A short piece of information about the procedure."},
+    {"proc_help",      T_OBJECT, OFF(proc_help),      RO,
+     "More detailed information about the procedure."},
+    {"proc_author",    T_OBJECT, OFF(proc_author),    RO,
+     "The author of the procedure."},
+    {"proc_copyright", T_OBJECT, OFF(proc_copyright), RO,
+     "The copyright holder for the procedure (usually the same as the author)."},
+    {"proc_date",      T_OBJECT, OFF(proc_date),      RO,
+     "The date when the procedure was written."},
+    {"proc_type",      T_OBJECT, OFF(proc_type),      RO,
+     "The type of procedure. This will be one of PROC_PLUG_IN, "\
+     "PROC_EXTENSION or PROC_TEMPORARY."},
+    {"nparams",        T_INT,    OFF(nparams),        RO,
+     "The number of parameters the procedure takes."},
+    {"nreturn_vals",   T_INT,    OFF(nreturn_vals),   RO,
+     "The number of return values the procedure gives."},
+    {"params",         T_OBJECT, OFF(py_params),      RO,
+     "A description of parameters of the procedure. It takes the form of a "\
+     "tuple of 3-tuples, where each 3-tuple describes a parameter. The items "\
+     "in the 3-tuple are a parameter type (one of the GimpPDBArgType constants), a "\
+     "name for the parameter, and a description of the parameter. "},
+    {"return_vals",    T_OBJECT, OFF(py_return_vals), RO,
+     "A description of return values of the procedure. It takes the form of a "\
+     "tuple of 3-tuples, where each 3-tuple describes a return value. The "\
+     "items in the 3-tuple are a return value type (one of the GimpPDBArgType "\
+     "constants), a name for the return value, and a description of the "\
+     "return value. "},
     {NULL}  /* Sentinel */
 };
 #undef OFF
@@ -991,6 +1010,66 @@
     (newfunc)0,				/* tp_new */
 };
 
+/*
+ * pygim_pdb_build_param_info_tuple:
+ * @n_params: Number of elements in @params.
+ * @params:   A array of GimpParamDef for which a description is created.
+ *
+ * Creates a  tuple with of 3-tuples in the form of (type, name, description)
+ * describing the passed pdb parameter definitions. When gimpenums is
+ * available type is a gimpenums.GimpPDBArgType else a integer, name and
+ * description are strings.
+ *
+ * Return value: A python tuple with @n_params elements of 3-tuples
+ *               describing @params or NULL if an error accured.
+ */
+static PyObject *
+pygimp_pdb_build_param_info_tuple(int n_params, GimpParamDef *params)
+{
+    PyObject *result;
+    PyObject *gimpenums;
+    PyObject *pdb_arg_type;
+    int i;
+    PyObject *arglist;
+    PyObject* type;
+
+    result = PyTuple_New(n_params);
+    
+    gimpenums = PyImport_ImportModule("gimpenums");
+
+    if(gimpenums == NULL ||
+       (pdb_arg_type = PyObject_GetAttrString(gimpenums, "GimpPDBArgType")) == NULL) {
+        PyErr_Clear();
+        for(i = 0; i < n_params; ++i)
+        PyTuple_SetItem(result, i,
+                Py_BuildValue("(iss)",
+                          params[i].type,
+                          params[i].name,
+                          params[i].description));
+    } else {
+        for(i = 0; i < n_params; ++i) {
+            if(!(arglist = Py_BuildValue("(i)", params[i].type))) break;
+            if(!(type = PyEval_CallObject(pdb_arg_type, arglist))) break;
+            PyTuple_SetItem(result, i,
+                    Py_BuildValue("(Oss)",
+                              type,
+                              params[i].name,
+                              params[i].description));
+            Py_DECREF(type);
+            Py_DECREF(arglist);
+        }
+        
+        if(i != n_params) {
+            Py_XDECREF(arglist);
+            Py_DECREF(result);
+            result = NULL;
+        }
+        Py_DECREF(pdb_arg_type);
+        Py_DECREF(gimpenums);
+    }
+    return result;
+}
+
 PyObject *
 pygimp_pdb_function_new(const char *name, const char *blurb, const char *help,
 			const char *author, const char *copyright,
@@ -999,7 +1078,6 @@
 			GimpParamDef *params, GimpParamDef *return_vals)
 {
     PyGimpPDBFunction *self;
-    int i;
 
     self = PyObject_NEW(PyGimpPDBFunction, &PyGimpPDBFunction_Type);
 
@@ -1018,22 +1096,10 @@
     self->nreturn_vals = n_return_vals;
     self->params = params;
     self->return_vals = return_vals;
+    PyDict_SetItemString(self->ob_type->tp_dict, "__doc__", PyString_FromString(help ? help : ""));
 
-    self->py_params = PyTuple_New(n_params);
-    for (i = 0; i < n_params; i++)
-	PyTuple_SetItem(self->py_params, i,
-			Py_BuildValue("(iss)",
-				      params[i].type,
-				      params[i].name,
-				      params[i].description));
-
-    self->py_return_vals = PyTuple_New(n_return_vals);
-    for (i = 0; i < n_return_vals; i++)
-	PyTuple_SetItem(self->py_return_vals, i,
-			Py_BuildValue("(iss)",
-				      return_vals[i].type,
-				      return_vals[i].name,
-				      return_vals[i].description));
+    self->py_params = pygimp_pdb_build_param_info_tuple(n_params, params);
+    self->py_return_vals = pygimp_pdb_build_param_info_tuple(n_return_vals, return_vals);
 
     return (PyObject *)self;
 }



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