Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use PyCharm for GIMP plugin development?

I need to develop a plugin for GIMP and would like to stay with PyCharm for Python editing, etc.

FYI, I'm on Windows.

After directing PyCharm to use the Python interpreter included with GIMP:

Project interpreter

I also added a path to gimpfu.py to get rid of the error on from gimpfu import *:

enter image description here

This fixes the error on the import, even when set to Excluded.

I experimented with setting this directory to Sources, Resources and Excluded and still get errors for constants such as RGBA-IMAGE, TRANSPARENT_FILL, NORMAL_MODE, etc.

enter image description here

Any idea on how to contort PyCharm into playing nice for GIMP plugin development?

Not really running any code from PyCharm, it's really just being used as a nice code editor, facilitate revisions control, etc.

like image 891
martin's Avatar asked Mar 05 '16 19:03

martin's


1 Answers

As you find this variables are part of .pyd files (dll files for Python). PyCharm can't get signatures for content of this files.

For Python builtins (like abs, all, any, etc.) PyCharm has it's own .py files that uses only for signatures and docs. You can see it if you'll click on some of this funcs and go to it's declaration:

enter image description here

PyCharm will open builtins.py file in it's folder with following content:

def abs(*args, **kwargs): # real signature unknown
    """ Return the absolute value of the argument. """
    pass

def all(*args, **kwargs): # real signature unknown
    """
    Return True if bool(x) is True for all values x in the iterable.

    If the iterable is empty, return True.
    """
    pass

def any(*args, **kwargs): # real signature unknown
    """
    Return True if bool(x) is True for any x in the iterable.

    If the iterable is empty, return False.
    """
    pass

As you see functions are defined and documented, but have no implementation, because their implementation created with C and placed somewhere in binary file.

Pycharm can't provide such wrapper for every library. Usually people who created .pyd files provide their .py wrappers (for example, PyQt module: no native python implementation, just signatures).

Looks like Gimp doesn't have such wrapper for some of variables. Only way I see is to create some sort of own wrapper manually. For example, create gimpfu_signatures.py with following content:

RGBA_IMAGE = 1
TRANSPARENT_FILL = 2
NORMAL_MODE = 3

And import it while you're creating plugin:

from gimpfu import *
from gimpfu_signatures import *  # comment on release

Not elegant, but better then nothing.

...

One more note about gimpfu.py's path. If I understand correctly, you just added this path to project. It may work, but correct way is to add it to project's PYTHONPATH (in project preferences). See this link for detailed manual.

like image 116
Mikhail Gerasimov Avatar answered Oct 19 '22 04:10

Mikhail Gerasimov