Custom sound feature
This commit is contained in:
		
							parent
							
								
									8fb24be336
								
							
						
					
					
						commit
						2ac4d7d0d8
					
				@ -1,6 +1,6 @@
 | 
			
		||||
# 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:
 | 
			
		||||
```
 | 
			
		||||
@ -16,7 +16,7 @@ Run it simply with, or preferably put it to run on boot as:
 | 
			
		||||
```
 | 
			
		||||
$ 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:
 | 
			
		||||
```
 | 
			
		||||
pip uninstall EyeStrainReminder
 | 
			
		||||
 | 
			
		||||
@ -17,11 +17,11 @@ MILLISECOND = 1000
 | 
			
		||||
MINUTE = 60
 | 
			
		||||
DIR = os.path.dirname(os.path.abspath(__file__))
 | 
			
		||||
 | 
			
		||||
icon = None
 | 
			
		||||
icon = mute = disable_notifs = invert_icons = notify_thread = sound = None
 | 
			
		||||
#mute = False
 | 
			
		||||
#disable_notifications = False
 | 
			
		||||
#disable_notifs = False
 | 
			
		||||
#invert_icons = False
 | 
			
		||||
notify_thread = None
 | 
			
		||||
#notify_thread = None
 | 
			
		||||
 | 
			
		||||
def init():
 | 
			
		||||
    print("Initializing EyeStrainReminder...")
 | 
			
		||||
@ -41,12 +41,12 @@ def update_icon():
 | 
			
		||||
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])
 | 
			
		||||
    return Image.open(theme[invert_icons][disable_notifs])
 | 
			
		||||
 | 
			
		||||
def generate_menu_items():   
 | 
			
		||||
    menu_items = []
 | 
			
		||||
    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
 | 
			
		||||
 | 
			
		||||
def toggle_mute():
 | 
			
		||||
@ -55,8 +55,8 @@ def toggle_mute():
 | 
			
		||||
    update_menu()
 | 
			
		||||
 | 
			
		||||
def toggle_notifications():
 | 
			
		||||
    global disable_notifications
 | 
			
		||||
    disable_notifications = not disable_notifications
 | 
			
		||||
    global disable_notifs
 | 
			
		||||
    disable_notifs = not disable_notifs
 | 
			
		||||
    update_menu()
 | 
			
		||||
    update_icon()
 | 
			
		||||
 | 
			
		||||
@ -69,15 +69,15 @@ def uninit():
 | 
			
		||||
    notify2.uninit()
 | 
			
		||||
 | 
			
		||||
def wait():
 | 
			
		||||
    sleep(TIMEOUT*MINUTE)
 | 
			
		||||
    #pass
 | 
			
		||||
    #sleep(TIMEOUT*MINUTE)
 | 
			
		||||
    pass
 | 
			
		||||
 | 
			
		||||
def send_notification():
 | 
			
		||||
    if not disable_notifications:
 | 
			
		||||
    if not disable_notifs:
 | 
			
		||||
        notify(MESSAGE)
 | 
			
		||||
    else:
 | 
			
		||||
        print("Notifications are disabled, waiting for an enable...")
 | 
			
		||||
        while disable_notifications:
 | 
			
		||||
        while disable_notifs:
 | 
			
		||||
            sleep(10)
 | 
			
		||||
        notify(MESSAGE_MISSED)
 | 
			
		||||
 | 
			
		||||
@ -94,14 +94,14 @@ def notify(message):
 | 
			
		||||
 | 
			
		||||
def play_sound():
 | 
			
		||||
    if not mute:
 | 
			
		||||
        playsound(f"{DIR}/files/default.wav")
 | 
			
		||||
        playsound(sound)
 | 
			
		||||
 | 
			
		||||
def parse_args():
 | 
			
		||||
    
 | 
			
		||||
    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("-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()
 | 
			
		||||
    globals().update(args.__dict__)
 | 
			
		||||
 | 
			
		||||
@ -117,4 +117,4 @@ if __name__ == '__main__':
 | 
			
		||||
    notify_thread = threading.Thread(target=main, name="Notify Thread")
 | 
			
		||||
    notify_thread.start()
 | 
			
		||||
    create_tray_icon()
 | 
			
		||||
    notify_thread.join()
 | 
			
		||||
    notify_thread.join()
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user