-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.pyw
170 lines (144 loc) · 5.62 KB
/
main.pyw
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import PySimpleGUI as sg
import settings
from playsound import playsound
from threading import Thread
from pathlib import Path
import gui
import traceback
import os
from win10toast import ToastNotifier
os.chdir(Path(__file__).parents[0])
def main():
sg.LOOK_AND_FEEL_TABLE["DarkPoker"] = {
"BACKGROUND": "#252525",
"TEXT": "#FFFFFF",
"INPUT": "#af0404",
"TEXT_INPUT": "#FFFFFF",
"SCROLL": "#af0404",
"BUTTON": ("#FFFFFF", "#252525"),
"BORDER": 1,
"SLIDER_DEPTH": 0,
"PROGRESS_DEPTH": 0,
"COLOR_LIST": ["#252525", "#414141", "#af0404", "#ff0000"],
"PROGRESS": ("# D1826B", "# CC8019"),
}
sg.theme("DarkPoker")
try:
sets = settings.read()
except:
settings.first()
sets = settings.read()
window = gui.noTop()
def updateTimer():
window['timer'].Update('{:02d}:{:02d}.{:02d}'.format(secondsToElapse // 3600, secondsToElapse // 60, secondsToElapse % 60))
def play():
try:
if getMoment() == 'Productivity time':
ToastNotifier().show_toast(
"Productivity time",
"Time to work hard!",
duration=10,
icon_path="icon.ico",
threaded=True
)
playsound('./sounds/pomodoro.mp3')
elif getMoment() == 'Break time':
ToastNotifier().show_toast(
"Break time",
"Chill for a bit, you deserve it",
duration=10,
icon_path="icon.ico",
threaded=True
)
playsound('./sounds/pause.mp3')
except:
print(traceback.format_exc())
def getMoment():
return window['inWhichMoment'].DisplayText
secondsToElapse = sets['pomodoro'] * 60
clockRunning = False
updateTimer()
while True:
event, values = window.read(1000)
if event == sg.WINDOW_CLOSED:
break
if event == 'Start':
if getMoment() == 'Productivity time':
secondsToElapse = sets['pomodoro'] * 60
elif getMoment() == 'Break time':
secondsToElapse = sets['pause'] * 60
clockRunning = True
window['Pause'].Update(disabled=False)
if event == 'Pause' and window['Pause'].ButtonText == 'Pause':
clockRunning = False
window['Pause'].Update('Resume')
elif event == 'Pause' and window['Pause'].ButtonText == 'Resume':
clockRunning = True
window['Pause'].Update('Pause')
if event == 'Reset':
secondsToElapse = sets['pomodoro'] * 60
window['inWhichMoment'].Update('Productivity time')
updateTimer()
clockRunning = False
if event in ['On top', 'Enlarge']:
window.close()
if event == 'On top': window = gui.onTop(getMoment())
if event == 'Enlarge': window = gui.noTop(getMoment(), not clockRunning)
if secondsToElapse == 0 and clockRunning == True:
first = ['Productivity time', 'autopause', 'pause']
second = ['Break time', 'autopomodoro', 'pomodoro']
def firstSecond(a, b, secondsToElapse, clockRunning):
if getMoment() == a[0]:
window['inWhichMoment'].Update(b[0])
Thread(target=play).start()
secondsToElapse = sets[a[2]] * 60
if not sets[a[1]]:
clockRunning = False
#window['Pause'].Update(disabled=True)
return secondsToElapse, clockRunning
return False
result = firstSecond(first, second, secondsToElapse, clockRunning)
if not result:
result = firstSecond(second, first, secondsToElapse, clockRunning)
if result:
secondsToElapse, clockRunning = result
"""
if getMoment() == 'Productivity time':
window['inWhichMoment'].Update('Break time')
Thread(target=play).start()
if sets['autopause']:
secondsToElapse = sets['pause'] * 60
else:
clockRunning = False
window['Pause'].Update(disabled=True)
elif getMoment() == 'Break time':
window['inWhichMoment'].Update('Productivity time')
Thread(target=play).start()
if sets['autopomodoro']:
secondsToElapse = sets['pomodoro'] * 60
else:
clockRunning = False
window['Pause'].Update(disabled=True)
"""
if clockRunning:
secondsToElapse -= 1
if event == 'Settings':
window.close()
saved = gui.settingsWin()
window = gui.noTop(getMoment(), not clockRunning)
if saved:
sets = settings.read()
secondsToElapse = sets['pomodoro'] * 60
updateTimer()
window['inWhichMoment'].Update('Productivity time')
clockRunning = False
updateTimer()
window.close()
if __name__ == '__main__':
import traceback
from pyperclip import copy
try:
main()
except:
sg.Popup(traceback.format_exc()+'\n'+'Hit ok to copy the error to clipboard'+'\n'+'Report it on https://github.com/DeusAres/Pythondoro/issues please!', title='Bug!')
copy(traceback.format_exc())