PyCharm - A Solid Open-Source Cross-Platform Python IDE

Hey, there. I just wanted to stop in and mention using PyCharm for writing scripts for use in the BGE. It’s pretty easy-to-use, cross-platform, has an open-source version (which is the version I use), and has some nice code completion options available (though the BGE’s API can’t be picked up). Check it out.

Some really cool features in there. I’d prefer to be able to simply change a function’s name just by backspacing and typing, not having dialogue boxes. It’d be amazing if it were possible to debug through bge.
Is there something preventing the IDE from picking up Blender’s API? Or does it need to be added manually?

Except when you have code referencing that function more than 3 times, it makes sense to specially handle renaming. By distinguishing between input and refactoring, you avoid headaches when something is edited (and avoid waiting times), and it means that you can edit the name of the function wherever it is referenced, and not just at the definition.

The API isn’t defined anywhere for PyCharm to read from. PyDev had a language library for the BGE, i’m not sure what format it was in though.

As agoose mentioned, I’m pretty sure the BGE API is somehow not defined anywhere, and there’s no apparent Python distribution executable bundled with Blender for PyCharm to pick up. Even if there was, it appears Blender injects the BGE Python API into the Python distro when the BGE is started or something, as you can’t import the bge module outside of the game engine (i.e. in Blender’s Python Console).

It probably is possible (and probably not even that difficult) to write a script that runs in the BGE that could generate .py files equivalent to the contents of each game engine and standalone module. Each Python file would contain a new function definition stub for each BGE function present, a new class stub for each class present, etc. Some of the functions might have docstrings that can be extracted as well…? Obviously the contents of the definitions don’t really matter so much as just the names and arguments of the definitions, along with the types of the properties in each class.

You’d add the folder (which is somewhere else other than your script directory) as a source folder in PyCharm to pick up the code-completion, while Blender will just import the modules naturally.

I use vim, which offers tools that can generate relevant data for package-wide completion. However, I never felt the need to use them, because I find local completion (which analyzes existing definitions in the file) more than sufficient for most of what I do.

Project-wide auto-completion is nice to have, but I think the real value of vim is in the fact that it’s optimized for text manipulation, rather than text insertion.

It has a sharp learning curve (well, to be honest, it’s more like a wall), but once you’re over it … I can’t imagine going back to anything else.

I’ve been using Geany - so good so far. I’ve tried a few others and were either lacking or bloated. I’ll check out PyCharm. Thanks for the heads-up!

When I was learning python I used vi, it’s really nice for text editing. Now I just go with the regular notepad++.

I use pycharm. It’s better than notepad ++.

For auto-completion of the BGE Python API, you can use these files. was generated by parsing the rst files for the docs, so it should have some doc information too.

Just make sure they are somewhere on your interpreter’s PYTHONPATH (you can change this in the interpreter’s settings in PyCharm).

Wow, thanks so much for this, Moguri. I’m going to add it to my SVN to keep track of it, if it’s okay with you.

EDIT: Man, this is awesome. Combined with PyCharm’s auto-complete and overriding objects with custom types, and you have pretty much the actual full API for objects and the logic module.

EDIT 2: A slight problem is that the generated stubs don’t have “self” as the first argument, thereby making PyCharm mark up all object function calls as having unexpected arguments. Any way to add "self, " to the generated function calls?

I’d be surprised if it works, because a number of method defines don’t have a body.
Your best bet is just to parse the RST files as Moguri has done, but modify the function template/

After some time, it does work. What do you mean parse the RST files? With what?

I’ve found the only problem to be that it doesn’t automatically find object names and SCA elements’ names (which would require some hectic editing I think). Rest works perfectly.

^ What do you mean? Automatically find names from within Blender scenes, or…?

I use geany, and would be hesitant to move to a python-specific ide because, well, I also develop in a couple other languages.
I also consider autocompletion slightly pointless, you should know what you’re doing before you type. Yes, I do have the api open whenever I develop.
As one author once wrote ‘IDE’s make programmers dumb.’ I don’t fully agree, but kind of do.

But then, maybe I’ve just not worked on large enough projects.

Auto completion is useful for the same reason that mobile completion is, in that it reduces the amount of time it takes to type a long function name :wink:

Yeah, for example scene.objects[“auto_complete”] or cont.owner[“auto_complete”] and anything else.

I once did programming contests, complete as many questions as possible in an hour. You’d think programming speed (ie autocomplete) would be essential, right? On the first training session, the tutor gave us a little lecture about it. Let’s say I have a ten character long function name. Takes ~1sec to type. You use autocomplete to type the first 3 characters, hit tab, now it takes 0.5sec. You use that function 100 times you’ve saved a minute. Woot, 1 minute. How long was the code that used that function 100 times, at least several hundred lines, taking maybe half-an hour.

It doesn’t save that much time. Maybe in really long projects, it makes a difference of 2-3 hours a week. I suppose that does translate to several hundred dollars.

Logically speaking it would be 0.3 seconds :wink:

I find that I am generally limited by the speed at which I can write code, especially at the start of a project. Whether I gain much time time through auto completion is less important than whether I feel as though it gives me a greater ability to translate thoughts into programs, which I reckon to be quite important

What do you think should this information come from?

Object names in a blend file are surely not known to any IDE, not even Blender.

I suggest to think about if your really need to rely on hard-coded object names, because it limits the re-usability. This does not mean it does not fit certain situations.

To get auto-completion for object names, property names etc. I suggest you define some “constants” at a very visible place. A good one is the top of the code.

# properties
PROPERTY_SCALE = "scale"           <- from now on your can auto-complete PROPERTY_SCALE
'A description what this property is good for'

def scale():
   scale = owner[PROP<- auto-completion

Depending on your naming conventions the completion can be better or worse.
E.g. I prefer: Pscale = “scale” [P=Property + name]
this would start with specific choices right after "P but might include classes starting with “P” too.
-> Pscale, Player, Platform …