Full icon functionality
This commit is contained in:
parent
4c0e419263
commit
f58b7681d0
|
@ -6,6 +6,7 @@ import os
|
|||
from pystray import MenuItem as item
|
||||
import pystray
|
||||
from PIL import Image
|
||||
import argparse
|
||||
|
||||
NAME = 'Eye Strain Reminder'
|
||||
MESSAGE = 'Friendly reminder to observe the 20-20-20 rule'
|
||||
|
@ -18,28 +19,43 @@ DIR = os.path.dirname(os.path.abspath(__file__))
|
|||
icon = None
|
||||
mute = False
|
||||
disable_notifications = False
|
||||
invert_icons = False
|
||||
|
||||
def init():
|
||||
global icon
|
||||
image = Image.open(f"{DIR}/files/eye_light.png")
|
||||
image = get_image()
|
||||
icon = pystray.Icon(NAME, image, NAME, generate_menu_items())
|
||||
icon.run()
|
||||
print("Initializing EyeStrainReminder...")
|
||||
notify2.init(NAME)
|
||||
|
||||
def update_icon():
|
||||
global icon
|
||||
image = get_image()
|
||||
icon.icon = image
|
||||
|
||||
def get_image():
|
||||
theme = [[f"{DIR}/files/eye_light.png", f"{DIR}/files/eye_dark.png"],
|
||||
[f"{DIR}/files/eye_dark.png", f"{DIR}/files/eye_light.png"]]
|
||||
return Image.open(theme[invert_icons][disable_notifications])
|
||||
|
||||
def generate_menu_items():
|
||||
menu_items = []
|
||||
if not mute:
|
||||
menu_items.append(item('Mute', toggle_mute))
|
||||
else:
|
||||
menu_items.append(item('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_notifications else 'Enable Notifications', toggle_notifications))
|
||||
return menu_items
|
||||
|
||||
def toggle_mute():
|
||||
global mute
|
||||
mute = True if not mute else False
|
||||
mute = not mute
|
||||
update_menu()
|
||||
|
||||
def toggle_notifications():
|
||||
global disable_notifications
|
||||
disable_notifications = not disable_notifications
|
||||
update_menu()
|
||||
update_icon()
|
||||
|
||||
def update_menu():
|
||||
global icon
|
||||
icon.menu = generate_menu_items()
|
||||
|
@ -62,7 +78,7 @@ def send_notification():
|
|||
notify(MESSAGE_MISSED)
|
||||
|
||||
def notify(message):
|
||||
print(MESSAGE)
|
||||
print(message)
|
||||
notification = notify2.Notification(NAME, message, "notification-device-eject")
|
||||
notification.set_timeout(TIMEOUT * MILLISECOND)
|
||||
notification.set_urgency(notify2.URGENCY_LOW)
|
||||
|
|
Loading…
Reference in New Issue