2016-05-10 13:20:15 +03:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
from argparse import ArgumentParser
|
|
|
|
from random import randint
|
|
|
|
from sys import argv
|
2016-05-10 13:39:01 +03:00
|
|
|
from time import sleep, strftime
|
2016-05-10 13:20:15 +03:00
|
|
|
import gi
|
|
|
|
gi.require_version('Notify', '0.7')
|
|
|
|
from gi.repository import Notify
|
|
|
|
|
|
|
|
URGENCY = 0
|
|
|
|
TITLE = 'EYE WATCH'
|
|
|
|
MESSAGES = (
|
|
|
|
'do some blinking',
|
|
|
|
'roll your eyes a few times',
|
|
|
|
'look at a distant object',
|
|
|
|
'close your eyes tightly for a few seconds',
|
|
|
|
'move your eyes sideways'
|
|
|
|
)
|
|
|
|
|
2017-05-10 15:33:10 +03:00
|
|
|
|
2018-05-24 15:24:53 +03:00
|
|
|
def parse_args():
|
2016-05-10 13:20:15 +03:00
|
|
|
desc = 'display a reminder to take a short break and do some eye practice'
|
2018-05-24 15:24:53 +03:00
|
|
|
parser = ArgumentParser(description=desc)
|
|
|
|
parser.add_argument(
|
2016-05-10 13:20:15 +03:00
|
|
|
'-t',
|
|
|
|
'--timer',
|
2016-05-10 13:39:01 +03:00
|
|
|
default='600',
|
2017-05-10 15:33:10 +03:00
|
|
|
help=('run in foreground, showing notification every TIMER seconds '
|
|
|
|
'(this is default, with TIMER = 600)')
|
2016-05-10 13:20:15 +03:00
|
|
|
)
|
2018-05-24 15:24:53 +03:00
|
|
|
parser.add_argument(
|
2016-05-10 13:20:15 +03:00
|
|
|
'-i',
|
|
|
|
'--icon',
|
|
|
|
help='show ICON alongside the message'
|
|
|
|
)
|
2018-05-24 15:24:53 +03:00
|
|
|
return parser.parse_args()
|
2016-05-10 13:20:15 +03:00
|
|
|
|
2017-05-10 15:33:10 +03:00
|
|
|
|
2016-05-10 13:20:15 +03:00
|
|
|
def get_random_message(message_list):
|
|
|
|
list_len = len(message_list)
|
|
|
|
random_value = randint(0, list_len - 1)
|
|
|
|
return message_list[random_value]
|
|
|
|
|
2017-05-10 15:33:10 +03:00
|
|
|
|
2017-05-22 17:11:36 +03:00
|
|
|
def show_notification(notification, text=None, icon=None):
|
|
|
|
notification.update(TITLE, text, icon)
|
2016-05-10 13:20:15 +03:00
|
|
|
notification.set_urgency(URGENCY)
|
|
|
|
notification.show()
|
|
|
|
|
2017-05-10 15:33:10 +03:00
|
|
|
|
2017-05-22 17:11:36 +03:00
|
|
|
def main():
|
2018-05-24 15:24:53 +03:00
|
|
|
args = parse_args()
|
2016-05-10 13:20:15 +03:00
|
|
|
Notify.init(argv[0])
|
|
|
|
notification = Notify.Notification.new(summary=TITLE)
|
|
|
|
|
2017-05-22 17:11:36 +03:00
|
|
|
show_notification(notification, 'Eyewatch daemon started!', args.icon)
|
|
|
|
while True:
|
|
|
|
sleep(int(args.timer))
|
|
|
|
text = get_random_message(MESSAGES)
|
|
|
|
show_notification(notification, text, args.icon)
|
2016-05-10 13:20:15 +03:00
|
|
|
|
|
|
|
Notify.uninit()
|
2017-05-22 17:11:36 +03:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|