I'm writing a small Python 3 app which uses AppIndicator3
to place an icon in the top bar, and then change that icon in response to user actions. Simple, right? Because the app is small, it needs to run from its source directory without any kind of installation.
The problem is that AppIndicator3.set_icon()
requires a str
with an icon name, not a path to said icon.
How can I persuade AppIndicator3 to let me give it either a filename or a Pixbuf
? Alternatively, how can I add my icon directory to the icon name search path? (I tried AppIndicator3.set_icon_theme_path()
, but my icon names are still unrecognized.
To use a path to the icon is best illustrated with an example. In the example below, I keep the icons in the same directory as the script (indicator), which seems a convenient solution in your case.
The bottom line is that once you initiated your indicator:
you can change the icon with:
Example
In the example below, all icons,
nocolor.png
,purple.png
andgreen.png
are stored together with the script, but the path to the icons, set incould be anywhere.
Note
...that if you need to update the icon from a second thread, you need to use
before
and you need to update the interface (either icon or indicator text) by using:
as applied e.g. here and here.