I'm completly confused with PyObject, PyGTK and GNOME 3 as well
我安装了Fedora 15以使用Python3和GObject开发桌面应用程序,因为PyGTK看起来已经过时了:
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. [...]
资料来源:http://www.pygtk.org/
我以为罢工! 使用Python 3和PyGObject开发新的Gnome3应用程序!
我访问了PyGObject页面,发现最新的稳定版本是2.28(自2.26开始支持Python3),该版本安装在Fedora上,但仅使用python2绑定。
有没有搞错?
我在站点上访问了PyGobject演示和示例,并查看了源代码,其中的每个代码都使用pygtk + pygtk.require('2.0')而不是pygobject。
我想念什么吗? 如何使用Python3和PyGObject开发Gnome 3应用程序?
更新:这里有一些文档:Python GTK + 3教程。它仍然缺少与GIO等有关的任何信息。
不是……不是不可能,但是……因为您在谈论最新一代的GTK(&co)绑定,所以事情肯定会落后一些。开发人员的工作主要是针对实际的开发,而文档,示例等往往会在以后很晚才赶上。这就是自由软件的现实:/请记住,PyGI也是最近才合并到PyGObject中的,因此编辑历史数据还有另一个不连续之处。
所以我对你的回答是:
(就我个人而言,我迫不及待地想花一些时间来尝试将新API与某些东西放在一起,但是我试图推迟直到Gnome 3进入Debian。我热切地等待在脸上戴这样的表情。)
developer.gnome.org上的平台演示完全用GTK 3和GNOME 3编写。目前,只有两个可用于Python,其他尚未翻译,但这应该可以帮助您入门。
不幸的是,即使在GTK 3变得司空见惯之后的几年,您仍然会在网上在线学习PyGTK 2教程,因为人们会以一种充满热情的方式编写它们,而不再更新它们。没人会拒绝它们,因为其中可能仍然包含有价值的材料,您只需更改X,Y和Z即可使其与GTK 3配合使用。这就是为什么仍然可以找到C教程的原因在线GTK 1.2。
因此,如果您找到PyGTK 2的教程,则最好向托管它的任何人写一封电子邮件,告诉他们它已过时。更好的是,更新GTK 3教程并向他们发送新版本!毕竟,它是开源的。
尽管
导入pygtk
pygtk.require('2.0')
它们是内省的,如果您注释掉它们仍在运行的pygtk导入,我怀疑它只是一个疏忽,我最近花了很多时间尝试移植某些内容
告诉方法是代码如何导入gtk本身
1 2 3 | #import pygtk #pygtk.require('2.0') from gi.repository import Gtk, GLib, GObject, GdkPixbuf, Gio, Pango |
表示如果代码使用大写G进行gtk事情,则使用自省,那么它也将进行自省:)
例如
1 2 3 4 | #a pygtk window awindow = gtk.Window() #an introspection window awindow = Gtk.Window() |
我现在开发
1 | conda create --name xld-attribute-value-adder python=3.4 pip setuptools pygobject |
(我添加了
然后
1 | binstar search -t conda pygobject |
但是,这会导致多个搜索结果:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 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+ |
那么如何知道我需要安装哪一个呢?我当然想要最新,最稳定的一款...其中有些没有资格,因为它们不适合我的
1 | access:public platform:linux-64 pygobject |
现在,我只看到4个结果,但仍然不知道哪个是最新的,还是应该使用哪个。 Anaconda网站也不会告诉我这些存储库何时更新。因此,我认为版本号最高的应该是它。实际上,我发现了一个网站,该网站指出版本
我创建了没有pygobject参数的虚拟环境:
1 | conda create --name xld-attribute-value-adder python=3.4 pip setuptools |
然后激活它:
1 | source activate xld-attribute-value-adder |
然后使用以下命令安装
1 | conda install -c https://conda.anaconda.org/fallen pygobject |
之后,我在IDE PyCharm中将该项目的
1 | (Project Directory)/bin/python3.4 |
然后,我打开一个python文件,其中包含以下行:
1 | from gi.repository import Gtk |
PyCharm尚未找到Gtk或存在其他问题,因此我需要单击红色的带下划线的
毕竟它终于工作了:)