Skip to content

Updating Pomodoro timer #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions Pomodoro Timer/App
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import sys
import time
from PyQt6.QtCore import QTimer, Qt
from PyQt6.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton, QLabel
from PyQt6.QtGui import QFont
from colorama import init, Fore, Style

# Initialize colorama
init(autoreset=True)

class CountdownApp(QWidget):
def __init__(self):
super().__init__()

self.initUI()

def initUI(self):
self.layout = QVBoxLayout()

self.label = QLabel("00:00")
self.label.setFont(QFont('Arial', 48))
self.label.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.layout.addWidget(self.label)

self.work_button = QPushButton('Start Work Session')
self.work_button.clicked.connect(lambda: self.start_countdown(25, "Work Session"))
self.layout.addWidget(self.work_button)

self.break_button = QPushButton('Start Break')
self.break_button.clicked.connect(lambda: self.start_countdown(5, "Break"))
self.layout.addWidget(self.break_button)

self.setLayout(self.layout)

self.setWindowTitle('Countdown Timer')
self.setGeometry(300, 300, 300, 200)
self.show()

def start_countdown(self, minutes, session_name):
self.work_button.setDisabled(True)
self.break_button.setDisabled(True)
self.seconds = minutes * 60
self.session_name = session_name
self.update_timer()
self.timer = QTimer(self)
self.timer.timeout.connect(self.update_timer)
self.timer.start(1000)

def update_timer(self):
mins, secs = divmod(self.seconds, 60)
timer_text = f'{mins:02d}:{secs:02d}'
self.label.setText(timer_text)

if self.seconds == 0:
self.timer.stop()
self.label.setText(f'{self.session_name} is over!')

self.work_button.setDisabled(False)
self.break_button.setDisabled(False)
else:
self.seconds -= 1

if __name__ == '__main__':
app = QApplication(sys.argv)
ex = CountdownApp()
sys.exit(app.exec())
35 changes: 25 additions & 10 deletions Pomodoro Timer/pomodoro.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
import time
from tqdm import tqdm
from colorama import init, Fore, Style

def countdown(minutes):
# Initialize colorama
init(autoreset=True)

def countdown(minutes, name):
print(name)
seconds = minutes * 60
while seconds:
mins, secs = divmod(seconds, 60)
timer = f'{mins:02d}:{secs:02d}'
print(timer, end='\r')
time.sleep(1)
seconds -= 1
print('Time is up!')
bar_format = Fore.GREEN + '{l_bar}{bar}| {remaining} seconds' + Style.RESET_ALL
with tqdm(total=seconds, desc='Time remaining', bar_format=bar_format, ncols=100) as pbar:
while seconds:
mins, secs = divmod(seconds, 60)
timer = f'{mins:02d}:{secs:02d}'
print(Fore.YELLOW + timer, end='\r' + Style.RESET_ALL)
time.sleep(1)
seconds -= 1
pbar.update(1)
print(Fore.RED + '\nTime is up!' + Style.RESET_ALL)

# Example usage:
countdown(1) # for a 25-minute work session
countdown(1) # for a 5-minute break
countdown(1,"Work Session") # for a 1-minute work session
countdown(1,"Break") # for a 1-minute break

# Example use, running for infinity:

while True:
countdown(25,"Work Session")
countdown(5, "Break")