问题
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
Apparently the new way of writing applets in python is to use PyGObject introspection, instead of the 'old' PyGtk.
So I have a few questions:
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.
EDIT: If I run
import gi
gi.require_version("Gtk", "2.0")
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
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.
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)
And more errors:
./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)
回答1:
MATE is a fork of GNOME 2, therefore you should use PyGTK (as the message you got).
Regarding to each question:
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.
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.
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.
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.
来源:https://stackoverflow.com/questions/14006512/writing-mate-gnome-applets-python-with-pygobject-introspection