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