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:
- The application's local icons are displayed properly
- The application will still run and display it's icons in future Ubuntu releases.
- 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?
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 :)
I have an excellent solution that has worked well in StackApplet - I created a functionally-equivalent version of the
appindicator
module that usesgtk.StatusIcon
internally to provide identical functionality when the real module does not exist.Using it is as simple as:
appindicator_replacement.py
Adding the following to your application:
That's it! Now your application will run perfectly with or without support for AppIndicators. It will even run on Windows, assuming you don't have any other platform-specific code.
Note: the file is released under the MIT license - so you can use it pretty much for anything.
You will need to write code for both. You can detect the presence of appindicator in your Python code using something similar to:
From there, use have_appindicator to decide whether you should use appindicator code or gtk_status_icon code.
Unfortunately, this also means you will need to have both an Ubuntu and another environment to test with.
This way you can detect if indicator applet is running. You don't need to worry about Ubuntu 11.04 because this won't be the case. There are no fallback scenario because indicator-applet is a mandatory component, running by default.