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

[Solved]python fu runmode detection

Fri Aug 21, 2015 3:57 am

Scripts in Gimp, whether in scheme, or in python, are running in one of three modes:
1 Interactive
2 Non-Interactive
3 Reuse last values.

From a scheme written plugin, determining the mode is easy since it is passed in as a parameter.

How (if it is even possible) is it done in a python-fu plugin?

(I have a plugin which has to return two values visually (via gimp-message) if in interactive mode, or as a tuple (gimp list) if otherwise...)

Re: python fu runmode detection

Fri Aug 21, 2015 7:00 am

Short answer: not possible
.. the run_mode parameter is used by the gimpfu module to decide how to run the script but is not passed through to the script itself (see gimpfu.py procedure _run()

Longer answer: you could write your script as a non-Fu Python plugin (ie. one which does not import gimpfu) but that means setting-up the plugin interface and creating/executing the interactive dialog yourself ..which is a right PITA if you've got a lot of input parameters (see eg. high-end-sharpen.py or the Color Grading plugin)

Simplest answer (probably): just make the output-mode itself a parameter (eg. a PF_TOGGLE which defaults to TRUE, meaning output as gimp-message, and set that parameter to FALSE when invoking non-interactively).

Re: python fu runmode detection

Fri Aug 21, 2015 2:02 pm

jontait2 Thank you for a simple and concise response. Funnily enough you outlined exactly the steps I had taken (right down to the plugin I used for researching this), and the solution I had adopted. I only posted this here 'cause I was hoping I had misinterpreted something in _run. Oh well.
Post a reply