7

I have this weird problem - I'm learning Gtk3 on Windows 7 with PyCharm Community 3.4.1. When I try to import Gtk:

from gi.repository import Gtk

it underlines Gtk as unresolved reference, becouse it's a binary module. Then I press Alt+Enter and choose "Generate methon stubs for binary module..." and wait until it it finishes indexing. Then I happily write this simple empty window with autocomplete working correctly:

class Okienko(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self, title='Okienko')

app = Okienko()
app.connect('delete-event', Gtk.main_quit)
app.show_all()
Gtk.main()

I run it, it shows me a nice empty Gtk window. So far so good.

BUT.

Bad things happen - autocomplete for Gtk module simply vanishes! from gi.repository import Gtk gets underlined red and autocomplete gives me just names which I've previously used (Window and main in this case). The only thing I can do is to Invalidate cache and restart Pycharm and go over this procedure again... I also tried .NET classes in IronPython - it's even worse, indexing takes several minutes and doesn't even finish.

DiPi
  • 99
  • 1
  • 7

2 Answers2

11

In PyCharm community edition 3.4.1 (mint 17), to make Gtk3 autocompletion works:

  1. In file: "pycharm.community-3.4.1/bin/idea.properties" comment the line: "idea.max.intellisense.filesize=2500"
  2. Restart the IDE
  3. In your code: from gi.repository import Gtk strike Alt-Enter and select "Generate stubs for binary module"
Victor Forero
  • 111
  • 1
  • 2
  • 1
    This is the same for the Professional edition, can confirm that this works. For Ubuntu it's /opt/pycharm/bin/idea.properties – PvdL Oct 22 '15 at 21:40
  • 3
    JetBrains products now have a _Help > Edit Custom Properties..._ menu item that gives you easy access to a file meant for user overrides of the idea.properties. The same solution works, but now it's a matter of adding an entry to increase the default limit: `idea.max.intellisense.filesize=10000`. – MithrilTuxedo Jun 09 '17 at 04:18
  • The third step does not work for me. Perhaps I already have some stubs generated that are not containing everything. My problem is that the autocompletion works for `box = Gtk.HButtonBox()` but then not for `box.` – dannymo Jan 27 '21 at 10:21
7

I had the same issue and found out that the Gtk.py file is too big for IDE file size limit allowed by PyCharm. I changed the config value "idea.max.intellisense.filesize" in idea.properties from 2500 to 10000. The stub generation takes some time but finishes now.

Hope that helps even Windows users. Feedback appreciated.

Devmind
  • 71
  • 1
  • 3
  • 2
    This is the same for the Professional edition, can confirm that this works. For Ubuntu it's /opt/pycharm/bin/idea.properties – PvdL Oct 22 '15 at 21:40