Ubuntu – Writing indicators with Python, GIR and GTK3

application-developmentindicatorpython

I'm writing an application that needs to use an indicator. I've done this in the past using PyGTK and GTK2, using as reference this document: https://wiki.ubuntu.com/DesktopExperienceTeam/ApplicationIndicators#Python_version

However, that only works with PyGTK and GTK2. Things have changed since then, and I need to find some good documentation, a tutorial or a good example to learn how it works.

Also, one thing that the previously mentioned document doesn't describe at all, is how to add sub-menus to an indicator. I hope someone can shed some light on this, as well as how to integrate with category indicators if that's done using the same tool.

Thanks.

Best Answer

This is my trial code for gtk3 and appindicator which creates a indicator for GPaste.

Basically,

from gi.repository import AppIndicator3 as AppIndicator

in order to use appindicator for gtk3 applications which is provided by package gir1.2-appindicator3.

Here is the AppIndicator3 documentation.

pygtk will be deprecated for Gtk3 and you have to go through GObject-Introspection route for developing Gtk3 applications in python. You can refer to PyGObject documentation. Instead of

import pygtk, gtk, gdk, gobject, pango  

etc you should do

from gi.repository import Gtk, Gdk, Pango, GObject  

For studying a working code, you could view Kazam which has moved to gtk3 from gtk2 and uses appindicator3.

There is a package gir1.2-appindicator as well which seems to be same as using python-appindicator as they both provide usage for gtk2 appplication which is:

from gi.repository import AppIndicator

OR

import appindicator

Some information in this blog post as well.