Skip to content

Commit df04546

Browse files
committed
wip: Counter based task-switching
1 parent 6715c3c commit df04546

File tree

3 files changed

+30
-51
lines changed

3 files changed

+30
-51
lines changed

src/dpg.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Collapsed=0
1010

1111
[Window][###23]
1212
Pos=152,225
13-
Size=458,100
13+
Size=100,100
1414
Collapsed=0
1515

1616
[Window][###93]

src/patchwork/app.py

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ def cancel_callback(self, sender, app_data):
215215
track_patch_file = TrackPatchfile()
216216
render_patch_file = RenderPatchFile()
217217

218-
219218
# Helpers
220219
def get_next_free_marker_num():
221220
"""Get the next marker number in the series"""
@@ -440,32 +439,38 @@ def open_documentation():
440439
dpg.setup_dearpygui()
441440
dpg.show_viewport()
442441

443-
while dpg.is_dearpygui_running():
444-
445-
# REACTIVE VARIABLES
446-
markers = copy.copy(resolve.active_timeline.markers)
447-
frame_rate = copy.copy(resolve.active_timeline.settings.frame_rate)
448-
current_timecode = copy.copy(resolve.active_timeline.timecode)
449442

450-
# SIMPLE
451-
resolve.active_timeline.custom_settings(True)
452-
443+
in_half_sec = dpg.get_total_time()
444+
while dpg.is_dearpygui_running():
445+
tf = dpg.get_total_time()
453446

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

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

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

463-
routines.check_timecode_starts_at_zero(current_timecode, frame_rate)
464-
routines.refresh_add_status(markers, current_timecode, frame_rate)
465-
routines.refresh_commit_status(markers)
458+
# SIMPLE
459+
resolve.active_timeline.custom_settings(True)
466460

467-
dpg.render_dearpygui_frame()
461+
# TODO: Check Resolve is open, lock up whole interface with warning otherwise
462+
# No option to dismiss dialog box. Automatically dismiss box when Resolve is opened
463+
464+
# TODO: Check timeline is open, lock up whole interface with warning otherwise
465+
# No option to dismiss dialog box. Automatically dismiss box when timeline is opened
466+
467+
# TODO: Check timeline is same as tracked timeline, disable changes page
468+
# On each timeline change, ensure custom settings are enabled. Make it so.
469+
470+
routines.check_timecode_starts_at_zero(current_timecode, frame_rate)
471+
routines.refresh_add_status(markers, current_timecode, frame_rate)
472+
routines.refresh_commit_status(markers)
473+
468474

469-
# TODO: Fix save init file
470475
dpg.save_init_file(os.path.join(root_folder, "dpg.ini"))
471476
dpg.destroy_context()

src/patchwork/routines.py

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,13 @@
1-
from datetime import datetime, timedelta
21
from timecode import Timecode
32
from dearpygui import dearpygui as dpg
43
from pydavinci.wrappers.marker import MarkerCollection
54
from widgets import dialog_box
65

7-
# TODO: Fix this!
8-
# While it does block functions from running every half second
9-
# It also allows multiple function calls at dpg's refresh rate for the next half second...
10-
def is_refreshable(refresh_rate:float) -> bool:
11-
12-
current_time = datetime.now()
13-
last_run = dpg.get_value(f"{refresh_rate}_lastrun")
14-
15-
if last_run == None:
16-
with dpg.value_registry():
17-
dpg.add_string_value(tag=f"{refresh_rate}_lastrun", default_value=str(current_time.strftime('%y%m%d%H%M%S')))
18-
last_run = dpg.get_value(f"{refresh_rate}_lastrun")
19-
20-
last_run = datetime.strptime(last_run, '%y%m%d%H%M%S')
21-
if current_time - last_run < timedelta(seconds=refresh_rate):
22-
return False
23-
24-
dpg.set_value(f"{refresh_rate}_lastrun", str(current_time.strftime('%y%m%d%H%M%S')))
25-
return True
6+
import trio
267

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

29-
if not is_refreshable(refresh_rate):
30-
return
10+
# await trio.sleep(refresh_rate)
3111

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

74-
if not is_refreshable(refresh_rate):
75-
return
54+
# await trio.sleep(refresh_rate)
7655

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

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

94-
if not is_refreshable(refresh_rate):
95-
return
96-
else:
97-
print("hey")
98-
9973
committed_changes = []
10074
uncommitted_changes = []
10175
invalid_changes = []

0 commit comments

Comments
 (0)