Post all Gimp scripts and script writing questions here
Post a reply

How to develop Python scripts for GIMP?

Thu Jun 25, 2015 2:31 pm

Hello,

I have been studying the Python scripting library, and it seems to be very advanced and powerful, but unfortunately I haven't found good documentation for it, and I am pretty much flying blind with it.

I have GIMP 2.8.14 on a Win7 pc.

Does anybody has a link for the API or SDK? I have found this page (http://www.gimp.org/docs/python/) but it seems to be a short introduction to GIMP+Python.

What is the best way to develop scripts for GIMP? Right now I have to edit the script, save, open GIMP, test script, close, repeat... every time... Is there a way to unload a script?

How can I see Python error messages? If something fails, GIMP just shows a 'invalid state' message, but I don't get the Python error message.

Any help on this topic will be greatly appreciated!

Thank you!

Re: How to develop Python scripts for GIMP?

Thu Jun 25, 2015 4:11 pm

Hi Pixaeiro,

There isn't much good documentation around - I find the best source is the procedure browser and plugin browser (both off the help menu) which give reasonable docs and basic search functionality. But it's a far cry from a proper IDE :)

Two other useful tips:
1. You only need to reload Gimp if you change the signature of the method call or the plugin registration. Once you've set these up, edit the body of the function (and any supporting functions or classes), and the latest version of the script runs every time.

2. If you run Gimp inside a command-line terminal, you can see the python error messages when your script throws errors.

Disclaimer: I run Gimp on Linux, not windows, but I imagine both points are true across platforms.

Hope that helps!

Dave

Re: How to develop Python scripts for GIMP?

Thu Jun 25, 2015 4:47 pm

Awesome, not having to close and open GIMP every time will be a great time saver!

I tried running GIMP from a command line, but as soon as I press the Enter key, GIMP is launched and the command returns immediately... but now that you say that is possible I'll try to find a command line argument to keep the command line active.

Thank you Dave...

Re: How to develop Python scripts for GIMP?

Thu Jun 25, 2015 4:56 pm

Yeah, it was a great day for me when I realised that the scripts would reload if the header/registration hadn't changed!

Regardig cmd line, how are you launching it? I don't have a windows VM to hand, so these instructions may be a bit wobbly, but i would do this, roughly:

1. Open a cmd window from start menu/charms bar by typing "cmd"
2. cd to Gimp installation folder (c:/Program Files/gimp-2.8 ??)
3. type "gimp" or "gimp-2.8"

This ought to launch gimp w/out closing the cmd prompt window. And if the program returns one the Gimp gui launches, it may still be able to spew output into that window. (Try registering a simple python script that divides b zero, say, just to see if you can generate an error?)

cheers, Dave

Re: How to develop Python scripts for GIMP?

Fri Jun 26, 2015 3:38 am

Just to slightly amend Dave's instructions, you need the --verbose option to get the terminal window to show. So it becomes:

Code:
1. Open a cmd window from start menu/charms bar by typing "cmd"
2. cd to Gimp binary installation folder (c:/Program Files/gimp-2.8/bin)
3. type "gimp-2.8.exe --verbose"


However, that probably won't get you much as verbose mode on Windows is anything but verbose.

If you have a Python error, you should get an error message:
Untitled2.png
Untitled2.png (22.02 KiB) Viewed 2999 times


However if you do something that creates a syntax error for example an indentation error, then you'll get an unhelpful message in the GIMP error console:
Untitled3.png
Untitled3.png (54.12 KiB) Viewed 2999 times

But if you've not got GIMP running and create that error, then your script won't register in the menu.

Kevin

Re: How to develop Python scripts for GIMP?

Fri Jun 26, 2015 3:53 pm

Some tips here

Re: How to develop Python scripts for GIMP?

Fri Jun 26, 2015 5:07 pm

I tried running GIMP with the --verbose flag, but I don't see the window with the Python errors... I get a window telling me the plug-in crashed.
Also, I do see the GIMP error console when the image is left in a bad state, but again, no Python errors.

In any case, just the fact that I don't need to restart GIMP every time I change my script is a huge time saver!

Thank you guys... if I find a way to see the Python errors, I'll post it here!

ps... Thanks ofnuts... I just saw your tips...
Post a reply