Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autocomplete for gtk3 and pygobject

I am looking for a possibility to add autocompletion for gtk3 libs to vim. I have already tried vim-jedi as it seems the state of the art autocompletion mechanism for vim and python (also recommended here), but that does not work for the gtk3 stuff wich is imported from the gi.repository

from gi.repository import Gtk, GdkPixbuf, Gdk, GObject

I took a look into the gi.repository site-packages. After that I am not suprised that jedi is not able to introsepect the methods of the Gtk modules, because these modules a generated there with a lot of magic ;-)

Additionally other "real" IDEs like PyCharm also does not support completion for the modules which were imported this way (i tried the Community Edition, but I would bet that the Professional Edition also does not support that).

Does anyone have an idea how to add autocompletion to vim (favored solution) or another Editor/IDE?

The GObject, Gtk modules contain quite a lot methods/classes and it's not easy to remebember everything you need. Furthermore there seems to be only documentation for the C api of gtk3, where the method names are not always the same as in python api...

like image 799
flammi88 Avatar asked May 14 '14 10:05

flammi88


2 Answers

Neocomplcache/Neocomplete are capable of completing introspected GObject libraries but it is very likely that this will crash if you did not compile Vim yourself against GTK+ 3. On Ubuntu 14.04, Vim is compiled against GTK+ 2 and trying to import and autocomplete GTK+ 3 libraries will fail because both toolkits cannot run at the same time.

like image 124
matthias Avatar answered Nov 08 '22 06:11

matthias


Both Jedi and PyCharm support PEP 484 .pyi type stubs. You can add these type annotation stubs for PyGObject to your editor using the PyGObject-stubs library:

python3 -m venv .venv
source .venv/bin/activate
pip install PyGObject-stubs

Both Jedi and PyCharm should pick them up automatically.

like image 1
Dan Yeaw Avatar answered Nov 08 '22 05:11

Dan Yeaw