strycore / fakegir

fakegir: Bring autocompletion to your PyGObject code
GNU General Public License v3.0
92 stars 16 forks source link

Select GTK version using environement variables #36

Closed major-mayer closed 3 years ago

major-mayer commented 3 years ago

Now that GTK4 is released the assumption that there is only one GTK version to generate stubs for doesn't work anymore. I experienced this myself the hard way, because the GTK 3 stub files always got overwritten by the GTK 4 ones which are completely different and don't make sense when you want to use GTK3.

To solve this, I introduced another environment variable that let's the user select the GTK version he wants. If no environment variable is set, the script generates stubfiles for GTK3 by default, because i think that's the most used right now.

realh commented 3 years ago

Can't you just specify the version on the command line eg -m Gtk-3.0 or -m Gtk-4.0? That's what I've been doing, and it seems to work,

major-mayer commented 3 years ago

Really? Specifying those arguments do work for you? For me it doesn't and I don't see where in the code this logic would come from...

~/Checkouts/fakegir >>> ./fakegir.py -m Gtk-3.0                                
Parsing /usr/share/gir-1.0/Gom-1.0.gir
...
Parsing /usr/share/gir-1.0/Gtk-3.0.gir
Parsing /usr/share/gir-1.0/LangTag-0.6.gir
Parsing /usr/share/gir-1.0/Gcr-3.gir
...
Parsing /usr/share/gir-1.0/Gtk-4.0.gir
Parsing /usr/share/gir-1.0/cairo-1.0.gir
...
realh commented 3 years ago

Perhaps it only works for me because I'm using Gtk-4.0 anyway. I'm using my own fork, but I don't think I changed anything relevant to this issue.

major-mayer commented 3 years ago

I guess this must be the reason then. At least for me the Gtk-4.gir files get converted later, so they overwrite all Gtk-3 files that were created previously.

BTW: I would like to also use Gtk4 but can't find any good Python tutorials on it. Any suggestions?

realh commented 3 years ago

Not really, I just relied on my experience with GTK3 and looking at the migration guide and C API docs for each widget.

Oh wait, python. I had this confused with another project for Typescript! You might actually find that helpful too, because one of the problems I had with python was that it could be hard to work out the parameters etc for functions in libraries that didn't have any docs for the python version of their API. The .d.ts files ts-for-gjs outputs provide a really handy reference, and I think the binding rules for python and gjs are very similar.

strycore commented 3 years ago

The patch looks simple enough, thanks for bringing support for Gtk 2 as well :D

major-mayer commented 3 years ago

Thanks for the quick merge :) Maybe you should update the readme at some point