Recently I’ve updated TheTool to support also AppIndicator3 interface so it can show icon in Unity panel. Although the documentation is not saying it, you can use absolute path to PNG image as icon-name ( apart of stock icon name). I was trying to add application specific stock icons, but is somehow did not work well (only possibility is to use xdg-icon-resource install --novendor --size 32 picture.png icon-name
, but python code for creating application specific icons with Gtk.IconFactory was not working for me – see this post on stackoverflow). And here is some snippet how to use AppIndicator3:
try: from gi.repository import AppIndicator3 # @UnresolvedImport HAS_INDICATOR=True except: HAS_INDICATOR=False class Indicator(object): def __init__(self, menu): self.ind = AppIndicator3.Indicator.new ( "thetool", "", AppIndicator3.IndicatorCategory.APPLICATION_STATUS) self.ind.set_status (AppIndicator3.IndicatorStatus.ACTIVE) self.ind.set_icon(os.path.join(_curr_dir, 'pics', 'tools.png')) self.ind.set_attention_icon (os.path.join(_curr_dir, 'pics', 'tools-active.png')) self.ind.set_menu(menu) def set_labelt(self, txt): self.ind.set_label(txt, txt) def set_attention(self, attention): if attention: self.ind.set_status (AppIndicator3.IndicatorStatus.ATTENTION) else: self.ind.set_status (AppIndicator3.IndicatorStatus.ACTIVE)
For platform that do not have AppIndicator3, you can still alternatively use Gtk.StatusIcon, which provides similar possibilities – here in GitHub is example – a factory function creates duck-typed wrapper – which uses either AppIndicator3 or Gtk.StatusIcon – according to what is available.