本文介绍了使用PyGObject自省编写MATE/GNOME小程序(Python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

So I have been trying to port a C GNOME applet to MATE, and after running into many different problems, I decided to rewrite it from scratch in python. Eventually, I found some not-horribly-out-of-date documentation, which is here: http://wiki.mate-desktop.org/docs:devel:mate-panel

显然,在python中编写applet的新方法是使用PyGObject自省,而不是旧的" PyGtk.

Apparently the new way of writing applets in python is to use PyGObject introspection, instead of the 'old' 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会话中,我得到警告:

in a python session, I get the warning:

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.另外,从gi.repository导入MatePanelApplet 运行也会产生ImportError 找不到MatePanelApplet 的任何类型库,即使我安装了libmatepanelapplet-dev.

Which pretty much answers Question 3, but then brings up Question 1 again. Also, running from gi.repository import MatePanelApplet gives an ImportError Could not find any typelib for MatePanelApplet even though I have libmatepanelapplet-dev installed.

再次我在这里找到了ImportError的解决方案:无法导入Webkit来自gi.repository .(只需安装 gir1.2-mate-panel 而不是webkit)

EDIT AGAIN: I found a solution to the ImportError here: Can't import Webkit from gi.repository. (Just install gir1.2-mate-panel instead of 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)

推荐答案

MATE是GNOME 2的分支,因此您应该使用PyGTK(作为获得的消息).

MATE is a fork of GNOME 2, therefore you should use PyGTK (as the message you got).

关于每个问题:

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

  1. PyGObject is better because you only need one single binding to a library (the one that provides introspection) and you get automatic access to the public API of every library that support GOBject Introspection. For developers is good because they have access to the same API than C without waiting the bindings for every new release.

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

Yes. But the user will likely have. The odds of GNOME 3 are 100%, with GNOME 2 (MATE) is less because it is not required.

它看起来不像是一个问题.如前所述,MATE是GNOME 2的一个,因此您必须使用GNOME 2可用的库和文档.

It does not look like a question. As I said previously, MATE is a for of GNOME 2, hence you have to use the libraries and documentation that is available for GNOME 2.

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

You can check applets that were written for GNOME 2 in Python (after GNOME dropped Bonobo). For instance, hasmter. You might need to change some names, likely in MATE renamed the library names from GNOME to MATE.

这篇关于使用PyGObject自省编写MATE/GNOME小程序(Python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-24 01:55