I installed Fedora 15 to use Python3 and GObject to develop a desktop-application, because PyGTK looks outdated:
PyGTK 2.24.0 released Friday 01 April 2011 by Rafael Villar Burke PyGTK 2.24.0 has been released. This is a stable release supporting the GTK+ 2.24 API. New users wishing to develop Python applications using GTK+ are recommended to use the GObject-Introspection features available in PyGObject.[...]
PyGobject 2.26.0 has been released. This is the first stable release in the 2.26.x series and introduces initial support for introspection and Python 3. [...]
Source: http://www.pygtk.org/
I thought STRIKE! using Python 3 and PyGObject to develop new Gnome3 Applications! I vis开发者_开发知识库ited the PyGObject Page and saw that the newest stable Version is 2.28 (and Python3 is supported since 2.26) which is installed on Fedora, BUT only with python2 bindings.
What the heck?
I visited the PyGobject demos and Examples on the Site, and looked at the source and every code there is using pygtk + pygtk.require('2.0'), instead of pygobject.
Am I missing something? How can I use Python3 and PyGObject to develop Gnome 3 Apps?
Update: there is a bit of documentation here: The Python GTK+ 3 Tutorial. It's still missing anything to do with GIO, etc.
It's not... er, impossible... but because you're talking about the latest generation of GTK (&co) bindings, things are bound to be a bit behind. Developer effort is mostly directed at actual development, and documentation, examples, etc. tend to catch up much later. Such is the reality of free software :/ Remember that PyGI was merged into PyGObject rather recently, too, so there's yet another discontinuity to edit out of history.
So my answer to you is:
- Subscribe to the PyGTK/PyGObject mailing lists, ask for some pointers or reference material or hand-holding and go from there. A constant channel to the developers is really the only way to stay on top of things.
- Keep this moment (and that guy's facial expression) tucked away in a corner of your brain, so that when you're up to speed, you — yes you, sir, YOU — can write some of this stuff down and submit it as documentation for the next hapless soul who is in this situation.
(Personally, I can't wait to put some time aside to try putting something together with the new API, but I'm trying to defer until Gnome 3 is in Debian. I eagerly await wearing such expressions on my face.)
The platform demos on developer.gnome.org are fully written in GTK 3 and GNOME 3. At the moment there are only two available for Python, the others haven't been translated yet, but that should get you started.
Unfortunately, even years after GTK 3 is commonplace, you will still run into PyGTK 2 tutorials online, because people write them in a flash of enthusiasm and never update them again. Nobody will take them down either, because there still might be valuable material in them, and you only have to change X, Y, and Z to get it to work with GTK 3... This is why you can still find C tutorials for GTK 1.2 online.
So if you find a tutorial for PyGTK 2, you would do well to write an e-mail to whoever is hosting it, telling them it's out of date. Better still, update the tutorial for GTK 3 and send them a new version! It is, after all, open source.
despite the import pygtk pygtk.require('2.0') they are written in introspection, if you comment out the pygtk import they all still run, i suspect its merely an oversight, ive been putting a fair bit of time trying to port some things lately
the way to tell is how the code imports gtk itself
#import pygtk
#pygtk.require('2.0')
from gi.repository import Gtk, GLib, GObject, GdkPixbuf, Gio, Pango
means its using introspection if code does gtk things with a capital G then its definately introspection too :) for example
#a pygtk window
awindow = gtk.Window()
#an introspection window
awindow = Gtk.Window()
What I did now to develop a GTK+
Application is to download and install Anaconda3
from here and then create a new virtual environment using:
conda create --name xld-attribute-value-adder python=3.4 pip setuptools pygobject
(I added pip
and setuptools
because virtualenv
used to add them when creating a virtual environment. I know I can use pip
for installing packages, but setuptools
's name implies it can be used or is used for something similar.)
Then Anaconda
tells me, that it cannot find PyGObject
and that I can search for it using binstar
(great, another tool to keep in mind!) as follows:
binstar search -t conda pygobject
However, that results in multiple search results:
Name | Version | Package Types | Platforms
------------------------- | ------ | --------------- | ---------------
???/pygobject3 | 3.12.0 | conda | linux-64
: None
KristanArmstrong/pygobject | 3.14.0 | conda | win-64
: PyGObject is a Python extension module that gives clean and consistent access to the entire GNOME software platform through the use of GObject Introspection.
fallen/pygobject | 3.14.0 | conda | linux-64, linux-32
: PyGObject is a Python extension module that gives clean and consistent access to the entire GNOME software platform through the use of GObject Introspection.
jeanconn/pygobject | | conda | linux-64
: None
pkgw/pygobject3 | 3.12.0 | conda | linux-64
: None
ska/pygobject | 2.20.0 | conda | linux-64
: Pipeline running tools
vgauthier/pygobject | 3.10.0 | conda | osx-64
: Python Bindings for GLib/GObject/GIO/GTK+
So how to know which one of those I need to install? I want the most up to date and stable one of course ... Some of them don't qualify, because they're not for my linux-64
system. I want to do a search, which only shows the ones available for my system, so I found some posts telling me, that this kind of search is possible on the Anaconda website itself entering the following in the search input field:
access:public platform:linux-64 pygobject
Now I see only 4 results and still don't know which one is most up to date, or which one I should use. the Anaconda website doesn't tell me when these repositories have been updated either. So I assume the one with the highest version number should be it. In fact I found a website, which states, that version PyGObject 3.14
is of 22 Sep 2014
or at least the post on that website is from that date.
I created the virtual environment without the pygobject argument:
conda create --name xld-attribute-value-adder python=3.4 pip setuptools
Then activated it:
source activate xld-attribute-value-adder
and then installed PyGObject
using:
conda install -c https://conda.anaconda.org/fallen pygobject
After that I changed the Project Interpreter
of this Project in my IDE PyCharm (yes I am using PyCharm for this project at the moment) to the Python 3.4
binary file of my newly created virtual environment:
(Project Directory)/bin/python3.4
Then I open a python file, which contains the line:
from gi.repository import Gtk
PyCharm does not find Gtk yet or has some other issue, so I needed to click the red underlined Gtk
and Alt+Enter
on it and choose to create binary stubs for it.
After all that it finally worked : )
精彩评论