Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Fu Image Creation - Slight Issues
#8
Looks like you are using the deprecated registration form, where the 7th argument is a full path for the menu, so you get an old behavior. In the current registration form, the 7th argument is only the menu label, and the location is passed in a named menu= argument. With this newer form, Gimp will not add parameters and will always call the plugin with the parameters declared in the registration. The only implicit behavior is that if the first parameters can be inferred from the way the plugin is called (typically, active image, layer, path...) they won't be part of the auto-generated dialog.

So, trying with this code (that uses the current registration form):

Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from gimpfu import *

### Plugin body
def plugin(*args):
    gimp.message('Called with %r' % (args,))

### Registration
register(
        "plugin1","Test plugin parms","Test plugin parms",
        "","","",
        "Test plugin parms1: no image, full args",
        "", # Accepted image type
        [
        (PF_IMAGE, "image", "Input image", None),
        (PF_OPTION,"option","Option",0,("Option1","Option2")),
        ],
        [],
    plugin,
    menu="<Image>/Test",
)

register(
        "plugin2","Test plugin parms","Test plugin parms",
        "","","",
        "Test plugin parms2: required image, full args",
        "*", # Accepted image type
        [
        (PF_IMAGE, "image", "Input image", None),
        (PF_OPTION,"option","Option",0,("Option1","Option2")),
        ],
        [],
    plugin,
    menu="<Image>/Test",
)

register(
        "plugin3","Test plugin parms","Test plugin parms",
        "","","",
        "Test plugin parms3: no image, minimal args",
        "", # Accepted image type
        [
        (PF_OPTION,"option","Option",0,("Option1","Option2")),
        ],
        [],
    plugin,
    menu="<Image>/Test",
)

register(
        "plugin4","Test plugin parms","Test plugin parms",
        "","","",
        "Test plugin parms4: required image, minimal args",
        "*", # Accepted image type
        [
        (PF_OPTION,"option","Option",0,("Option1","Option2")),
        ],
        [],
    plugin,
    menu="<Image>/Test",
)

main()

The plugin itself is written in way that makes it accept any number of parameters (this is for debug purposes only, not a good idea for a real plugin). The only purpose of the plugin code is to display the parameters received.
It is registered as four different Gimp plugins, each with a different registration:
  • With or without an explicit PF_IMAGE first argument
  • With an image type of  "" or "*", to require an image or not.This is an important parameter: with an empty string "", the plugin doesn't work on a specific image, and so can work even if there are no images (typically if the plugin creates an image), and when its defined ("*" means image of any type) the plugin will only be enabled if there is an image and it is one of the allowed types.
The results:

Called without any image opened in Gimp:
  1. Dialog shows Image +  Option, args are (None, 0)
  2. <Menu disabled>
  3. Dialog only shows option, args are (0,)
  4. <Menu disabled>
Called with an image opened:
  1. Dialog only shows option, args are (<gimp.Image '[Untitled]'>, 0)
  2. Dialog only shows option, args are (<gimp.Image '[Untitled]'>, 0)
  3. Dialog only shows option, args are (0,)
  4. Dialog only shows option, args are (0,)
So:
  • Registration type #1 (no image required and explicit PF_IMAGE) doesn't make much sense, because the plugin will be called and can require an input that the user cannot provide.
  • Registration type #2 (image required and explicit PF_IMAGE) is the canonical way to register a plugin that works on an existing image.
  • Registration type #3 (no image required and no PF_IMAGE) is the canonical way to register a plugin that creates an image.
  • Registration type #4 (image required and no PF_IMAGE) doesn't makes much senses either, because the plugin can only be called if there are images, but the specific image will not be passed to the plugin (unless there are additional PF_IMAGE parameters after the PF_OPTION)
Reply


Messages In This Thread
RE: Python Fu Image Creation - Slight Issues - by Ofnuts - 01-23-2023, 09:16 AM

Forum Jump: