13

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.

martin's
  • 3,853
  • 6
  • 32
  • 58
  • Are you getting actual errors or just warnings? – Padraic Cunningham Mar 09 '16 at 20:17
  • Probably very important clue: what does the error say? If you hover your mouse over the red-curly-line, what does PyCharm say? – Ian Mar 10 '16 at 15:33
  • Have you tried importing those things explicitly? I'd try `import gimpfu`, then access those constants like `gimpfu.RGBA_IMAGE`. – fodma1 Mar 10 '16 at 23:55
  • Sorry, busy week... The code runs just fine in GIMP. No issues there. It really is a question about setting up PyCharm so it can resolve these symbols. I searched the entire GIMP installation tree (C:\Program Files\GIMP 2) and the above-mentioned symbol names are not found. This probably means they are part of a C library that has been compiled. Not sure it is possible to provide PyCharm with what it needs to know about these symbols without polluting the code with unnecessary band-aids. Again, the code is correct and my plugin runs perfectly under GIMP. – martin's Mar 13 '16 at 01:40

1 Answers1

4

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.

Community
  • 1
  • 1
Mikhail Gerasimov
  • 36,989
  • 16
  • 116
  • 159
  • Thanks for this. I'll go through it in detail tomorrow. I was afraid the only way to approach this might be an undesirable artificial import. – martin's Mar 14 '16 at 02:20
  • If this is something GIMP should provide, and someone would contribute it (preferably in a way that is updated during a build), then we'd certainly accept this into GIMP. – Michael Schumacher Mar 14 '16 at 21:12
  • The answer given isn't exactly the right answer but I'll award the bounty nonetheless. – martin's Mar 16 '16 at 05:38
  • @MichaelSchumacher, perhaps a connection between you and the folks at JetBrains (authors of PyCharm) might facilitate this? I am not in a position to contribute to GIMP (working 16 hour days already) but perhaps JetBrains might have interest in having PyCharm work seamlessly for plugin development. – martin's Mar 16 '16 at 05:41
  • Are the `.py` "wrapper" files that Gerasimov describes the equivalent of `.h` files? That is -- they are stubbed definitions of functions and constants? Then perhaps, @MichaelSchumacher these aren't so hard to generate. I'd be willing to look at this and see if it's do-able. – aenw Apr 24 '17 at 00:28
  • They are likely most similar to C header files. I do not expect any of this to be overly complicated, and assume that anyone who can invest the time will have such files created pretty fast. It might even be enough to just include the original *.py files the *.pyd are made from. – Michael Schumacher Apr 27 '17 at 16:53
  • Any progress on providing such a py wrapper file? – Troy Weber Oct 04 '20 at 17:57