使用PyGObject自省编写MATE/GNOME Applets(Python)

2024-09-28 18:58:48 发布

您现在位置:Python中文网/ 问答频道 /正文

因此,我一直在尝试将一个C GNOME applet移植到MATE中,在遇到许多不同的问题后,我决定用python从头重写它。最后,我找到了一些不堪重负的过时文档,在这里:http://wiki.mate-desktop.org/docs:devel:mate-panel

显然,用python编写applet的新方法是使用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.

编辑:如果我跑

^{pr2}$

在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。另外,运行from gi.repository import MatePanelApplet会产生一个ImportError Could not find any typelib for MatePanelApplet,即使我已经安装了libmatepanelapplet dev。在

再次编辑:我在这里找到了解决这个问题的方法: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)

Tags: andtheto方法orghttpgtkis
1条回答
网友
1楼 · 发布于 2024-09-28 18:58:48

MATE是gnome2的分支,因此您应该使用PyGTK(作为您得到的消息)。在

关于每个问题:

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

  2. 是的。但用户很可能会有。侏儒3号的几率是100%,而侏儒2号(伴侣)的几率较小,因为它不是必需的。

  3. 这看起来不像是个问题。如前所述,MATE是gnome2的for,因此您必须使用gnome2可用的库和文档。

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

相关问题 更多 >