Writing MATE / GNOME applets (Python) with PyGObject introspection

So, I am trying to port the C GNOME applet to MATE, and faced with many different problems, I decided to rewrite it from scratch to python. In the end, I found the not-so-terribly outdated documentation, which is located here: http://wiki.mate-desktop.org/docs:devel:mate-panel

Apparently, the new way to write applets in python is to use the introspection of PyGObject, rather than 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 a 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 raises question 1. Again, running from gi.repository import MatePanelApplet gives ImportError Could not find any typelib for MatePanelApplet , although I have libmatepanelapplet-dev installed.

EDIT AGAIN: I found a solution for ImportError here: Unable to 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) 
+4
source share
1 answer

MATE is a GNOME 2 fork, so you should use PyGTK (as a received message).

Regarding each question:

  • PyGObject is better because you only need one library binding (one that provides introspection), and you get automatic access to the public API of each library that supports GOZject Introspection. This is good for developers because they have access to the same API as C, without waiting for a binding for each new version.

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

  • This is not like a question. As I said earlier, MATE is for GNOME 2, so you should use the libraries and documentation available for GNOME 2.

You can check the applets that were written for GNOME 2 in Python (after GNOME Bonobo crashed). For example, hasmter . You may need to change some names, probably in MATE renamed library names from GNOME to MATE.

+3
source

All Articles