From adccf133e12f25b31d8ffc3cf68f53b06c4be974 Mon Sep 17 00:00:00 2001 From: Abhorrent_Anger Date: Mon, 28 Oct 2019 15:09:55 +0200 Subject: [PATCH] Mute toggling --- README.md | 2 +- eyestrainreminder/__main__.py | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 9d42cfc..528e81b 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ First, you might need these packages: sudo apt-get install python-gobject libnotify-bin python-gst-1.0 ``` -Second, just install the tool and required [Python modules](src/branch/master/setup.py) via: +Second, just install the tool and required [Python modules](setup.py) by cloning the repository and running: ``` cd EyeStrainReminder pip install . --user diff --git a/eyestrainreminder/__main__.py b/eyestrainreminder/__main__.py index b43a9ba..5972269 100755 --- a/eyestrainreminder/__main__.py +++ b/eyestrainreminder/__main__.py @@ -14,26 +14,33 @@ MILLISECOND = 1000 MINUTE = 60 DIR = os.path.dirname(os.path.abspath(__file__)) +icon = None mute = False +disable_notifications = False -def set_mute(): +def toggle_mute(): global mute - mute = True + mute = True if not mute else False + update_menu() -def generate_menu_items(): +def generate_menu_items(): menu_items = [] if not mute: - menu_items.append(item('Mute', set_mute)) + menu_items.append(item('Mute', toggle_mute)) else: - menu_items.append(item('Unmute', set_mute)) + menu_items.append(item('Unmute', toggle_mute)) return menu_items +def update_menu(): + global icon + icon.menu = generate_menu_items() + icon.update_menu() + def init(): + global icon image = Image.open(f"{DIR}/files/eye_light.png") icon = pystray.Icon(NAME, image, NAME, generate_menu_items()) icon.run() - - print("Initializing EyeStrainReminder...") notify2.init(NAME)