Skip to content

Instantly share code, notes, and snippets.

@palto42
Last active August 27, 2023 09:05
Show Gist options
  • Save palto42/7f19d8c7b5b0ee680c9aa8256b7afbbd to your computer and use it in GitHub Desktop.
Save palto42/7f19d8c7b5b0ee680c9aa8256b7afbbd to your computer and use it in GitHub Desktop.
Short Python3 appindicator demo
# Appindicator Demo
import sys
from gi import require_version
require_version("Gtk", "3.0")
require_version("AyatanaAppIndicator3", "0.1")
require_version("Notify", "0.7")
from gi.repository import AyatanaAppIndicator3 as appindicator
from gi.repository import Gtk as gtk
from gi.repository import Notify
def exit_menu(self):
sys.exit(0)
def hello(_):
# notify_icon = "info"
# Full path icon is not correctly shown, instead a mail icon is displayed
notify_icon = "/usr/share/icons/hicolor/48x48/places/start-here-solus.png"
Notify.Notification.new("Message", "Hello World!", notify_icon).show()
if __name__ == "__main__":
# Full path icon doesn't work
icon = "/usr/share/icons/hicolor/48x48/places/distributor-logo-solus.png"
# icon = "/usr/share/icons/hicolor/scalable/places/start-here-solus.svg"
# Using generic icon works
# icon = "tray-new-im"
indicator = appindicator.Indicator.new("My Menu", icon, appindicator.IndicatorCategory.APPLICATION_STATUS)
indicator.set_status(appindicator.IndicatorStatus.ACTIVE)
Notify.init("My Menu")
menu = gtk.Menu()
hello_msg = gtk.MenuItem(label="Hello")
hello_msg.connect("activate", hello)
hello_msg.show()
menu.append(hello_msg)
exit_app = gtk.MenuItem(label="Exit")
exit_app.connect("activate", exit_menu)
exit_app.show()
menu.append(exit_app)
menu.show()
indicator.set_menu(menu)
gtk.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment