Application Indicators In Python

220
Article Source jonobacon@home
December 16, 2009, 5:48 pm

I am really excited to see Ted’s post regarding some of the improvements coming to the desktop notification area. This part of our desktop has become something of a wild west – icons look ugly, are spaced too close together, have left/right click inconstancy, often provide obscure and inaccessible widgets and cannot be easily controlled across notification icons with a single keyboard shortcut. This approach will fix many of these issues.

This approach has two distinctive components – the user interface improvements and the technology to implement. The user interface changes I think are really interesting and bring some distinctive benefits:

  • Application indicators are more consistent ‚Äì no more left and right-click inconsistency. Always left click to see the items.
  • Scrubbing ‚Äì you can click once on an app indicator and scrub left and right through other indicators with your mouse.
  • More accessible ‚Äì importantly, scrubbing also applies to the keyboard: this means you could bind a key to the indicator applet, hit that key and then use the arrow keys to navigate through all the indicators.
  • Themable panel icons ‚Äì you can set a specific icon to be a panel icon for an indicator: this should make it easier for creating single colour panel icons for light and dark themes.
  • KDE/GNOME compatability ‚Äì one thing that really excites me is that by using this spec, KDE applications running in GNOME will have their application notification menus rendered with GTK widgets and vice-versa.

I am really excited about the opportunities this brings to the desktop, and I am also really excited about us working with our friends in KDE on this spec.

I wanted to give this a roll in my more native Python tongue so I added the Karmic PPA and started playing with the module. I contributed my code as an example on the wiki. Here it is to show how it works:

import gobject import gtk import appindicator  if __name__ == "__main__":     ind = appindicator.Indicator ("example-simple-client", "indicator-messages", appindicator.CATEGORY_APPLICATION_STATUS)     ind.set_status (appindicator.STATUS_ACTIVE)     ind.set_attention_icon ("indicator-messages-new")      # create a menu     menu = gtk.Menu()      # create some labels     for i in range(3):         buf = "Test-undermenu - %d" % i      menu_items = gtk.MenuItem(buf)      menu.append(menu_items)      # this is where you would connect your menu item up with a function:      # menu_items.connect("activate", self.menuitem_response, buf)      # show the items     menu_items.show()      ind.set_menu(menu)      gtk.main() 

I basically created an indicator object and threw a GTK menu into it and as if by magic my app appeared in the notification panel, properly spaced out and enjoying the benefits I mentioned above. Pretty simple.