Ubuntu app indicators when using PyGObject

PyGObject and the Python appindicator module don’t agree with each other. As soon as I import “appindicator”, all objects from the gi.repository.Gtk namespaces seem to reset to what might be PyGTK, not sure. However, with gir1.2-appindicator-0.1 (on Natty) installed , you can do:

from gi.repository import AppIndicator

ind = AppIndicator.Indicator.new(
            "send-to-kindle",
            "indicator-messages",
            AppIndicator.IndicatorCategory.APPLICATION_STATUS)

self.menu = Gtk.Menu()
item = Gtk.MenuItem()
item.set_label("Menu Item")
item.show()
self.menu.append(item)

self.menu.show()
ind.set_menu(self.menu)

Note that there is a gir1.2-appindicator3-0.1 package in Natty, which provides a AppIndicator3 object, which seems to be the GTK3 version, and pulls a bunch of GTK dependencies. After installing it on Natty, I was seemingly unable to work with GTK2 in PyGObject, so be careful (uninstalling the GTK3 packages fixed it). Jockey (the “Additional Drivers” tool) is using AppIndicator3, and from looking at the source, AppIndicator3 works without attaching a menu to it. Apparently Canonical still gets some things right.

Update 2012-04-10: In order to make my app work with both Gtk3 (Oneiric) and Gtk2 (Natty), I am now using this code:

try:
   from gi.repository import AppIndicator3 as AppIndicator
except:
   from gi.repository import AppIndicator

1 thought on “Ubuntu app indicators when using PyGObject

Leave a comment