GIMP Python-Fu 脚本没有 运行 多于 4 个参数

GIMP Python-Fu script does not run with more than 4 parameters

我正在尝试为 GIMP 编写一个 Python-Fu 插件,但是添加超过 4 个输入参数(包括 Image 和 Drawable 参数)将导致脚本根本无法 运行 .我已经尝试过使用各种输入参数类型,它们都产生相同的结果。有谁知道为什么会这样?我是否漏掉了一些明显的东西?

register(
"python_fu_guide_maker",
"Guide Maker",
"Creates guides with specified spacing.",
"MrKagouris", "", "2017",
"Guide Maker",
"*",
[
    (PF_IMAGE, "image", "Input Image", None),
    (PF_DRAWABLE, "drawable", "Input Layer", None),
    (PF_INT, "hspace", "Horizontal Spacing", None),
    (PF_INT, "vspace", "Vertical Spacing", None),
    (PF_BOOL, "percent", "By percent?", None)
],
[],
guide_maker,
menu="<Image>/Image/Guides"
)

编辑:

下面是完整的、功能齐全的脚本,包括 Python 代码。

#!/usr/bin/env python

from gimpfu import *

def guide_by_num(image, hspace, vspace):
    imageHeight = pdb.gimp_image_height(image)
    imageWidth = pdb.gimp_image_width(image)
    if (hspace <= 0 or vspace <= 0):
        return                          # Input validity check.
    hGuides = int(imageHeight/hspace)   # Calculates the
    vGuides = int(imageWidth/vspace)    # number of guides.
    for i in range(2):
        pdb.gimp_image_add_hguide(image, i * imageHeight)   # Adds guides to
        pdb.gimp_image_add_vguide(image, i * imageWidth)    # image edges.
    for i in range(1, hGuides):                         # Adds the horizontal
        pdb.gimp_image_add_hguide(image, i * hspace)    # guides.
    for i in range(1, vGuides):                         # Adds the vertical
        pdb.gimp_image_add_vguide(image, i * vspace)    # guides.

def guide_by_percent(image, hspace, vspace):    #Not used.
    imageHeight = pdb.gimp_image_height(image)
    imageWidth = pdb.gimp_image_width(image)
    hspace = int(hspace * (imageWidth * 0.01))
    vspace = int(vspace * (imageHeight * 0.01))
    if (hspace <= 0 or vspace <= 0):
        return
    hGuides = int(imageHeight/hspace)
    vGuides = int(imageWidth/vspace)
    for i in range(2):
        pdb.gimp_image_add_hguide(image, i * imageHeight)
        pdb.gimp_image_add_vguide(image, i * imageWidth)
    for i in range(1, hGuides):
        pdb.gimp_image_add_hguide(image, i * hspace)
    for i in range(1, vGuides):
        pdb.gimp_image_add_vguide(image, i * vspace)

def guide_maker(image, drawable, hspace, vspace):
    guide_by_num(image, hspace, vspace)

register(
    "python_fu_guide_maker",
    "Guide Maker",
    "Creates guides with specified spacing.",
    "MrKagouris", "", "2017",
    "Guide Maker",
    "*",
    [
        (PF_IMAGE, "image", "Input Image", None),
        (PF_DRAWABLE, "drawable", "Input Layer", None),
        (PF_INT, "hspace", "Horizontal Spacing", None),
        (PF_INT, "vspace", "Vertical Spacing", None),
        #(PF_BOOL, "percent", "By percent?", None)
    ],
    [],
    guide_maker,
    menu="<Image>/Image/Guides"
    )

main()

您必须在注册时使用整数默认值,而不是None:

[
    (PF_IMAGE, "image", "Input Image", None),
    (PF_DRAWABLE, "drawable", "Input Layer", None),
    (PF_INT, "hspace", "Horizontal Spacing", 0),
    (PF_INT, "vspace", "Vertical Spacing", 0),
    (PF_BOOL, "percent", "By percent?", 1)
],