>>> pdb.gimp_file_load.nparams
3
>>> pprint.pprint(pdb.gimp_file_load.params)
((0,
'run-mode',
'The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }'),
(4, 'filename', 'The name of the file to load'),
(4, 'raw-filename', 'The name as entered by the user'))
>>> fname = 'a filename'
>>> img = pdb.gimp_file_load(gimpfu.RUN_NONINTERACTIVE, fname, fname)
Traceback (most recent call last):
File "<input>", line 1, in <module>
TypeError: wrong number of parameters
So, what am I doing wrong here? According to the method itself, it takes three rather-well documented arguments. I pass it the three things it wants, and I receive a TypeError. So:
In the tuples for the arguments, there's a 0, a 4, and a 4. What are these magic constants? According to the docs, these appear to be:
a parameter type (one of the PARAM_* constants)
But nowhere in those docs do I find PARAM_ constants, and I've not found them introspecting any of pdb, gimp or gimpfu.
Just to be complete: the obvious, help(pdb.gimp_file_load), isn't really that helpful:
>>> help(pdb.gimp_file_load)
Help on PDBFunction object:
class PDBFunction(__builtin__.object)
| Methods defined here:
|
| __call__(...)
| x.__call__(...) <==> x(...)
|
| __repr__(...)
| x.__repr__() <==> repr(x)
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| nparams
|
| nreturn_vals
|
| params
|
| proc_author
|
| proc_blurb
|
| proc_copyright
|
| proc_date
|
| proc_help
|
| proc_name
|
| proc_type
|
| return_vals
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __new__ = <built-in method __new__ of type object>
| T.__new__(S, ...) -> a new object with type S, a subtype of T
This seems to be a bit of leakiness in the abstraction between GIMP's "Procedure database" and the Python wrapper around it. run_mode, AFAICT, is a special child, and is an optional, keyword-only param. E.g., this works:
>>> img = pdb.gimp_file_load(fname, fname, run_mode=gimpfu.RUN_NONINTERACTIVE)
>>> img
<gimp.Image 'fname.xcf'>
As this source says:
Procedure Browser to Python:
- Change dashes to underscores
- Omit any run-mode parameter
- Change -1 to None
(emphasis mine); you don't really need to omit it, it just has to be a keyword arg. (As my example shows.) Keyword args must follow non-keyword args in Python. You can also leave it off, and I'm guess it assumes some sort of default. (I don't know which though.)
Presumably, the "PARAM_" constants I was curious about in the question reveal this, except I can't find in docs or introspection the symbolic/named versions of the integers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With