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 :
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 :
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 :
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) faq_item.show() menu.append(faq_item)
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: lucid • Python • Ubuntu