Added "Exit" functionality
This commit is contained in:
parent
5e7d11470e
commit
f9037c8acd
|
@ -8,7 +8,7 @@ import notify2
|
||||||
import pystray
|
import pystray
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from playsound import playsound
|
from playsound import playsound
|
||||||
from pystray import MenuItem as item
|
from pystray import Menu as menu, MenuItem as item
|
||||||
|
|
||||||
NAME = 'Eye Strain Reminder'
|
NAME = 'Eye Strain Reminder'
|
||||||
MESSAGE = 'Friendly reminder to observe the 20-20-20 rule'
|
MESSAGE = 'Friendly reminder to observe the 20-20-20 rule'
|
||||||
|
@ -29,7 +29,7 @@ def create_tray_icon():
|
||||||
image = get_image()
|
image = get_image()
|
||||||
icon = pystray.Icon(NAME, image, NAME, generate_menu_items())
|
icon = pystray.Icon(NAME, image, NAME, generate_menu_items())
|
||||||
icon.run()
|
icon.run()
|
||||||
|
|
||||||
def update_icon():
|
def update_icon():
|
||||||
global icon
|
global icon
|
||||||
image = get_image()
|
image = get_image()
|
||||||
|
@ -44,6 +44,8 @@ def generate_menu_items():
|
||||||
menu_items = []
|
menu_items = []
|
||||||
menu_items.append(item('Mute' if not mute else 'Unmute', toggle_mute))
|
menu_items.append(item('Mute' if not mute else 'Unmute', toggle_mute))
|
||||||
menu_items.append(item('Do Not Disturb' if not disable_notifs else 'Enable Notifications', toggle_notifications))
|
menu_items.append(item('Do Not Disturb' if not disable_notifs else 'Enable Notifications', toggle_notifications))
|
||||||
|
menu_items.append(menu.SEPARATOR)
|
||||||
|
menu_items.append(item('Exit', exit))
|
||||||
return menu_items
|
return menu_items
|
||||||
|
|
||||||
def toggle_mute():
|
def toggle_mute():
|
||||||
|
@ -57,6 +59,11 @@ def toggle_notifications():
|
||||||
update_menu()
|
update_menu()
|
||||||
update_icon()
|
update_icon()
|
||||||
|
|
||||||
|
def exit():
|
||||||
|
global icon
|
||||||
|
icon.stop()
|
||||||
|
os._exit(0)
|
||||||
|
|
||||||
def update_menu():
|
def update_menu():
|
||||||
global icon
|
global icon
|
||||||
icon.menu = generate_menu_items()
|
icon.menu = generate_menu_items()
|
||||||
|
|
Loading…
Reference in New Issue