Thanatos
Thanatos

Reputation: 44334

How do you call gimp_file_load?


>>> 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:

  1. What am I doing wrong?
  2. Is there a reference manual for this?
  3. 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

Upvotes: 3

Views: 3303

Answers (2)

jacobq
jacobq

Reputation: 11577

Some additional resources that I've been finding useful to answer questions like this for myself are here:

For example, I think the PARAM_ types are these enum values for defining the type of each parameters that the plugin takes: (presumably PF is for "PythonFu" and "PDB" is for "Procedure Database")

PF_INT8        : PDB_INT8,
PF_INT16       : PDB_INT16,
PF_INT32       : PDB_INT32,
PF_FLOAT       : PDB_FLOAT,
PF_STRING      : PDB_STRING,
#PF_INT8ARRAY   : PDB_INT8ARRAY,
#PF_INT16ARRAY  : PDB_INT16ARRAY,
#PF_INT32ARRAY  : PDB_INT32ARRAY,
#PF_FLOATARRAY  : PDB_FLOATARRAY,
#PF_STRINGARRAY : PDB_STRINGARRAY,
PF_COLOR       : PDB_COLOR,
PF_ITEM        : PDB_ITEM,
PF_DISPLAY     : PDB_DISPLAY,
PF_IMAGE       : PDB_IMAGE,
PF_LAYER       : PDB_LAYER,
PF_CHANNEL     : PDB_CHANNEL,
PF_DRAWABLE    : PDB_DRAWABLE,
PF_VECTORS     : PDB_VECTORS,

PF_TOGGLE      : PDB_INT32,
PF_SLIDER      : PDB_FLOAT,
PF_SPINNER     : PDB_INT32,

PF_FONT        : PDB_STRING,
PF_FILE        : PDB_STRING,
PF_BRUSH       : PDB_STRING,
PF_PATTERN     : PDB_STRING,
PF_GRADIENT    : PDB_STRING,
PF_RADIO       : PDB_STRING,
PF_TEXT        : PDB_STRING,
PF_PALETTE     : PDB_STRING,
PF_FILENAME    : PDB_STRING,
PF_DIRNAME     : PDB_STRING,
PF_OPTION      : PDB_INT32,

Upvotes: 2

Thanatos
Thanatos

Reputation: 44334

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.

Upvotes: 7

Related Questions