From cdfbe29715f7cc36ffc0525120dcb19785173c4c Mon Sep 17 00:00:00 2001 From: hmjsp Date: Sun, 28 Dec 2025 13:35:02 +0000 Subject: INCOMPLETE: add stop/start and rest bank to stopwatch - IMPORTANT: added seconds to timestamp in csv as someone could start and rest in the same minute - BROKEN commit, but i need something sane to be able to roll back to - only works for stopwatch atm, haven't even tested timer - doesn't show cumalative time focused in timer, will need a bit of refactoring (hence need for sane commit) - timer now returns seconds for everything except start --- timers.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'timers.py') diff --git a/timers.py b/timers.py index cf8e91d..5ba51fa 100644 --- a/timers.py +++ b/timers.py @@ -4,7 +4,7 @@ import inputs frequency = 120 # 120Hz refresh -def timer(length=0): +def timer(length=0, ratio = 0.2, rest_accum=0): """countdown and stopwatch; pass length as 0 for stopwatch""" start = datetime.datetime.now() end = start + datetime.timedelta(seconds=length) # change to mins in final @@ -16,12 +16,16 @@ def timer(length=0): while True: now = datetime.datetime.now() elapsed = now - start + rest = elapsed * ratio + datetime.timedelta(seconds=rest_accum) time_left = end - now if length > 0 and time_left.total_seconds() <= 0: break ch = inputs.getch_nb(timeout) if ch == 'q': + rest = datetime.timedelta() + break + elif ch == ' ': break if length > 0: @@ -30,11 +34,12 @@ def timer(length=0): time_display = elapsed # see https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797 - print("\x1b[2K\r" + inputs.delta_to_HM(time_display), end="", flush=True) + print("\x1b[2K\r" + inputs.delta_to_HM(time_display) + "\t" + + inputs.delta_to_HM(rest), end="", flush=True) accum += timeout if accum >= 1: accum = 0 termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings) - return (elapsed, start) + return (elapsed.total_seconds(), rest.total_seconds(), start) -- cgit v1.2.3