-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpomo_timer.py
103 lines (90 loc) · 2.5 KB
/
pomo_timer.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
92
93
94
95
96
97
98
99
100
101
102
103
"""
Description:
Using PySimpleGUI to make a Pomodoro Timer
Build Instructions:
To run:
python pom_timer.py
To create installer (MAC ONLY):
py2applet --make-setup pom_timer.py
python setup.py py2app
TODO:
base on internal time to prevent drift and other timing issues
resolve issue of timer ending and skipping 1 second while playing sound
"""
import PySimpleGUI as sg
import os
import sys
# import time as t
sg.theme("DarkBrown4")
pomodoro = 25
sec = int(pomodoro * 60)
minn, secc = divmod(sec, 60)
time_format = "{:02d}:{:02d}".format(minn, secc)
start_btn = "Start"
layout = [
[sg.Text(text="Pomodoro Timer", font="Arial 15", justification="center")],
[
sg.Text(
text=time_format,
size=(8, 1),
font="Arial 45",
key="-OUT-",
justification="center",
)
],
[
sg.Button(
button_text="Start",
font="Arial 20",
disabled=False,
key="btn1",
size=(8, 1),
),
sg.Button(
button_text="Reset",
font="Arial 20",
disabled=True,
key="btn2",
size=(8, 1)
),
],
]
window = sg.Window("Pomodoro Timer", layout)
running = False
while True:
event, values = window.read(timeout=1000)
if event == sg.WIN_CLOSED or event == "Cancel":
break
if event == "btn1":
if running:
running = False
window["btn1"].update("Start")
else:
running = True
window["btn1"].update("Pause")
window["btn2"].update(disabled=False)
if time_format == "00:00":
running = False
if running is True:
minn, secc = divmod(sec, 60)
time_format = "{:02d}:{:02d}".format(minn, secc)
window["-OUT-"].update(time_format)
window["btn2"].update(disabled=False)
sec -= 1
if event == "btn2":
running = False
sec = int(pomodoro * 60)
minn, secc = divmod(sec, 60)
time_format = "{:02d}:{:02d}".format(minn, secc)
window["-OUT-"].update(time_format)
window["btn1"].update("Start")
window["btn2"].update(disabled=True)
if time_format == "00:01":
if sys.platform.startswith("darwin"):
os.system('say "got it done"')
elif sys.platform.startswith("linux"):
os.system('spd-say "got it done"')
time_format = "00:00"
window["-OUT-"].update(time_format)
running = False
window.close()