Custom sound feature

This commit is contained in:
Abhorrent_Anger 2019-10-29 11:06:36 +02:00
parent d4944a0888
commit 6a5a5cca89
2 changed files with 18 additions and 18 deletions

View File

@ -1,6 +1,6 @@
# EyeStrainReminder # EyeStrainReminder
A small background tool to remind the user of the "20-20-20" rule. Uses system notifications and sound cues. Made primarily for GNU/Linux, but might work with other environments. A small background tool to remind the user of the "20-20-20" rule. Uses system notifications and sound cues. Made primarily for GNU/Linux, but should theoretically work with other environments.
First, you might need these packages: First, you might need these packages:
``` ```
@ -16,7 +16,7 @@ Run it simply with, or preferably put it to run on boot as:
``` ```
$ eyestrainreminder $ eyestrainreminder
``` ```
Optional parameters can be viewed through "$ eyestrainreminder -h", but let you mute the notification sound, turn off notifications by default and invert the tray icon colors. Optional parameters can be viewed through "$ eyestrainreminder -h". In short, it's possible to set a custom notification sound, mute the notification sound, turn off notifications by default and invert the tray icon colors.
In order to remove it, just run: In order to remove it, just run:
``` ```
pip uninstall EyeStrainReminder pip uninstall EyeStrainReminder

View File

@ -17,11 +17,11 @@ MILLISECOND = 1000
MINUTE = 60 MINUTE = 60
DIR = os.path.dirname(os.path.abspath(__file__)) DIR = os.path.dirname(os.path.abspath(__file__))
icon = None icon = mute = disable_notifs = invert_icons = notify_thread = sound = None
#mute = False #mute = False
#disable_notifications = False #disable_notifs = False
#invert_icons = False #invert_icons = False
notify_thread = None #notify_thread = None
def init(): def init():
print("Initializing EyeStrainReminder...") print("Initializing EyeStrainReminder...")
@ -41,12 +41,12 @@ def update_icon():
def get_image(): def get_image():
theme = [[f"{DIR}/files/eye_light.png", f"{DIR}/files/eye_dark.png"], 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"]] [f"{DIR}/files/eye_dark.png", f"{DIR}/files/eye_light.png"]]
return Image.open(theme[invert_icons][disable_notifications]) return Image.open(theme[invert_icons][disable_notifs])
def generate_menu_items(): 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_notifications else 'Enable Notifications', toggle_notifications)) menu_items.append(item('Do Not Disturb' if not disable_notifs else 'Enable Notifications', toggle_notifications))
return menu_items return menu_items
def toggle_mute(): def toggle_mute():
@ -55,8 +55,8 @@ def toggle_mute():
update_menu() update_menu()
def toggle_notifications(): def toggle_notifications():
global disable_notifications global disable_notifs
disable_notifications = not disable_notifications disable_notifs = not disable_notifs
update_menu() update_menu()
update_icon() update_icon()
@ -69,15 +69,15 @@ def uninit():
notify2.uninit() notify2.uninit()
def wait(): def wait():
sleep(TIMEOUT*MINUTE) #sleep(TIMEOUT*MINUTE)
#pass pass
def send_notification(): def send_notification():
if not disable_notifications: if not disable_notifs:
notify(MESSAGE) notify(MESSAGE)
else: else:
print("Notifications are disabled, waiting for an enable...") print("Notifications are disabled, waiting for an enable...")
while disable_notifications: while disable_notifs:
sleep(10) sleep(10)
notify(MESSAGE_MISSED) notify(MESSAGE_MISSED)
@ -94,14 +94,14 @@ def notify(message):
def play_sound(): def play_sound():
if not mute: if not mute:
playsound(f"{DIR}/files/default.wav") playsound(sound)
def parse_args(): def parse_args():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("-m", "--mute", action="store_true", default=False, help="Mute notification sounds by default")
parser.add_argument("-n", "--disable_notifications", action="store_true", default=False, help="Disable notifications by default")
parser.add_argument("-i", "--invert_icons", action="store_true", default=False, help="Default to the dark icon for light themes") parser.add_argument("-i", "--invert_icons", action="store_true", default=False, help="Default to the dark icon for light themes")
parser.add_argument("-m", "--mute", action="store_true", default=False, help="Mute notification sounds by default")
parser.add_argument("-n", "--disable_notifs", action="store_true", default=False, help="Disable notifications by default")
parser.add_argument("-s", "--sound", action="store", default=f"{DIR}/files/default.wav", help="Custom notification sound")
args = parser.parse_args() args = parser.parse_args()
globals().update(args.__dict__) globals().update(args.__dict__)
@ -117,4 +117,4 @@ if __name__ == '__main__':
notify_thread = threading.Thread(target=main, name="Notify Thread") notify_thread = threading.Thread(target=main, name="Notify Thread")
notify_thread.start() notify_thread.start()
create_tray_icon() create_tray_icon()
notify_thread.join() notify_thread.join()