Skip to content

Commit

Permalink
refactor: Move Timer class to routines
Browse files Browse the repository at this point in the history
  • Loading branch information
in03 committed Nov 30, 2022
1 parent fd94bdf commit 0405df8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
23 changes: 1 addition & 22 deletions src/patchwork/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():

Expand Down Expand Up @@ -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):
Expand Down
20 changes: 20 additions & 0 deletions src/patchwork/routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 0405df8

Please sign in to comment.