Skip to content

Commit ffba311

Browse files
authored
Merge pull request #2 from bbob122/new_features
Updating Pomodoro timer
2 parents 7f2cf85 + 853e3ae commit ffba311

File tree

2 files changed

+91
-10
lines changed

2 files changed

+91
-10
lines changed

Pomodoro Timer/App

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import sys
2+
import time
3+
from PyQt6.QtCore import QTimer, Qt
4+
from PyQt6.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton, QLabel
5+
from PyQt6.QtGui import QFont
6+
from colorama import init, Fore, Style
7+
8+
# Initialize colorama
9+
init(autoreset=True)
10+
11+
class CountdownApp(QWidget):
12+
def __init__(self):
13+
super().__init__()
14+
15+
self.initUI()
16+
17+
def initUI(self):
18+
self.layout = QVBoxLayout()
19+
20+
self.label = QLabel("00:00")
21+
self.label.setFont(QFont('Arial', 48))
22+
self.label.setAlignment(Qt.AlignmentFlag.AlignCenter)
23+
self.layout.addWidget(self.label)
24+
25+
self.work_button = QPushButton('Start Work Session')
26+
self.work_button.clicked.connect(lambda: self.start_countdown(25, "Work Session"))
27+
self.layout.addWidget(self.work_button)
28+
29+
self.break_button = QPushButton('Start Break')
30+
self.break_button.clicked.connect(lambda: self.start_countdown(5, "Break"))
31+
self.layout.addWidget(self.break_button)
32+
33+
self.setLayout(self.layout)
34+
35+
self.setWindowTitle('Countdown Timer')
36+
self.setGeometry(300, 300, 300, 200)
37+
self.show()
38+
39+
def start_countdown(self, minutes, session_name):
40+
self.work_button.setDisabled(True)
41+
self.break_button.setDisabled(True)
42+
self.seconds = minutes * 60
43+
self.session_name = session_name
44+
self.update_timer()
45+
self.timer = QTimer(self)
46+
self.timer.timeout.connect(self.update_timer)
47+
self.timer.start(1000)
48+
49+
def update_timer(self):
50+
mins, secs = divmod(self.seconds, 60)
51+
timer_text = f'{mins:02d}:{secs:02d}'
52+
self.label.setText(timer_text)
53+
54+
if self.seconds == 0:
55+
self.timer.stop()
56+
self.label.setText(f'{self.session_name} is over!')
57+
58+
self.work_button.setDisabled(False)
59+
self.break_button.setDisabled(False)
60+
else:
61+
self.seconds -= 1
62+
63+
if __name__ == '__main__':
64+
app = QApplication(sys.argv)
65+
ex = CountdownApp()
66+
sys.exit(app.exec())

Pomodoro Timer/pomodoro.py

+25-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
import time
2+
from tqdm import tqdm
3+
from colorama import init, Fore, Style
24

3-
def countdown(minutes):
5+
# Initialize colorama
6+
init(autoreset=True)
7+
8+
def countdown(minutes, name):
9+
print(name)
410
seconds = minutes * 60
5-
while seconds:
6-
mins, secs = divmod(seconds, 60)
7-
timer = f'{mins:02d}:{secs:02d}'
8-
print(timer, end='\r')
9-
time.sleep(1)
10-
seconds -= 1
11-
print('Time is up!')
11+
bar_format = Fore.GREEN + '{l_bar}{bar}| {remaining} seconds' + Style.RESET_ALL
12+
with tqdm(total=seconds, desc='Time remaining', bar_format=bar_format, ncols=100) as pbar:
13+
while seconds:
14+
mins, secs = divmod(seconds, 60)
15+
timer = f'{mins:02d}:{secs:02d}'
16+
print(Fore.YELLOW + timer, end='\r' + Style.RESET_ALL)
17+
time.sleep(1)
18+
seconds -= 1
19+
pbar.update(1)
20+
print(Fore.RED + '\nTime is up!' + Style.RESET_ALL)
1221

1322
# Example usage:
14-
countdown(1) # for a 25-minute work session
15-
countdown(1) # for a 5-minute break
23+
countdown(1,"Work Session") # for a 1-minute work session
24+
countdown(1,"Break") # for a 1-minute break
25+
26+
# Example use, running for infinity:
27+
28+
while True:
29+
countdown(25,"Work Session")
30+
countdown(5, "Break")

0 commit comments

Comments
 (0)