AppIndicator3 – how to use custom icons

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:

    from gi.repository import AppIndicator3  # @UnresolvedImport

class Indicator(object):    
    def __init__(self, menu):
        self.ind = (
        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'))

    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)
            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.

Leave a Reply

Your email address will not be published. Required fields are marked *