0

I am trying to write a Python-Fu plugin for GIMP, but adding more than 4 input parameters (including the Image and Drawable parameters) will cause the script to not run at all. I have tried this with various input parameter types and they all produce the same result. Does anyone have some insight as to why this is happening? Am I missing something obvious?

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"
)

EDIT:

Below is the full, fully functional script including the Python code.

#!/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()
MrKagouris
  • 106
  • 1
  • 8
  • Likely not a problem of too many parameters, there are scripts around with too many parameters to fit a screen. But in practice I haven't been able to make your code work even just keeping the PF_IMAGE (btw, you don't need the PF_DRAWABLE for this script). There must be something subtle that makes the registration fail (or nor happen at all). Can you edit your question to add the code that registers properly? – xenoid May 29 '17 at 00:14
  • @xenoid Done. However the only difference between the functional code and the non-functional code is exactly just that one extra input parameter. – MrKagouris May 29 '17 at 07:41
  • You know your actual Python function (`guide_maker`) has to match the signature you pass to register, don't you? – jsbueno May 30 '17 at 08:10
  • @jsbueno Look at the code again. – MrKagouris May 30 '17 at 09:57

1 Answers1

3

You have to use integer default values in the registration, not 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)
],

enter image description here

xenoid
  • 8,396
  • 3
  • 23
  • 49