diff --git a/Pomodoro Timer/App b/Pomodoro Timer/App new file mode 100644 index 00000000..e27f529c --- /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()) diff --git a/Pomodoro Timer/pomodoro.py b/Pomodoro Timer/pomodoro.py index daaa971e..8c6382da 100644 --- a/Pomodoro Timer/pomodoro.py +++ b/Pomodoro Timer/pomodoro.py @@ -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")