Switch to full style
Post all Gimp scripts and script writing questions here
Post a reply

Unable to get simple python plugin to show up

Wed Sep 29, 2021 6:52 am

Thank you in advance for anybody helping.

I am using GIMP 2.10.28 on Windows 7. I am following the youtube video at

https://www.youtube.com/watch?v=nmb-0KcgXzI&t=480s&ab_channel=JacksonBates

for developing a simple Python plugin. I am unable to get the simple plugin to show up. The sample exercise in the video is to add a "gimp-Hello-Warning" in the File menu. But no matter where I put the .py file, it doesn't show up. I've tried all of the places in the edit -> preference -> folder -> plugins and no luck.

C:\Users\####\AppData\Roaming\GIMP\2.10\plug-ins
E:\Program Files\GIMP 2\lib\gimp\2.0\plug-ins

I even tried:

C:\Users\####\AppData\Roaming\GIMP\2.10\scripts
E:\Program Files\GIMP 2\lib\gimp\2.0\scripts

Here's the no brainer program

#!/usr/bin/env python

# Tutorial available at: https://www.youtube.com/watch?v=nmb-0KcgXzI # Feedback welcome: jacksonbates@hotmail.com

from gimpfu import *

def Hello-Warning(image, drawable): # function code goes here...
pdb.gimp_message("Hello World!")

register(
"python-fu-Hello-Warning",
"This is a short message",
"This is a long message",
"Myname", "Myname", "2021",
"NAME FOR MENU",
"*", # type of image it works on (*, RGB, RGB*, RGBA, GRAY etc...) [
# basic parameters are: (UI_ELEMENT, "variable", "label", Default) (PF_IMAGE, "image", "takes current image", None), (PF_DRAWABLE, "drawable", "Input layer", None) # PF_SLIDER, SPINNER have an extra tuple (min, max, step) # PF_RADIO has an extra tuples within a tuple: # eg. (("radio_label", "radio_value), ...) for as many radio buttons # PF_OPTION has an extra tuple containing options in drop-down list # eg. ("opt1", "opt2", ...) for as many options # see ui_examples_1.py and ui_examples_2.py for live examples ],
[],
Hello-Warning, menu="/File") # second item is menu location

main()

Re: Unable to get simple python plugin to show up

Wed Sep 29, 2021 7:43 am

A python or python-fu goes in your plug ins folder NOT your scripts folder.

When you look at your folders in your C:\Users\####\AppData\Roaming\GIMP\2.10\
Look for the plug in folder

Re: Unable to get simple python plugin to show up

Wed Sep 29, 2021 7:47 am

sallyanne wrote:A python or python-fu goes in your plug ins folder NOT your scripts folder.

When you look at your folders in your C:\Users\####\AppData\Roaming\GIMP\2.10\
Look for the plug in folder


Thanks but I did try the plug-ins folders before trying the scripts folder.

Re: Unable to get simple python plugin to show up

Wed Sep 29, 2021 7:53 am

The way you posted it you destroyed all indentation.

Very often the plugin contains syntax errors. You can run it outside of Gimp to check for the worst (and most frequent) ones; such as indentation, and unbalanced quotes and parentheses.

See https://www.gimp-forum.net/Thread-Debug ... in-Windows

In your case there is at least "Hello-Warning" which isn't a valid function name in Python (the "-" is always seen as a minus sign). Try "hello_warning" (snake_case, python style) or "helloWarning" (camelCase). It could also further complain about the menu location (try "<Image>/File" instead).

Re: Unable to get simple python plugin to show up

Wed Sep 29, 2021 10:31 am

Hi - getting started can be so frustrating.
There are so many things that can go wrong - hyphens instead of underscores, not indenting or using tab instead of inserting spaces - to say nothing of miserable error reporting.

Don't give up!

Below is your code up and running. I have moved the menu location to the Filters menu and added a toggle option (which does nothing) so that the message will (should) show up in a message box rather than just appear briefly below the image which makes it easy to miss.

Select and copy the code below into your text editor (I use Notepad++). Check that the indentations are all the same (4 spaces) and save it as a python file.


Code:
#!/usr/bin/env python
#
# -------------------------------------------------------------------------------------
#



from gimpfu import *



def Hello_Warning(image, drawable, hello):
    pdb.gimp_message("Hello")


   
register(
    "python_fu_python_fu_Hello_Warning_Plug_in",
    "This is a short message",
    "This is a long message",
    "No Brainer",
    "Open source (BSD 3-clause license)",
    "2021",
    "<Image>/Filters/Hello Warning...",
    "*",
    [
    (PF_TOGGLE, "Hello_Yes_or_no", "Say hello:", 0),
    ],
    [],
    Hello_Warning)

main()

Re: Unable to get simple python plugin to show up

Wed Sep 29, 2021 11:55 am

Thanks, that helps.

Reminds me of my first meeting with Python. I attended a training class and within 2 minutes, I was ready to walk out the door. All those indentation to me was a formula for failure. You guys are joking, right? And it's case sensitive? What's this, a Linux thingy?

The instructor urge me to stay for a little longer. "It will get better, a lot better, I promise", he said.

I've never looked back. Goodbye C, C++, Fortran, Rexx, Perl, ... and a gazillion other languages I dabbled with.

Python rules!

Re: Unable to get simple python plugin to show up

Wed Sep 29, 2021 12:28 pm

I don't have a lot of years with GIMP python and I have created a few plugins. The main trick is to put your mind into the learning process of python. Like it was state it by the excellent coders here;

From ofnuts - "Very often the plugin contains syntax errors. You can run it outside of Gimp to check for the worst (and most frequent) ones; such as indentation, and unbalanced quotes and parentheses."

From Skinnyhouse - "Hi - getting started can be so frustrating.
There are so many things that can go wrong - hyphens instead of underscores, not indenting or using tab instead of inserting spaces - to say nothing of miserable error reporting."

"Don't give up!"


I think it was well said; Don't give up!

Re: Unable to get simple python plugin to show up

Wed Sep 29, 2021 2:23 pm

Rock and roll! Works.

Thanks, everybody.

Re: Unable to get simple python plugin to show up

Wed Sep 29, 2021 4:07 pm

Pocholo wrote:The main trick is to put your mind into the learning process of python.


.. and programming. Knowing a language and knowing programming are distinct skills.
Post a reply