我安装了 Fedora 15 来使用 Python3 和 GObject 来开发桌面应用程序,因为 PyGTK 看起来已经过时了:
PyGTK 2.24.0 发布
2011 年 4 月 1 日星期五作者:Rafael Villar Burke
PyGTK 2.24.0 已发布。这是一个支持 GTK+ 2.24 API 的稳定版本。
建议希望使用 GTK+ 开发 Python 应用程序的新用户使用 PyGObject 中提供的 GObject-Introspection 功能。[...]
PyGobject 2.26.0已发布。 这是 2.26.x 系列中的第一个稳定版本,引入了对内省和 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 应用程序?
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 visited 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?
发布评论
评论(4)
更新:这里有一些文档:Python GTK+ 3 教程。它仍然缺少与 GIO 等相关的任何内容。
这不是......呃,不可能......但因为你正在谈论最新一代的 GTK (&co) 绑定,所以事情肯定会有点落后。开发人员的工作主要针对实际开发,文档、示例等往往会晚得多。这就是自由软件的现实:/请记住,PyGI 最近也被合并到 PyGObject 中,因此历史记录中还存在另一个不连续性需要编辑。
所以我对你的回答是:
(就我个人而言,我迫不及待地想留出一些时间来尝试将一些东西与新的 API 结合在一起,但我试图推迟到 Gnome 3 出现在 Debian 中。我热切地等待在我的 脸。)
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:
(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.)
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 教程并向他们发送新版本!毕竟,它是开源的。
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.
尽管
导入pygtk
pygtk.require('2.0')
它们是在内省中编写的,如果您注释掉 pygtk 导入,它们仍然会运行,我怀疑这只是一个疏忽,我最近花了相当多的时间尝试移植一些东西,
告诉我们代码如何导入 gtk 本身
意味着它使用内省,如果代码用大写 G 做 gtk 的事情,那么它肯定也是内省:)
例如
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
means its using introspection if code does gtk things with a capital G then its definately introspection too :)
for example
我现在开发
GTK+
应用程序的方法是从 Anaconda3 >here 然后使用以下命令创建一个新的虚拟环境:(我添加了
pip
和setuptools
因为virtualenv
用于在创建时添加它们我知道我可以使用虚拟环境。pip
用于安装软件包,但setuptools
的名称暗示它可以使用或用于类似的用途。)然后
Anaconda
告诉我,它找不到PyGObject
,我可以使用binstar
(太棒了,另一个要记住的工具!)来搜索它,如下所示:但是,这会产生多个搜索结果:
那么如何知道我需要其中哪一个 安装?当然,我想要最新且稳定的版本...其中一些不符合条件,因为它们不适合我的
linux-64
系统。我想做一个搜索,它只显示我的系统可用的搜索,所以我发现一些帖子告诉我,这种搜索可以在 Anaconda 网站本身在搜索输入字段中输入以下内容:现在我只看到 4 个结果,但仍然不知道哪一个是最新的,或者我应该使用哪一个。 Anaconda 网站也没有告诉我这些存储库何时更新。所以我认为版本号最高的应该是它。事实上,我找到了一个网站,其中指出版本
PyGObject 3.14
是2014 年 9 月 22 日
或至少是关于 网站 是从该日期开始的。我创建了没有 pygobject 参数的虚拟环境:
然后激活它:
然后安装
PyGObject
使用:之后我在 IDE PyCharm 中更改了该项目的
Project Interpreter
(是的我目前在这个项目中使用 PyCharm)到我新创建的虚拟环境的Python 3.4
二进制文件:然后我打开一个 python 文件,其中包含以下行:
PyCharm 还没有找到 Gtk或者有其他问题,所以我需要单击红色下划线的 Gtk 和 Alt+Enter 并选择为其创建二进制存根。
毕竟它终于成功了:)
What I did now to develop a
GTK+
Application is to download and installAnaconda3
from here and then create a new virtual environment using:(I added
pip
andsetuptools
becausevirtualenv
used to add them when creating a virtual environment. I know I can usepip
for installing packages, butsetuptools
's name implies it can be used or is used for something similar.)Then
Anaconda
tells me, that it cannot findPyGObject
and that I can search for it usingbinstar
(great, another tool to keep in mind!) as follows:However, that results in multiple search results:
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: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 of22 Sep 2014
or at least the post on that website is from that date.I created the virtual environment without the pygobject argument:
Then activated it:
and then installed
PyGObject
using: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 thePython 3.4
binary file of my newly created virtual environment:Then I open a python file, which contains the line:
PyCharm does not find Gtk yet or has some other issue, so I needed to click the red underlined
Gtk
andAlt+Enter
on it and choose to create binary stubs for it.After all that it finally worked : )