Skip to content

Commit

Permalink
wip: Counter based task-switching
Browse files Browse the repository at this point in the history
  • Loading branch information
in03 committed Nov 29, 2022
1 parent 6715c3c commit df04546
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 51 deletions.
2 changes: 1 addition & 1 deletion src/dpg.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Collapsed=0

[Window][###23]
Pos=152,225
Size=458,100
Size=100,100
Collapsed=0

[Window][###93]
Expand Down
47 changes: 26 additions & 21 deletions src/patchwork/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ def cancel_callback(self, sender, app_data):
track_patch_file = TrackPatchfile()
render_patch_file = RenderPatchFile()


# Helpers
def get_next_free_marker_num():
"""Get the next marker number in the series"""
Expand Down Expand Up @@ -440,32 +439,38 @@ def open_documentation():
dpg.setup_dearpygui()
dpg.show_viewport()

while dpg.is_dearpygui_running():

# REACTIVE VARIABLES
markers = copy.copy(resolve.active_timeline.markers)
frame_rate = copy.copy(resolve.active_timeline.settings.frame_rate)
current_timecode = copy.copy(resolve.active_timeline.timecode)

# SIMPLE
resolve.active_timeline.custom_settings(True)

in_half_sec = dpg.get_total_time()
while dpg.is_dearpygui_running():
tf = dpg.get_total_time()

# TODO: Check Resolve is open, lock up whole interface with warning otherwise
# No option to dismiss dialog box. Automatically dismiss box when Resolve is opened
dpg.render_dearpygui_frame()

# TODO: Check timeline is open, lock up whole interface with warning otherwise
# No option to dismiss dialog box. Automatically dismiss box when timeline is opened
# EVERY HALF SECOND
if (tf - in_half_sec) > 1:
in_half_sec = tf

# TODO: Check timeline is same as tracked timeline, disable changes page
# On each timeline change, ensure custom settings are enabled. Make it so.
# REFRESH API GLOBALS
markers = copy.copy(resolve.active_timeline.markers)
frame_rate = copy.copy(resolve.active_timeline.settings.frame_rate)
current_timecode = copy.copy(resolve.active_timeline.timecode)

routines.check_timecode_starts_at_zero(current_timecode, frame_rate)
routines.refresh_add_status(markers, current_timecode, frame_rate)
routines.refresh_commit_status(markers)
# SIMPLE
resolve.active_timeline.custom_settings(True)

dpg.render_dearpygui_frame()
# TODO: Check Resolve is open, lock up whole interface with warning otherwise
# No option to dismiss dialog box. Automatically dismiss box when Resolve is opened

# TODO: Check timeline is open, lock up whole interface with warning otherwise
# No option to dismiss dialog box. Automatically dismiss box when timeline is opened

# TODO: Check timeline is same as tracked timeline, disable changes page
# On each timeline change, ensure custom settings are enabled. Make it so.

routines.check_timecode_starts_at_zero(current_timecode, frame_rate)
routines.refresh_add_status(markers, current_timecode, frame_rate)
routines.refresh_commit_status(markers)


# TODO: Fix save init file
dpg.save_init_file(os.path.join(root_folder, "dpg.ini"))
dpg.destroy_context()
32 changes: 3 additions & 29 deletions src/patchwork/routines.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,13 @@
from datetime import datetime, timedelta
from timecode import Timecode
from dearpygui import dearpygui as dpg
from pydavinci.wrappers.marker import MarkerCollection
from widgets import dialog_box

# TODO: Fix this!
# While it does block functions from running every half second
# It also allows multiple function calls at dpg's refresh rate for the next half second...
def is_refreshable(refresh_rate:float) -> bool:

current_time = datetime.now()
last_run = dpg.get_value(f"{refresh_rate}_lastrun")

if last_run == None:
with dpg.value_registry():
dpg.add_string_value(tag=f"{refresh_rate}_lastrun", default_value=str(current_time.strftime('%y%m%d%H%M%S')))
last_run = dpg.get_value(f"{refresh_rate}_lastrun")

last_run = datetime.strptime(last_run, '%y%m%d%H%M%S')
if current_time - last_run < timedelta(seconds=refresh_rate):
return False

dpg.set_value(f"{refresh_rate}_lastrun", str(current_time.strftime('%y%m%d%H%M%S')))
return True
import trio

def refresh_add_status(markers:MarkerCollection, current_timecode:str, frame_rate:float, refresh_rate:float=0.5):

if not is_refreshable(refresh_rate):
return
# await trio.sleep(refresh_rate)

current_frame = Timecode(frame_rate, current_timecode).frames
current_marker = None
Expand Down Expand Up @@ -71,8 +51,7 @@ def check_timecode_starts_at_zero(current_timecode:str, frame_rate:float, refres
start_timecode_check_dismissed (bool): The flag to check for dialog box dismissal
"""

if not is_refreshable(refresh_rate):
return
# await trio.sleep(refresh_rate)

dismissed = dpg.get_value("zero_timecode_warning_dismissed")
if dismissed is None:
Expand All @@ -91,11 +70,6 @@ def check_timecode_starts_at_zero(current_timecode:str, frame_rate:float, refres

def refresh_commit_status(markers:MarkerCollection, refresh_rate:float=0.5):

if not is_refreshable(refresh_rate):
return
else:
print("hey")

committed_changes = []
uncommitted_changes = []
invalid_changes = []
Expand Down

0 comments on commit df04546

Please sign in to comment.