From d95981e2d521b273e630c525313265a38fea69f6 Mon Sep 17 00:00:00 2001 From: Saman Mahdian <111632324+Sam-mhd@users.noreply.github.com> Date: Sun, 30 Jun 2024 10:52:28 +0200 Subject: [PATCH 1/5] Update pomodoro.py new ui --- Pomodoro Timer/pomodoro.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/Pomodoro Timer/pomodoro.py b/Pomodoro Timer/pomodoro.py index daaa971..e6e99ce 100644 --- a/Pomodoro Timer/pomodoro.py +++ b/Pomodoro Timer/pomodoro.py @@ -1,15 +1,23 @@ import time +from tqdm import tqdm +from colorama import init, Fore, Style + +# Initialize colorama +init(autoreset=True) def countdown(minutes): 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) # for a 1-minute work session +countdown(1) # for a 1-minute break From 922676ee89cc03c3c0dbeaf89e23b4e0a9e89919 Mon Sep 17 00:00:00 2001 From: bbob122 <55184297+bbob122@users.noreply.github.com> Date: Sun, 30 Jun 2024 10:57:34 +0200 Subject: [PATCH 2/5] Update pomodoro.py Added a string to name the timer currently running --- Pomodoro Timer/pomodoro.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Pomodoro Timer/pomodoro.py b/Pomodoro Timer/pomodoro.py index e6e99ce..80270ba 100644 --- a/Pomodoro Timer/pomodoro.py +++ b/Pomodoro Timer/pomodoro.py @@ -5,7 +5,8 @@ # Initialize colorama init(autoreset=True) -def countdown(minutes): +def countdown(minutes, name): + print(name) seconds = minutes * 60 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: @@ -19,5 +20,5 @@ def countdown(minutes): print(Fore.RED + '\nTime is up!' + Style.RESET_ALL) # Example usage: -countdown(1) # for a 1-minute work session -countdown(1) # for a 1-minute break +countdown(1,"Work Session") # for a 1-minute work session +countdown(1,"Break") # for a 1-minute break From d25108614ef2ef07d731ac0f3b20accc1187158a Mon Sep 17 00:00:00 2001 From: bbob122 <55184297+bbob122@users.noreply.github.com> Date: Sun, 30 Jun 2024 11:00:05 +0200 Subject: [PATCH 3/5] Update pomodoro.py Added second Example usage, the pomodoro timer will run for 25 min work session and 5 min break for infinity --- Pomodoro Timer/pomodoro.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Pomodoro Timer/pomodoro.py b/Pomodoro Timer/pomodoro.py index 80270ba..4bc0a45 100644 --- a/Pomodoro Timer/pomodoro.py +++ b/Pomodoro Timer/pomodoro.py @@ -22,3 +22,9 @@ def countdown(minutes, name): # Example usage: 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") From 6b6749a8f3bece24e35f71e4cdcf1c4ad86f0138 Mon Sep 17 00:00:00 2001 From: bbob122 <55184297+bbob122@users.noreply.github.com> Date: Sun, 30 Jun 2024 11:01:39 +0200 Subject: [PATCH 4/5] Update pomodoro.py Changed true to True --- Pomodoro Timer/pomodoro.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pomodoro Timer/pomodoro.py b/Pomodoro Timer/pomodoro.py index 4bc0a45..8c6382d 100644 --- a/Pomodoro Timer/pomodoro.py +++ b/Pomodoro Timer/pomodoro.py @@ -25,6 +25,6 @@ def countdown(minutes, name): # Example use, running for infinity: -while true: +while True: countdown(25,"Work Session") countdown(5, "Break") From 853e3ae51f858cdbaabee66aba9fbdd93910f1aa Mon Sep 17 00:00:00 2001 From: Saman Mahdian <111632324+Sam-mhd@users.noreply.github.com> Date: Sun, 30 Jun 2024 11:04:17 +0200 Subject: [PATCH 5/5] Create App An Application --- Pomodoro Timer/App | 66 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 Pomodoro Timer/App diff --git a/Pomodoro Timer/App b/Pomodoro Timer/App new file mode 100644 index 0000000..e27f529 --- /dev/null +++ b/Pomodoro Timer/App @@ -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())