This is an enhancement request. Repeated calls to gimp_env_init should
yield warnings and not fatal errors. It has benefits for gimp plugins
written in Python.
Currently gimp_env_init() calls g_error (fatal) if called a second time.
Instead, pygimp_main(), which calls gimp_env_init(), should check
whether this is a repeated call and issue a warning then return an
error. (I'm not sure if any changes are needed for ScriptFu, whether
Pygimp should check the return from gimp_main and raise a warning
Currently, you can't import a plugin from another plugin unless the
imported plugin guards the call to main() to prevent it from being
called unless this is a top level invocation:
It could be sufficient to have a convention for plugins to guard the
call to main(), but the convention is not usually followed. Or you could
have a convention that any shared code needs to be in a separate module
from the top plugin module, but again, that convention is not often
If you could import a plugin from within a Gimp plugin, then you could
share more code. You could use classes etc. from imported plugins. You
could also invoke the imported plugin's top function without invoking it
as a registered PDB procedure. Neither reason is compelling.
I am not that familiar with the gimp source. I am guessing that
gimp_main() can't be called twice to avoid redundant io channels, and
that gimp_env_init() is doing the guarding. But does it need to be
fatal, is there any real harm done if they return a warning to the
caller? Apparently not. I built a version of gimp in which gimp_main
returned a warning on second invocations. It didn't seem to hurt gimp.
Context: I was exploring whether you could use pydoc to document
plugins. I tried to invoke the python pydoc module on a plugin from
within another plugin, an 'inspector' plugin. Pydoc imports a module
and introspectively documents it using the python inspect module. It
fails to import (fatal error: gimp_env_init must only be called once)
unless the call to main() is guarded. This enhancement fixes that
problem. (You can't typically invoke pydoc as a command from the shell
on a plugin because the shell environment typically does not include the
path to the gimpfu module.) Documentation produced by pydoc might be of
marginal use, and then only to programmers, and sometimes only if the
plugin writer has provided docstrings, self documentation in the code.
Gimp-developer mailing list