From 1ed6b9f8493ecd65ae0a75c1d2fe1cfe63971ea9 Mon Sep 17 00:00:00 2001 From: Dejvino Date: Fri, 23 Oct 2020 22:03:00 +0200 Subject: [PATCH] example-tray-icon --- example-tray-icon/README.md | 14 +++++++++++++ example-tray-icon/tray.py | 39 +++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 example-tray-icon/README.md create mode 100755 example-tray-icon/tray.py diff --git a/example-tray-icon/README.md b/example-tray-icon/README.md new file mode 100644 index 0000000..33e0e5f --- /dev/null +++ b/example-tray-icon/README.md @@ -0,0 +1,14 @@ +# Tray Icon Notification +Shows a custom notification icon with a menu in the tray area of your desktop. + +## Dependencies +- Python +- GTK3 +- AppIndicator3 (libappindicator-gtk3) + +## Resources +- Source Tutorial: [Create a Custom System Tray Indicator For Your Tasks on Linux](https://fosspost.org/custom-system-tray-icon-indicator-linux/) +- Background on app indicators: [ApplicationIndicators](https://wiki.ubuntu.com/DesktopExperienceTeam/ApplicationIndicators) +- [Python GTK3 Tutorial](https://python-gtk-3-tutorial.readthedocs.io/en/latest/) +- [PyGObject](https://pygobject.readthedocs.io/en/latest/index.html) + diff --git a/example-tray-icon/tray.py b/example-tray-icon/tray.py new file mode 100755 index 0000000..08d07a7 --- /dev/null +++ b/example-tray-icon/tray.py @@ -0,0 +1,39 @@ +#!/usr/bin/python +import os +import gi + +gi.require_version('Gtk', '3.0') +gi.require_version('AppIndicator3', '0.1') + +from gi.repository import Gtk as gtk +from gi.repository import AppIndicator3 as appindicator + +def main(): + indicator = appindicator.Indicator.new("customtray", "semi-starred-symbolic", appindicator.IndicatorCategory.APPLICATION_STATUS) + indicator.set_status(appindicator.IndicatorStatus.ACTIVE) + indicator.set_menu(menu()) + gtk.main() + +def menu(): + menu = gtk.Menu() + + command_one = gtk.MenuItem(label='My Notes') + command_one.connect('activate', note) + menu.append(command_one) + + exittray = gtk.MenuItem(label='Exit Tray') + exittray.connect('activate', quit) + menu.append(exittray) + + menu.show_all() + return menu + +def note(_): + os.system("gvim $HOME/notes.txt") + +def quit(_): + gtk.main_quit() + +if __name__ == "__main__": + main() +