Using the application indicator in Python

Yesterday, during the second day of Ubuntu Developer Week, Ted Gould gave a great presentation of the application indicator that will be present in Lucid Lynx. Here I will show you how to use it in your applications with a small application I wrote very quickly.

This application shows a Debian logo in the panel and gives you access to essential documents for packagers and developers : The Debian FAQ, the Developer Reference, the Maintainer’s guide and the Debian Policy. You can fetch it on the project’s page or on my PPA.

Ok, let’s start digging in. First thing to do when you want to use libindicator in your Python applications is to install the python-appindicator package (I assume that you are running Lucid Lynx). Once this is done import the module in your program :

import appindicator

In the body of your program create a Indicator object

ind = appindicator.Indicator ("debian-doc-menu","debian-swirl", appindicator.CATEGORY_APPLICATION_STATUS)

You instantiate an indicator object with 3 parameters, first an unique identifier for your app, then an icon (you can pick any stock icon from your icon theme) and finally a category that will tell libindicate where to place the icon in the panel.
You have 5 categories to choose from :


As you can see, the names are self explanatory.
Then you set the status of your indicator :

ind.set_status (appindicator.STATUS_ACTIVE)

Again you have 3 statuses to choose from :

  • STATUS_PASSIVE : The icon is hidden
  • STATUS_ACTIVE : The icon is visible
  • STATUS_ATTENTION : The icon changes to the attention icon, requesting some kind of interaction with the user

You can set the attention icon with :

ind.set_attention_icon ("indicator-messages-new")

Then you’re likely to want to attach a menu to this icon, it’s a standard Gtk Menu :

menu = gtk.Menu()
faq_item = gtk.MenuItem("Debian FAQ")
faq_item.connect("activate", faq_clicked)

You attach the menu with :


Of course you have to write some actions for the menu :

def faq_clicked(widget,data=None):
    os.system("evince /usr/share/doc/debian/FAQ/debian-faq.pdf.gz &")

And you’re done ! Run the gtk.main() and you got your AppIncidator running.

Next thing to do is to find an application using a legacy “systray” icon and propose a patch to the developers, maybe Parcellite would be a good start, it would be a good way to show how it’s done in a C project.

Tagged with:


  1. jorge says:

    Here’s the Current List of Bugs of applications that need to be ported. There are lots of apps that can be ported, feel free to just add it to the list! Let me know if you need a hand!

  2. raph says:

    Your blog’s very promising. Though, you should perhaps pay attention to the way your lines of code are formatted (via css) : reading and understanding python will be easier for your audience if they can see the end of the line :)

    – on my firefox 3.6 the following line gets truncated :
    ind = appindicator.Indicator (“debian-doc-menu”,”debian-swirl”, appindicator.CATEGORY_APPLICATION_STATUS)

  3. Brian Jain says:

    Cool Thanks for your article. I am starting python and this will be a big help.

  4. Owais Lone says:

    How do I set a custom PNG icon?

  5. Serrano says:

    Thanks you very much for this tutorial. I was wondering for quite some time how to do this, but this got me on track real fast. I just gave a Python app I was working on a nice indicator icon. And you bet I will send in some patches for my favorite apps.

  6. [...] Mutt, so I just wanted a simple indicator to check my Maildir. So I did some googling and found some examples of indicator applets in Python, and coded up as simple applet. [...]

  7. Pseudomino says:

    Hi, thanks for yout post that helped me to understand a little bit how these indicator work.

    I was wondering : you say
    “Then you’re likely to want to attach a menu to this icon, it’s a standard Gtk Menu :”
    what if I actually don’t want a menu ? is there a way to have a mere launcher ?
    Trying to do that, I get no indicator at all.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Get Adobe Flash player