My love for Python has increased from a lot to even more since I started, yet again, with completing various challenges on projecteuler.net. It just so easy and fun to create small scripts. As with this post, I usually use Emacs for the text editing of these smaller programs. But, being lazy, I am not that interesting in finding extensions to write things like autocomplete et al, as my interest grew to write larger programs in Python.
Wanting a GUI for my idea for a larger program to develop, Gtk was what I settled with since it has good bindings for Python. I followed the installation instructions and ran several of the examples successfully. Great!
But, when I tried to modify one of the examples, I realized that I wasn’t given autocomplete context for the object I tried to invoce a method upon. A popup was presented with a hint of installing the python package pygobject-stubs==0.0.2 could give me autocomplete. Installing it resulted in no more autocomplete than before. A comment on an issue on the GitHub page for this project seems to point to that this package isn’t in a currently working state.
A quick search on the Internet provided me with similar needs to have Gtk autocompletion in PyCharm. The solution is quite nice, as it is generic to similar packages that are provided in binary form, as PyCharm can generate autocompletion (stubs?) for you! As Gtk is quite large, a general advice is to increase the intellisense cache file. This is done by editing the setting
idea.max.intellisense.filesize to a bigger than default value. I ended up with 25000, but smaller values might work. I edited this setting in the file that can be found via the menu item Help > Edit Custom Properties….
Then I followed the advice to put the blinking cursor inside the
Gtk word in the line
from gi.repository import Gtk and pressed
Enter. But no matter where I put the cursor, the option
Generate stubs for for binary module gi.repository.Gtk never appeared. Putting two and two together, I uninstalled the “pygobject-stubs” python package, restarted PyCharm and then tried it one more time. This time the option appeared! It took some time, but now I have autocompletion for Gtk in PyCharm!