2019-10-21 00:14:56 +03:00
|
|
|
#!/usr/bin/python3
|
|
|
|
import notify2
|
|
|
|
from time import sleep
|
2019-10-21 14:14:15 +03:00
|
|
|
from playsound import playsound
|
2019-10-23 10:52:39 +03:00
|
|
|
import os
|
2019-10-24 16:12:32 +03:00
|
|
|
from pystray import MenuItem as item
|
|
|
|
import pystray
|
|
|
|
from PIL import Image
|
2019-10-21 00:14:56 +03:00
|
|
|
|
|
|
|
NAME = 'Eye Strain Reminder'
|
|
|
|
MESSAGE = 'Friendly reminder to observe the 20-20-20 rule'
|
|
|
|
TIMEOUT = 20
|
|
|
|
MILLISECOND = 1000
|
2019-10-22 13:55:16 +03:00
|
|
|
MINUTE = 60
|
2019-10-23 10:52:39 +03:00
|
|
|
DIR = os.path.dirname(os.path.abspath(__file__))
|
2019-10-21 00:14:56 +03:00
|
|
|
|
2019-10-28 15:09:55 +02:00
|
|
|
icon = None
|
2019-10-24 16:12:32 +03:00
|
|
|
mute = False
|
2019-10-28 15:09:55 +02:00
|
|
|
disable_notifications = False
|
2019-10-24 16:12:32 +03:00
|
|
|
|
2019-10-28 15:09:55 +02:00
|
|
|
def toggle_mute():
|
2019-10-24 16:12:32 +03:00
|
|
|
global mute
|
2019-10-28 15:09:55 +02:00
|
|
|
mute = True if not mute else False
|
|
|
|
update_menu()
|
2019-10-24 16:12:32 +03:00
|
|
|
|
2019-10-28 15:09:55 +02:00
|
|
|
def generate_menu_items():
|
2019-10-24 16:12:32 +03:00
|
|
|
menu_items = []
|
|
|
|
if not mute:
|
2019-10-28 15:09:55 +02:00
|
|
|
menu_items.append(item('Mute', toggle_mute))
|
2019-10-24 16:12:32 +03:00
|
|
|
else:
|
2019-10-28 15:09:55 +02:00
|
|
|
menu_items.append(item('Unmute', toggle_mute))
|
2019-10-24 16:12:32 +03:00
|
|
|
return menu_items
|
|
|
|
|
2019-10-28 15:09:55 +02:00
|
|
|
def update_menu():
|
|
|
|
global icon
|
|
|
|
icon.menu = generate_menu_items()
|
|
|
|
icon.update_menu()
|
|
|
|
|
2019-10-21 00:14:56 +03:00
|
|
|
def init():
|
2019-10-28 15:09:55 +02:00
|
|
|
global icon
|
2019-10-24 16:12:32 +03:00
|
|
|
image = Image.open(f"{DIR}/files/eye_light.png")
|
|
|
|
icon = pystray.Icon(NAME, image, NAME, generate_menu_items())
|
|
|
|
icon.run()
|
2019-10-22 14:43:20 +03:00
|
|
|
print("Initializing EyeStrainReminder...")
|
2019-10-21 00:14:56 +03:00
|
|
|
notify2.init(NAME)
|
|
|
|
|
|
|
|
def uninit():
|
|
|
|
notify2.uninit()
|
|
|
|
|
2019-10-22 13:55:16 +03:00
|
|
|
def wait():
|
2019-10-24 16:12:32 +03:00
|
|
|
#sleep(TIMEOUT*MINUTE)
|
|
|
|
pass
|
|
|
|
|
|
|
|
def play_sound():
|
|
|
|
if not mute:
|
|
|
|
playsound(f"{DIR}/files/default.wav")
|
2019-10-22 13:55:16 +03:00
|
|
|
|
2019-10-21 00:14:56 +03:00
|
|
|
def send_notification():
|
2019-10-22 14:43:20 +03:00
|
|
|
print(MESSAGE)
|
2019-10-21 14:14:15 +03:00
|
|
|
notification = notify2.Notification(NAME, MESSAGE, "notification-device-eject")
|
2019-10-21 00:14:56 +03:00
|
|
|
notification.set_timeout(TIMEOUT * MILLISECOND)
|
|
|
|
notification.set_urgency(notify2.URGENCY_LOW)
|
|
|
|
notification.show()
|
2019-10-24 16:12:32 +03:00
|
|
|
play_sound()
|
2019-10-21 00:14:56 +03:00
|
|
|
sleep(TIMEOUT)
|
|
|
|
notification.close()
|
2019-10-24 16:12:32 +03:00
|
|
|
play_sound()
|
2019-10-21 00:14:56 +03:00
|
|
|
|
2019-10-22 14:43:20 +03:00
|
|
|
def main():
|
2019-10-21 00:14:56 +03:00
|
|
|
init()
|
2019-10-22 13:55:16 +03:00
|
|
|
while 1:
|
|
|
|
wait()
|
|
|
|
send_notification()
|
2019-10-22 14:43:20 +03:00
|
|
|
uninit()
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|