-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
110 lines (95 loc) · 3.38 KB
/
main.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
104
105
106
107
108
109
110
import sys
from pathlib import Path
import ctypes
from PyQt6.QtCore import QTimer
from PyQt6.QtGui import QIcon
from PyQt6.QtWidgets import QMainWindow, QApplication
from mainWindow import Ui_MainWindow
# constants
APP_NAME = "Pomo!"
APP_ID = "pomodoro.v1"
WORK_MIN = 30
SHORT_BREAK_MIN = 5
LONG_BREAK_MIN = 30
LONG_BREAK_INTERVAL = 4
class MainWindow(QMainWindow, Ui_MainWindow):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.setupUi(self)
self.startButton.clicked.connect(self.startTimer)
self.resetButton.clicked.connect(self.resetTimer)
self.workTimer = QTimer()
self.workTimer.setInterval(1000) # 1 second
self.workTimer.timeout.connect(self.updateWork)
self.breakTimer = QTimer()
self.breakTimer.setInterval(1000) # 1 second
self.breakTimer.timeout.connect(self.updateBreak)
self._setDefaults()
def startTimer(self):
self.startWork()
self.startButton.setEnabled(False)
def resetTimer(self):
self._setDefaults()
def startWork(self):
self.modeLabel.setText("Work")
self.modeLabel.setStyleSheet("color: red")
self.timeLCD.display(f"{WORK_MIN:02d}:00")
self.workSessions += 1
self.timeRemainingSec = WORK_MIN * 60
self.workTimer.start()
def updateWork(self):
self.updateTimeDisplay()
if self.timeRemainingSec == 0:
self.checkmarks += "✅"
self.countLabel.setText(self.checkmarks)
self.workTimer.stop()
self.startBreak()
def startBreak(self):
if (self.workSessions % LONG_BREAK_INTERVAL == 0):
self.modeLabel.setText("Long Break")
duration = LONG_BREAK_MIN
self.modeLabel.setStyleSheet("color: #80c342")
else:
self.modeLabel.setText("Short Break")
duration = SHORT_BREAK_MIN
self.modeLabel.setStyleSheet("color: #53baff")
self.timeLCD.display(f"{duration:02d}:00")
self.timeRemainingSec = duration * 60
self.breakTimer.start()
def updateBreak(self):
self.updateTimeDisplay()
if self.timeRemainingSec == 0:
self.breakTimer.stop()
self.startWork()
def updateTimeDisplay(self):
self.timeRemainingSec -= 1
mins, secs = secToMinSec(self.timeRemainingSec)
mins = f"{mins:02d}"
secs = f"{secs:02d}"
remainingText = mins + ":" + secs
self.timeLCD.display(remainingText)
def _setDefaults(self):
self.workSessions = 0
self.checkmarks = ""
self.countLabel.setText(self.checkmarks)
self.startButton.setEnabled(True)
self.modeLabel.setText("Let's get working")
self.modeLabel.setStyleSheet("color: #f0f0f0")
self.workTimer.stop()
self.breakTimer.stop()
self.timeLCD.display("00:00")
def secToMinSec(seconds: int) -> tuple[int, int]:
mins = seconds // 60
seconds = seconds - (mins * 60)
return (mins, seconds)
def run():
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(APP_ID)
app = QApplication(sys.argv)
app.setApplicationName(APP_NAME)
app.setWindowIcon(QIcon("tomato.png"))
app.setStyleSheet(Path('styles.qss').read_text())
window = MainWindow()
window.show()
app.exec()
if __name__ == "__main__":
sys.exit(run())