From e3bccd4a8a8e1b1533e20f785ba44acf44006698 Mon Sep 17 00:00:00 2001 From: moiSentineL Date: Tue, 12 Nov 2024 13:28:12 +0530 Subject: [PATCH 1/2] added new variables for timer (workaround --- flomo/cli.py | 2 +- flomo/ui.py | 71 ++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 50 insertions(+), 23 deletions(-) diff --git a/flomo/cli.py b/flomo/cli.py index ee01fe2..1b75c37 100644 --- a/flomo/cli.py +++ b/flomo/cli.py @@ -72,7 +72,7 @@ def start(tag: str, name: str): db.create_table() session_id = db.create_session(tag, name, datetime.datetime.now()) db.conn.close() - ui.main(tag, name, session_id) + ui.main(tag, name, session_id, timer=True) except ( errors.DBFileNotFoundError, errors.NoConfigError, diff --git a/flomo/ui.py b/flomo/ui.py index 8761c0e..ce1eb95 100644 --- a/flomo/ui.py +++ b/flomo/ui.py @@ -13,7 +13,7 @@ class UI: def __init__( - self, status: int, tag: str, name: str, chilling_time: int | None = None + self, status: int, tag: str, name: str, chilling_time: int, timer_time: int | None = None ): self.tag = f"#{tag}" self.tag_color = helpers.tag_color(self.tag) @@ -21,6 +21,8 @@ def __init__( self.status = status self.chilling_time = round(chilling_time) if chilling_time else None + self.timer_time = round(timer_time) if timer else None + self.stopwatch = 0 self.close_live_panel = False @@ -34,7 +36,7 @@ def __init__( def generate_panel(self): # TODO: Fix UI resize issue? stuff = f"{self.name}\n[{self.tag_color}]{self.tag}[/{self.tag_color}]\n\n{helpers.format_time( - self.stopwatch if (self.status == 0) else self.chilling_time or 0)}\n\n\\[q] - {'break' if self.status == 0 else 'skip?'} [Ctrl+C] - quit" + self.stopwatch if (self.status == 0) else (self.chilling_time or 0 if (self.status == 1) else self.timer_time or 0)) }\n\n\\[q] - {'break' if self.status == 0 else 'skip?'} [Ctrl+C] - quit" content = Text.from_markup(stuff, justify="center", style="yellow") return Align.center( Panel( @@ -59,6 +61,10 @@ def show_live_panel(self): if not (self.chilling_time > 1): break self.chilling_time -= 1 + elif self.status == 2 and self.timer_time: + if not (self.timer_time > 1): + break + self.timer_time -=1 _live.update(self.generate_panel()) def get_input(self): @@ -66,32 +72,53 @@ def get_input(self): return self.terminal.inkey(timeout=0.1).lower() -def main(tag: str, name: str, session_id: str): +def main(tag: str, name: str, session_id: str, timer=False): # TODO: Do something with the Terminal close issue try: while True: play_sound_thread = threading.Thread(target=helpers.play_sound, daemon=True) play_sound_thread.start() - flowing_ui = UI(0, tag, name) - flowing_panel_thread = threading.Thread( - target=flowing_ui.show_live_panel, daemon=True - ) - flowing_panel_thread.start() - - inp = "" - while flowing_ui.stopwatch == 0 or not ( - flowing_ui.stopwatch != 0 and inp == "q" - ): - inp = flowing_ui.get_input() - - chilling_time = flowing_ui.stopwatch / 5 - - flowing_ui.close_live_panel = True - flowing_panel_thread.join() - play_sound_thread.join() - - del flowing_ui + if timer: + timer_ui = UI(2, tag, name, timer_time=6000) + timer_panel_thread = threading.Thread( + target=timer_ui.show_live_panel, daemon=True + ) + timer_panel_thread.start() + + inp = "" + while timer_ui.stopwatch == 0 or not ( + timer_ui.stopwatch != 0 and inp == "q" + ): + inp = timer_ui.get_input() + + chilling_time = timer_ui.stopwatch / 5 + + timer_ui.close_live_panel = True + timer_panel_thread.join() + play_sound_thread.join() + + del timer_ui + else: + flowing_ui = UI(0, tag, name) + flowing_panel_thread = threading.Thread( + target=flowing_ui.show_live_panel, daemon=True + ) + flowing_panel_thread.start() + + inp = "" + while flowing_ui.stopwatch == 0 or not ( + flowing_ui.stopwatch != 0 and inp == "q" + ): + inp = flowing_ui.get_input() + + chilling_time = flowing_ui.stopwatch / 5 + + flowing_ui.close_live_panel = True + flowing_panel_thread.join() + play_sound_thread.join() + + del flowing_ui chilling_ui = UI(1, tag, name, int(chilling_time)) From 4f9080e5f77e287ce12f4f4bedb14a46414abe62 Mon Sep 17 00:00:00 2001 From: moiSentineL Date: Tue, 12 Nov 2024 13:32:57 +0530 Subject: [PATCH 2/2] "timer" not defined? --- flomo/ui.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/flomo/ui.py b/flomo/ui.py index ce1eb95..d64ef76 100644 --- a/flomo/ui.py +++ b/flomo/ui.py @@ -80,19 +80,20 @@ def main(tag: str, name: str, session_id: str, timer=False): play_sound_thread.start() if timer: - timer_ui = UI(2, tag, name, timer_time=6000) + print("bruh") + timer_ui = UI(2, tag, name, timer_time=6000, chilling_time=60) timer_panel_thread = threading.Thread( target=timer_ui.show_live_panel, daemon=True ) timer_panel_thread.start() inp = "" - while timer_ui.stopwatch == 0 or not ( - timer_ui.stopwatch != 0 and inp == "q" + while timer_ui.timer_time == 0 or not ( + timer_ui.timer_time != 0 and inp == "q" ): inp = timer_ui.get_input() - chilling_time = timer_ui.stopwatch / 5 + chilling_time = timer_ui.timer_time / 5 timer_ui.close_live_panel = True timer_panel_thread.join()