Ubuntu – How to program a status icon that will display in Ubuntu as well as in other distributions

appletapplication-developmentdevelopmentindicatorpython

The application in question does some action (here connecting audio to network streams) and runs minimized if these actions were successful. Therefore a status icon is needed to display the state of the connection (e.g. CONNECTED/DISCONNECTED). Only when clicking the icon the application window will open to give access to further options.

Using Python 2.6 and pyGtk I conveniently realised this by using gtk_status_icon. I deliberately wrote the application to run on as many distributions as possible including the various Ubuntu versions. I took care to use possible dependencies only after the user had installed them.

However now I hear that gtk_status_icon will no longer be supported in future Ubuntu releases. Developers are asked to use Application Indicators instead. What is then best practise to make sure that:

  1. The application's local icons are displayed properly
  2. The application will still run and display it's icons in future Ubuntu releases.
  3. The application will also run and display it's icons in other environments where indicator-applet, libappindicator, and python-appindicator are not provided.

Application Indicator fallback mechanisms to gtk_status_icon won't work if indicator-applet is not running. Python interpreters will not run if there was no appindicator module to import from. Do I need to develop different versions for different distributions or is there a better way to come around this.

Where do I find a documentation on how to use ApplicationIndicator other than in the example given in Ubuntu Wiki? What commands are provided to check if indicator-applet is running to avoid programming different source codes for Ubuntu vs. non-Ubuntu distributions?

Best Answer

I think that the need here is actually more determining of the python-appindicator library is present. If it is present, it will support all the fallback cases that you need. It will handle XFCE, KDE and older GNOME appropriately. Good example of how to do it in this answer.

The appindicator library will use DBus to check if the application indicator rendering process is available. This will be the case on Unity, or if the indicator-applet is running. If it is available it will use that, if not, it will fallback to using a GtkStatusIcon with the same menu.

Unfortunately, I believe you'd have to keep both code paths if you want to handle the case of the library not being available. Though, we'd be happy to help get the library in other distros :)

Related Question