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

How to know why a python plug-in is failing

Tue Nov 23, 2010 12:05 am

noob here.

Say there's a problem with a python script. e.g., I forgot a paren somewhere.
The result is that my plug-in isn't available on the menu. I presume because the script quit before it registered.

Where is that syntax error going?

If I could see the errors coming from the script, I could find the culprit faster.

Thanks.

Re: How to know why a python plug-in is failing

Tue Nov 23, 2010 12:06 am

Forgot to say:
Running GIMP 2.6.11 on Win 7.

Re: How to know why a python plug-in is failing

Tue Nov 23, 2010 1:32 am

A start would be to use the Python console in GIMP:

http://registry.gimp.org/node/24275

Re: How to know why a python plug-in is failing

Tue Nov 23, 2010 1:58 am

Thanks, mahvin. There's a lot of useful information there that I was unaware of.

However, I couldn't find an answer to my question.

I'm trying to figure out: where do the python errors go when there is a syntax error in the script?

Re: How to know why a python plug-in is failing

Tue Nov 23, 2010 3:21 am

I don't know the answer to your question, specifically. I use NetBeans or IDLE to run/check syntax and indentation for errors.

Re: How to know why a python plug-in is failing

Tue Nov 23, 2010 4:19 am

john_whorfin wrote:I'm trying to figure out: where do the python errors go when there is a syntax error in the script?

Greets John,

I'm not a GIMP python person and I don't know the direct answer to your question in Windows but interpreted languages, like python and scheme, normally direct output to the console (or to GUI message dialog). This is the case in Linux. If python-fu isn't displaying those messages in a GUI dialog or in the python-fu console, you might try redirecting GIMP messages to the Windows console.

Code:
gimp --console-messages

You can check "gimp --help" on your system to see which options are compiled in.

Here is my gimp --help
Code:
]$ gimp -help
Usage:
  gimp [OPTION...] [FILE|URI...]

GNU Image Manipulation Program

Help Options:
  -h, --help                          Show help options
  --help-all                          Show all help options
  --help-gegl                         Show GEGL Options
  --help-gtk                          Show GTK+ Options

Application Options:
  -v, --version                       Show version information and exit
  --license                           Show license information and exit
  --verbose                           Be more verbose
  -n, --new-instance                  Start a new GIMP instance
  -a, --as-new                        Open images as new
  -i, --no-interface                  Run without a user interface
  -d, --no-data                       Do not load brushes, gradients, patterns, ...
  -f, --no-fonts                      Do not load any fonts
  -s, --no-splash                     Do not show a startup window
  --no-shm                            Do not use shared memory between GIMP and plugins
  --no-cpu-accel                      Do not use special CPU acceleration functions
  --session=<name>                    Use an alternate sessionrc file
  -g, --gimprc=<filename>             Use an alternate user gimprc file
  --system-gimprc=<filename>          Use an alternate system gimprc file
  -b, --batch=<command>               Batch command to run (can be used multiple times)
  --batch-interpreter=<proc>          The procedure to process batch commands with
  -c, --console-messages              Send messages to console instead of using a dialog
  --pdb-compat-mode=<mode>            PDB compatibility mode (off|on|warn)
  --stack-trace-mode=<mode>           Debug in case of a crash (never|query|always)
  --debug-handlers                    Enable non-fatal debugging signal handlers
  --g-fatal-warnings                  Make all warnings fatal
  --dump-gimprc                       Output a gimprc file with default settings
  --display=DISPLAY                   X display to use


Another thought would be to try running GIMP with the --verbose option.

You could also try running the plug-in directly from the command line but I don't know the exact syntax for that in Windows, uses something like "gimp-console", I believe. Look for the those executables and check their options.

There are a couple of python "code checkers" out there like PyChecker or PyLint, which might be useful in debugging syntax errors.

Push comes to shove, start your plug-in as skeleton code and add small sections in at a time, testing as you go. :mrgreen:

Sorry I couldn't assist more but maybe some of those suggestions will help.

Re: How to know why a python plug-in is failing

Tue Nov 23, 2010 4:30 am

Oh, and a python editor with color syntax highlighting might be helpful too. I'm sure there are a few good freebies out there for the Windows platform.

Re: How to know why a python plug-in is failing

Tue Nov 23, 2010 9:42 am

Although I don't do much programming, check out notepad++ on sourceforge. It is a free text editor that is syntax-aware for many programming languages (about 50, by my count) from Ada to YAML. It can do syntax highlighting for the selected language, find mis-matched parens, change document encodings, does unicode, and much more - and it runs on Windows and on Linux under Wine. It might be helpful to you in finding errors in your program.

I used it when I was on Windows, and on Linux found it a big help opening those problem text files and code that sometimes gives gedit problems due to encoding issues. (Although not so helpful, it can even open most binary files.)

As of today, the most recent version is 5.8.4. See it here on Sourceforge. I see one of the commenters posted that "Notepad++ is to text editors what IrfranView is to image viewers." Having used both programs, I have to agree. That may or may not mean much to Linux users, but Irfanview is sort of a Swiss Army Knife image viewer and simple image editor for Windows that can open pretty much any image...and also runs on Linux under Wine.

Re: How to know why a python plug-in is failing

Tue Nov 23, 2010 10:01 am

I agree. I have been using notepad++ for 3 yrs now. It is great for viewing scripts and plugins also.
There is also Notepad++ portable, http://filepig.org/download/notepad_plus_plus_portable/

Re: How to know why a python plug-in is failing

Wed Nov 24, 2010 4:06 am

Yes Notepad ++ is awesome.
I believe you can run any python script in a wsys command line window and see the errors there.cygwin works as well i believe.As long as you have python installed , and they see the path it should work.

Here is a command window through cygwin throwing an error for not finding certain files to run it.

Compaq_Owner@Family-Room ~
$ ./scrnshot_tearoff.py
Traceback (most recent call last):
File "./scrnshot_tearoff.py", line 43, in <module>
from gimpfu import *
ImportError: No module named gimpfu

Compaq_Owner@Family-Room ~
$
Post a reply