Score:1

Add an Icon to the Top Bar using AppIndicator3

cr flag

I want to create a time counter that gets added to the top bar in Ubuntu (GNOME Shell 42.9).

I am trying to add an icon first, but it doesn't get added. I also installed all necessary dependencies and restarted the computer.

import signal
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('AppIndicator3', '0.1')
from gi.repository import Gtk, AppIndicator3, GLib

APPINDICATOR_ID = 'custom_indicator'
CUSTOM_ICON_PATH = '/home/afranz/Desktop/ActiveTime/activity_counter_app/icon.svg'

class CustomIndicator:
    def __init__(self):
        self.indicator = AppIndicator3.Indicator.new(
            APPINDICATOR_ID, CUSTOM_ICON_PATH, AppIndicator3.IndicatorCategory.APPLICATION_STATUS
        )
        self.indicator.set_status(AppIndicator3.IndicatorStatus.ACTIVE)

    def run(self):
        Gtk.main()

def main():
    gi.require_version('Gtk', '3.0')
    gi.require_version('AppIndicator3', '0.1')
    
    app = CustomIndicator()
    signal.signal(signal.SIGINT, signal.SIG_DFL)  # Allow Ctrl+C to exit the application
    app.run()

if __name__ == '__main__':
    main()

I am also not getting any error when running this.

The path is correct, I am using Python 3.10.12 and Ubuntu 22.04.3 LTS.

I also enabled this GNOME extension (since legacy tray icons seem to be disabled by default with modern GNOME versions).

Also, I am not constrained to use AppIndicator for any reason, it's just the common solution I saw while researching online about how to "add stuff to the top bar in Ubuntu".

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.