【问题标题】:Writing MATE/GNOME Applets (Python) with PyGObject Introspection使用 PyGObject Introspection 编写 MATE/GNOME 小程序 (Python)
【发布时间】:2012-12-22 20:55:56
【问题描述】:

所以我一直在尝试将 C GNOME 小程序移植到 MATE,在遇到许多不同的问题后,我决定用 python 从头开始​​重写它。最终,我找到了一些过时的文档,这里是:http://wiki.mate-desktop.org/docs:devel:mate-panel

显然,在 python 中编写小程序的新方法是使用 PyGObject 内省,而不是“旧”PyGtk。

所以我有几个问题:

1. Why is it better to use PyGObject instead of PyGtk etc
2. Is the end user who downloads a python applet expected to have pygobject installed? It looks like it.
3. The MATE documentation says 'ensure we are using Gtk 2, not Gtk3', but http://python-gtk-3-tutorial.readthedocs.org/en/latest/install.html says that its exclusively supports Gtk+ 3 and higher.

编辑:如果我运行

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

在 python 会话中,我收到警告:

RuntimeWarning: You have imported the Gtk 2.0 module.  Because Gtk 2.0 was not designed for use with introspection some of the interfaces and API will fail.  As such this is not supported by the pygobject development team and we encourage you to port your app to Gtk 3 or greater. PyGTK is the recomended python module to use with Gtk 2.0

这几乎回答了问题 3,但随后又提出了问题 1。此外,即使我安装了 libmatepanelapplet-dev,运行 from gi.repository import MatePanelApplet 也会出现 ImportError Could not find any typelib for MatePanelApplet

再次编辑:我在这里找到了 ImportError 的解决方案:Can't import Webkit from gi.repository。 (只需安装 gir1.2-mate-panel 而不是 webkit)

还有更多错误:

./xmonad-log-applet.py:66: Warning: g_closure_set_marshal: assertion `closure != NULL' failed
  applet = MatePanelApplet.Applet()

(xmonad-log-applet.py:10928): GLib-GIO-CRITICAL **: g_dbus_connection_register_object: assertion `G_IS_DBUS_CONNECTION (connection)' failed
Segmentation fault (core dumped)

【问题讨论】:

    标签: python gnome pygobject mate-desktop


    【解决方案1】:

    MATE 是 GNOME 2 的一个分支,因此您应该使用 PyGTK(作为您收到的消息)。

    关于每个问题:

    1. PyGObject 更好,因为您只需要一个与库(提供自省的库)的绑定,并且您可以自动访问每个支持 GOBject 自省的库的公共 API。对开发人员来说很好,因为他们可以访问与 C 相同的 API,而无需等待每个新版本的绑定。

    2. 是的。但用户很可能会有。 GNOME 3 的几率是 100%,而 GNOME 2 (MATE) 的几率更低,因为它不是必需的。

    3. 这看起来不像一个问题。正如我之前所说,MATE 是 GNOME 2 的一个版本,因此您必须使用适用于 GNOME 2 的库和文档。

    您可以检查用 Python 为 GNOME 2 编写的小程序(在 GNOME 删除 Bonobo 之后)。例如,hasmter。您可能需要更改一些名称,可能在 MATE 中将库名称从 GNOME 重命名为 MATE。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-15
      • 2011-08-30
      • 2015-05-01
      • 2019-02-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多