Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 474
Thanatos Avatar asked Dec 21 '25 05:12

Thanatos


1 Answers

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.

like image 196
Thanatos Avatar answered Dec 23 '25 21:12

Thanatos