Re: [Gimp-user] Help with python-fu



On 2/17/20 9:41 PM, Alussam wrote:
Hello! I need some help with writing simple plugin. I tryed to use ready to use
plugin code from https://www.gimp.org/docs/python/index.html. But when I used
it, seems nothing happens. So I made a simple script, which prints message. But
nothing works seems. Please,whatch video for details:
https://youtu.be/0vpPaIEUGGE

Thanks for help.

Attachments:
* https://www.gimpusers.com/system/attachments/1371/original/script

Your script registers (shows up in menus, listed in pluginrc), so you
have it basically right.

When you run it you get his message (may require to use Gimp-console if
you are on Windows):

Traceback (most recent call last):
  File "/app/lib/gimp/2.0/python/gimpfu.py", line 857, in _run
    res = apply(func, params[1:])
TypeError: crop_all_layers() takes exactly 1 argument (2 given)

This is because your function takes one single argument ("image"), and
since your plugin is using old-style registration, an image and a layer
are always implied as the first two arguments, so you need at least two
arguments in your function (and you can ignore the second).

A better approach is to use new-style registration. In this registration
model, the menu entry is split in two: the menu label as before, but
without any path, and a named "menu" argument with the path:

Old style:

register(
    "crop-all-layers","","","Alex","Alex","2020",
    "<Image>/Filters/Artistic/_croplayers...",
    "RGB*, GRAY*",
    [],
    [],
    crop_all_layers,
)

New style:

register(
    "crop-all-layers","","","Alex","Alex","2020",
    "_croplayers...",
    "RGB*, GRAY*",
    [],
    [],
    crop_all_layers,
    menu="<Image>/Filters/Artistic/"
)

However with the new style registration, there are no implicit
arguments, so you have to declare your image argument:

register(
    "crop-all-layers","","","Alex","Alex","2020",
    "_croplayers...",
    "RGB*, GRAY*",
    [(PF_IMAGE, "image", "Input image", None)],
    [],
    crop_all_layers,
    menu="<Image>/Filters/Artistic/"
)

And then of course use a function that takes a single argument, the image.

Some hints to debug your scripts, especially if you are on Windows:

https://www.gimp-forum.net/Thread-Debugging-python-fu-scripts-in-Windows

PS: Couldn't see anything useful in your video, it is too fuzzy to see
the labels. Best make static screenshots, and copy/paste any error
messages as text.









[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]