From 0405df84fbefc1edc5eb16a5a9db0fb64b93fa4e Mon Sep 17 00:00:00 2001 From: in03 Date: Wed, 30 Nov 2022 16:34:18 +1000 Subject: [PATCH] refactor: Move Timer class to routines --- src/patchwork/app.py | 23 +---------------------- src/patchwork/routines.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/patchwork/app.py b/src/patchwork/app.py index 0887ea2..955f2fc 100644 --- a/src/patchwork/app.py +++ b/src/patchwork/app.py @@ -47,27 +47,6 @@ def save_init(): dpg.save_init_file("dpg.ini") -class Timer: - # keeps track of DPG time since last render - # note: frame rate speeds up by a factor of 4 to 5 - # when manipulating the viewport - - def __init__(self, interval): - self.total_time = dpg.get_total_time() - self.last_total_time = dpg.get_total_time() - self.interval = interval - - @property - def has_passed(self): - self.total_time = dpg.get_total_time() - delta_time = dpg.get_total_time() - self.last_total_time - if delta_time > self.interval: - self.last_total_time = self.total_time - return True - return False - - - # RENDER PRESET def choose_render_preset_callback(): @@ -372,7 +351,7 @@ def init(): # Timers global half_a_second - half_a_second = Timer(0.5) + half_a_second = routines.Timer(0.5) def setup_gui(): with dpg.window(tag="primary_window", autosize=True): diff --git a/src/patchwork/routines.py b/src/patchwork/routines.py index 236b88a..e9b04b8 100644 --- a/src/patchwork/routines.py +++ b/src/patchwork/routines.py @@ -8,6 +8,26 @@ logger = logging.getLogger(__name__) logger.setLevel(dpg.get_value("loglevel")) + +class Timer: + # keeps track of DPG time since last render + # note: frame rate speeds up by a factor of 4 to 5 + # when manipulating the viewport + + def __init__(self, interval): + self.total_time = dpg.get_total_time() + self.last_total_time = dpg.get_total_time() + self.interval = interval + + @property + def has_passed(self): + self.total_time = dpg.get_total_time() + delta_time = dpg.get_total_time() - self.last_total_time + if delta_time > self.interval: + self.last_total_time = self.total_time + return True + return False + async def get_marker_at_playhead(current_markers:MarkerCollection, current_frame:int) -> Marker|None: logger.debug("[magenta]Checking for marker at playhead")