-
Notifications
You must be signed in to change notification settings - Fork 0
/
coffeebreak.py
91 lines (72 loc) · 2.12 KB
/
coffeebreak.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import pystray
from PIL import Image
import time
import sys
import os
from webbrowser import open
import pymsgbox
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, "resources", relative_path)
def set_duration(icon):
global duration
response = pymsgbox.prompt(
text='How many seconds til your next break? ☕',
title='breaktime',
default='10')
try:
duration = int(response)
except:
return
icon.title = f'Timer set for {duration} seconds.'
def quit(icon):
icon.stop()
def update(icon):
global coffee_drank
global start_time
global duration
if duration == 0:
set_duration(icon)
return
if coffee_drank:
icon.icon = Image.open(resource_path("clock.png"))
icon.title = f'Timer set for {duration} seconds.'
coffee_drank = False
else:
for i in range(duration):
icon.icon = Image.open(resource_path("night.png"))
icon.title = f"Stay focused! You have {duration - i} seconds left."
time.sleep(1)
icon.notify(" ", "Time for a break! ☕")
icon.icon = Image.open(resource_path("coffee-break.png"))
icon.title = "Time for a break! ☕"
coffee_drank = True
def developer(icon):
open("https://github.com/gbhand")
coffee_drank = False
duration = 0
menu = pystray.Menu(
pystray.MenuItem(
text=None,
action=update,
default=True,
visible=False),
pystray.MenuItem(
text="coffebreak v0.1 © gbhand",
action=developer),
pystray.MenuItem(
text="set duration",
action=set_duration),
pystray.MenuItem(
text="quit",
action=quit)
)
image = Image.open(resource_path("clock.png"))
icon = pystray.Icon("coffebreak", image, title="Get started!", menu=menu)
icon.visible = True
icon.run()