Re: PyGobject / GTK+ 3 support



Hello Jérôme,

On 2012-02-02, Jérôme <jerome jolimont fr> wrote:
> Hi all.
>
> I learnt python/GTK using PyGTK.
>
> Then I read on http://pygtk.org/ that "new users wishing to develop Python
> applications using GTK+ are recommended to use the GObject-Introspection
> features available in PyGObject", and that "existing authors of PyGTK
> applications are also recommended to port their applications to PyGObject to
> take advantage of new features appearing in GTK-3 and beyond."
>
> Does using PyGobject necessary mean doing GTK+ 3 ?

No. You can write GTK+ 2 applications using PyGObject. There is a
special require_version() function in the `gi` package that you can
use to specify the version of GTK+ that PyGObject will bind for.

Here is a complete example of a PyGObject program that uses GTK+ 2
(adapted from <http://readthedocs.org/docs/python-gtk-3-tutorial/en/latest/introduction.html#extended-example>):


import gi
gi.require_version("Gtk", "2.0")

from gi.repository import Gtk

class MyWindow(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self, title="Hello World")

        self.button = Gtk.Button(label="Click Here")
        self.button.connect("clicked", self.on_button_clicked)
        self.add(self.button)

    def on_button_clicked(self, widget):
        print "Hello World"

win = MyWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()


> PyGObject webpage says "If you want to use PyGObject to write GTK+ 3
> applications [...]". Like you can use it not to write GTK+ 3 applications.
> Yet, there's a little documentation for GTK+ 3 programming, but I didn't
> find
> any for GTK+ 2.
>
> From what I have gathered, PyGObject / GTK+ 3 seems a bit "bleeding edge" at
> this time :
>
> I think it does not work on debian squeeze (stable), for instance.
> python-gobject version is 2.21.4 and I get the following error :
> "No module named gi.repository".
>
> Can someone please confirm it does not work ? It could be my mistake.

I believe that Debian Squeeze's python-gobject package is still PyGTK.
Unfortunately, Debian Squeeze / stable does not have either of the
PyGObject packages: python-gi for Python 2.x and python3-gi for Python
3. It looks like Wheezy / testing will be the first version of Debian
to include PyGObject. As usual, Debian Sid / unstable has both
packages.

> (I know debian stable is not bleeding-edge itself, but if one starts a
> project today, he may expect his program to run on it. I didn't check other
> distros, assuming it would be about the same.)
>
> Which version of python-gobject is needed for import gi.repository to work ?

>From what I understand, PyGObject reads the compiled Typelib files
(binaries) to figure out the interface to expose. On my AMD64 Fedora
15 system, these are located in /usr/lib64/girepository-1.0. On Debian
systems, they are located in /usr/lib/girepository-1.0.

Your version of PyGObject is independent of the version of GTK+, GObject, etc.

> I understand debian package for PyGObject, pyghon-gobject, was renamed to
> python-gi starting from version 3, but it is still PyGObject. Is this
> correct ? (Is this 3 as in GTK 3 ?)

python-gi is PyGObject for Python 2.x. python3-gi is PyGObject for Python 3.

> Now, concerning windows porting, the installers on PyGobject webpage go up
> to
> 2.28 : http://ftp.gnome.org/pub/GNOME/binaries/win32/pygobject/
>
> Does this mean applications using GTK+ 3 (gi.repository) won't run either ?
>
> Where can I find information about PyGObject / GTK+ 3 support on all
> platforms (current stage, roadmap,...) ?
>
> Should I understand that it is advised to use PyGObject instead of PyGTK,
> but
> not to use GTK+ 3 ? If so, how ?

Please see my example above for an example PyGObject program that uses GTK+ 2.

> Or is the advice of the community to use GTK+ 3 and to wait for (or
> contribute to...) its full support ?
>
> I'm afraid I come in the middle of a huge change from GTK+ 2 to GTK+ 3, when
> things are in a state where GTK+ 3 is recommended, yet too early. Just like
> we
> had to bear with GTK+ 1 applications in GTK+ 2 environments for a while, as
> the porting was not trivial. For instance, glade 3.10 dropped GTK+ 2
> support,
> expecting everyone to work with GTK+ 3 (or keeping both versions installed,
> if their distribution allows it).
>
> Sorry if those are FAQ, but I've been searching already, and this whole
> thing is still unclear to me.
>
> --
> Jérôme


I hope that helps to clear up the confusion.

Daniel Trebbien


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