Re: [pygtk] python and GTK+-3 - possible?




----- Original Message -----
> J Stowers wrote:
> >
> > > > From what I understand, pygobject can only provide GTK3 and
> > > > pygtk can
> > > > only provide GTK2.
> >
> > pygtk.py (what gets executed above) lives in pygobject. This, for
> > historical reasons lived there to help easy the pain of the pygtk-1
> > ->
> > pygtk-2 transition. This is why you see pygtk.require(2.0) at the
> > top of
> > some programs (although this has not been necessary for some time).
> >
> > pygtk.py does some things with sys.path to choose which native code
> > gets
> > imported. We might start requiring people to call pygtk.require(2.0)
> > again in future, depending on the parallel installation capabilities
> > of
> > the static parts of pygobject, however I think that discussion is
> > ongoing, and not something you should worry about (Dieter, J5, is
> > that
> > correct, I have been AFK for a while)
> >
> > > Actually I think it's possible that
> > > 'from gi.repository import Gtk'
> > > may give you GTK+2; I think it depends on which (version of) GTK
> > > was introspected into whichever gi repository your python finds.
> > > Not suggesting this is what you want - just my experience.
> >
> > This is not correct. One can choose the version of the typelib to be
> > loaded; e.g.
> >
> > >>> import gi
> > >>> gi.require_version("Gtk", "2.0")
> > >>> from gi.repository import Gtk
> > >>> Gtk.Switch
> > --> Fails
> >
> > But the annotations are most up to date in the Gtk-3 overrides, so I
> > would suggest letting it choose the most recent typelib by default,
> > that
> > is
> >
> > >>> from gi.repository import Gtk
> > >>> Gtk.Switch
> > ---> Works
> >
> > And gives you gtk+-3.
> >
> > If you want to use gtk+-2 I suggest you stick with pygtk.
> >

I would add that you should always be specific on which version you are loading.  Gtk2 works under introspection but pretty much minimally.  Gtk 4 is going to come a lot sooner than the 2 to 3 transition.
Also if you don't have Gtk 3 installed it will pick up 2.

> Thanks for the explanation. I am starting to get it.
> 
> Would this be a true statement regarding the role that pygobject
> plays:
> (Please correct it)
> 
> 
> 
> "pygobject today provides two different roles :
> 
> 1. support for pygtk to use static bindings to
> 
> Gobject, Gio, Gdk, Gtk.

yes, but for static bindings we use lowercase - gobject, gio, gtk and gtk.gdk
 
> Support for Gtk is for GTK+2 only, not GTK+3

Correct.  To support gtk+3 someone would have to add all the new API and removed all the deprecated API and that is all manual

> 2. support for python apps to use dynamic python bindings for
> 
> Gobject, Gdk, Gio, Gtk and others, each introspected from their
> 
> respective packages. GTK version can be altered
> 
> by choice of package during introspection
> 
> and also overridden in the application by require,
> 
> but support is intended for GTK+3."

Yes.  Well they are introspected from their installed typelibs which for the most part comes from the library package in question.  For GLib, Gio and GObject, those all come from the gbject-introspection package because of circular dependencies (gobject-introspection requires glib/gobject which in turns gets typelibs compiled from gobject-introspection).  Many other libraries like libchamplain have typelibs so you quickly see how we make things easier for GObject based libraries.

However this comes with the issue that API can be released that doesn't quite work with bindings because Python can't support everything C can do.  This means library quality will vary umoung those with maintainers that actually understand how introspection works and those who don't.

--
John (J5) Palmieri
Software Engineer
Red Hat, Inc.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]