python - 你如何调用 gimp_file_load?

标签 python gimp gimpfu


>>> pdb.gimp_file_load.nparams
<strong>3</strong>
>>> 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 = '<em>a filename</em>'
>>> img = pdb.gimp_file_load(gimpfu.RUN_NONINTERACTIVE, fname, fname)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
<strong>TypeError: wrong number of parameters</strong>

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

最佳答案

这似乎是 GIMP 的“过程数据库”和围绕它的 Python 包装器之间抽象的一点漏洞。 run_mode,AFAICT,是一个特殊的 child ,是一个可选的,仅限关键字的参数。例如,这有效:

>>> img = pdb.gimp_file_load(fname, fname, run_mode=gimpfu.RUN_NONINTERACTIVE)
>>> img
<gimp.Image 'fname.xcf'>

作为this source说:

Procedure Browser to Python:

  • Change dashes to underscores
  • Omit any run-mode parameter
  • Change -1 to None

(强调我的);你真的不需要省略它,它只需要是一个关键字参数。 (如我的示例所示。)关键字参数必须跟在 Python 中的非关键字参数之后。您也可以将其关闭,我猜它假定某种默认值。 (虽然我不知道是哪个。)

据推测,我在问题中很好奇的“PARAM_”常量揭示了这一点,除了我无法在文档或内省(introspection)中找到整数的符号/命名版本。

关于python - 你如何调用 gimp_file_load?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19104693/

相关文章:

python - 在 Python 中将有限的 dict 值解压缩为局部变量的优雅方法

python - Imagemagick 或类似的脚本图像增强

layer - 如何快速知道 Gimp 中的图层尺寸?

gimp - 从 Python 脚本/插件关闭 GIMP 图像

python - 批量导出 Gimp 中所有打开的窗口

python - 检查我的提交在 emacs/git 中是否有 'import pdb'?

python - 如何解析 BaseHTTPRequestHandler.path

python - 取模求未知值

linux - 从命令行 Gimp

python 无法导入 gimpfu