我也完全混淆了 PyObject、PyGTK 和 GNOME 3

发布于 2024-11-15 20:36:30 字数 1086 浏览 2 评论 0 原文

我安装了 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

短叹 2024-11-22 20:36:30

更新:这里有一些文档:Python GTK+ 3 教程。它仍然缺少与 GIO 等相关的任何内容。

这不是......呃,不可能......但因为你正在谈论最新一代的 GTK (&co) 绑定,所以事情肯定会有点落后。开发人员的工作主要针对实际开发,文档、示例等往往会晚得多。这就是自由软件的现实:/请记住,PyGI 最近也被合并到 PyGObject 中,因此历史记录中还存在另一个不连续性需要编辑。

所以我对你的回答是:

  1. 订阅 PyGTK/PyGObject 邮件列表,请求一些指导或参考资料或指导,然后从那里开始。与开发人员保持持续的联系确实是掌握最新情况的唯一方法。
  2. 将这一刻(以及那个人的面部表情)藏在你大脑的某个角落,这样当你跟上节奏时,你 - 是的,先生, - 可以写下其中一些内容并将其作为文档提交给下一个处于这种情况的不幸的人。

(就我个人而言,我迫不及待地想留出一些时间来尝试将一些东西与新的 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:

  1. 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.
  2. 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.)

病女 2024-11-22 20:36:30

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.

骑趴 2024-11-22 20:36:30

尽管
导入pygtk
pygtk.require('2.0')
它们是在内省中编写的,如果您注释掉 pygtk 导入,它们仍然会运行,我怀疑这只是一个疏忽,我最近花了相当多的时间尝试移植一些东西,

告诉我们代码如何导入 gtk 本身

#import pygtk
#pygtk.require('2.0')
from gi.repository import Gtk, GLib, GObject, GdkPixbuf, Gio, Pango

意味着它使用内省,如果代码用大写 G 做 gtk 的事情,那么它肯定也是内省:)
例如

#a pygtk window
awindow = gtk.Window()
#an introspection window
awindow = Gtk.Window()

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()
赏烟花じ飞满天 2024-11-22 20:36:30

我现在开发 GTK+ 应用程序的方法是从 Anaconda3 >here 然后使用以下命令创建一个新的虚拟环境:(

conda create --name xld-attribute-value-adder python=3.4 pip setuptools pygobject

我添加了 pipsetuptools 因为 virtualenv 用于在创建时添加它们我知道我可以使用虚拟环境。 pip 用于安装软件包,但 setuptools 的名称暗示它可以使用或用于类似的用途。)

然后 Anaconda 告诉我,它找不到 PyGObject,我可以使用 binstar (太棒了,另一个要记住的工具!)来搜索它,如下所示:

binstar search -t conda pygobject

但是,这会产生多个搜索结果:

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+

那么如何知道我需要其中哪一个 安装?当然,我想要最新且稳定的版本...其中一些不符合条件,因为它们不适合我的 linux-64 系统。我想做一个搜索,它只显示我的系统可用的搜索,所以我发现一些帖子告诉我,这种搜索可以在 Anaconda 网站本身在搜索输入字段中输入以下内容:

access:public platform:linux-64 pygobject

现在我只看到 4 个结果,但仍然不知道哪一个是最新的,或者我应该使用哪一个。 Anaconda 网站也没有告诉我这些存储库何时更新。所以我认为版本号最高的应该是它。事实上,我找到了一个网站,其中指出版本 PyGObject 3.142014 年 9 月 22 日 或至少是关于 网站 是从该日期开始的。

我创建了没有 pygobject 参数的虚拟环境:

conda create --name xld-attribute-value-adder python=3.4 pip setuptools

然后激活它:

source activate xld-attribute-value-adder

然后安装 PyGObject 使用:

conda install -c https://conda.anaconda.org/fallen pygobject

之后我在 IDE PyCharm 中更改了该项目的 Project Interpreter (是的我目前在这个项目中使用 PyCharm)到我新创建的虚拟环境的 Python 3.4 二进制文件:

(Project Directory)/bin/python3.4

然后我打开一个 python 文件,其中包含以下行:

from gi.repository import Gtk

PyCharm 还没有找到 Gtk或者有其他问题,所以我需要单击红色下划线的 Gtk 和 Alt+Enter 并选择为其创建二进制存根。

毕竟它终于成功了:)

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 : )

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文