diff --git a/__init__.py b/__init__.py index 0f4f85d..4e45700 100644 --- a/__init__.py +++ b/__init__.py @@ -36,6 +36,9 @@ if 'bpy' in locals(): import bpy def register(): + print('Register update script handler') + bpy.app.handlers.frame_change_post.append(update_text_strips) + if bpy.app.background: return @@ -43,10 +46,12 @@ def register(): module.register() bpy.app.handlers.frame_change_post.append(set_active_strip) - bpy.app.handlers.frame_change_post.append(update_text_strips) + def unregister(): + bpy.app.handlers.frame_change_post.remove(update_text_strips) + try: bpy.utils.previews.remove(ASSET_PREVIEWS) except Exception as e: @@ -58,8 +63,6 @@ def unregister(): return bpy.app.handlers.frame_change_post.remove(set_active_strip) - bpy.app.handlers.frame_change_post.remove(update_text_strips) - for module in reversed(modules): module.unregister() diff --git a/file_utils.py b/file_utils.py index 752c239..6db3700 100644 --- a/file_utils.py +++ b/file_utils.py @@ -140,4 +140,13 @@ def open_file(filepath, env=None, select=False): cmd += [str(filepath)] - subprocess.Popen(cmd, env=env) \ No newline at end of file + subprocess.Popen(cmd, env=env) + +def parse(string, template): + template = re.sub(r'{index:(.+?)}', r'(?P.+)', template) + reg = re.sub(r'{(.+?)}', r'(?P<_\1>.+)', template) + + values = list(re.search(reg, string).groups()) + keys = re.findall(r'{(.+?)}', template) + ['index'] + + return dict(zip(keys, values)) diff --git a/operators/sequencer.py b/operators/sequencer.py index faa2e58..8656299 100644 --- a/operators/sequencer.py +++ b/operators/sequencer.py @@ -4,7 +4,7 @@ from bpy.types import Operator from bpy.props import (BoolProperty, StringProperty) from vse_toolbox.sequencer_utils import (get_strips, rename_strips, set_channels, - get_channel_index, new_text_strip) + get_channel_index, new_text_strip, get_strip_at) from vse_toolbox.bl_utils import get_scene_settings @@ -212,17 +212,105 @@ class VSETB_OT_set_stamps(Operator): return {"FINISHED"} +class VSETB_OT_previous_shot(Operator): + bl_idname = "vse_toolbox.previous_shot" + bl_label = "Jump to Previous Shot" + bl_description = "Jump to Previous Shot" + bl_options = {"REGISTER", "UNDO"} + + def execute(self, context): + strips = get_strips('Shots') + if not strips: + return {"CANCELLED"} + + active_strip = get_strip_at('Shots') + if active_strip is strips[0]: + return {"CANCELLED"} + + active_strip_index = strips.index(active_strip) + next_shot = strips[active_strip_index - 1] + context.scene.frame_set(next_shot.frame_final_start) + + bpy.ops.sequencer.select_all(action="DESELECT") + next_shot.select = True + context.scene.sequence_editor.active_strip = next_shot + + return {"FINISHED"} + + +class VSETB_OT_next_shot(Operator): + bl_idname = "vse_toolbox.next_shot" + bl_label = "Jump to Next Shot" + bl_description = "Jump to Next Shot" + bl_options = {"REGISTER", "UNDO"} + + def execute(self, context): + + strips = get_strips('Shots') + if not strips: + return {"CANCELLED"} + + active_strip = get_strip_at('Shots') + if active_strip is strips[-1]: + return {"CANCELLED"} + + active_strip_index = strips.index(active_strip) + next_shot = strips[active_strip_index + 1] + context.scene.frame_set(next_shot.frame_final_start) + + bpy.ops.sequencer.select_all(action="DESELECT") + next_shot.select = True + context.scene.sequence_editor.active_strip = next_shot + + return {"FINISHED"} + + +addon_keymaps = [] +def register_keymaps(): + addon = bpy.context.window_manager.keyconfigs.addon + + if not addon: + return + + #print('VSE Toolbox Keymaps Register') + + km = addon.keymaps.new(name="Sequencer", space_type="SEQUENCE_EDITOR") + + kmi = km.keymap_items.new('vse_toolbox.previous_shot', type='LEFT_ARROW', value='PRESS', ctrl=True) + addon_keymaps.append((km, kmi)) + + kmi = km.keymap_items.new('vse_toolbox.next_shot', type='RIGHT_ARROW', value='PRESS', ctrl=True) + addon_keymaps.append((km, kmi)) + + +def unregister_keymaps(): + #print('unregister_keymaps', addon_keymaps) + for km, kmi in addon_keymaps: + if kmi in list(km.keymap_items): + km.keymap_items.remove(kmi) + + addon_keymaps.clear() + + + classes = ( VSETB_OT_rename, VSETB_OT_set_sequencer, VSETB_OT_set_stamps, VSETB_OT_show_waveform, + VSETB_OT_previous_shot, + VSETB_OT_next_shot ) def register(): for cls in classes: bpy.utils.register_class(cls) + + register_keymaps() + def unregister(): for cls in reversed(classes): - bpy.utils.unregister_class(cls) \ No newline at end of file + bpy.utils.unregister_class(cls) + + unregister_keymaps() diff --git a/operators/tracker.py b/operators/tracker.py index c087485..be74aaf 100644 --- a/operators/tracker.py +++ b/operators/tracker.py @@ -286,6 +286,7 @@ class VSETB_OT_upload_to_tracker(Operator): col.separator() col.prop(self, 'casting', text='Casting') col.prop(self, 'custom_data', text='Custom Data') + col.prop(self, 'set_main_preview', text='Set Main Preview') def execute(self, context): #self.report({'ERROR'}, f'Export not implemented yet.') @@ -345,6 +346,7 @@ class VSETB_OT_upload_to_tracker(Operator): if status or preview: tracker.new_comment(task, comment=self.comment, status=status, preview=preview, set_main_preview=self.set_main_preview) + if self.custom_data: metadata = strip.vsetb_strip_settings.metadata.to_dict() description = strip.vsetb_strip_settings.description diff --git a/sequencer_utils.py b/sequencer_utils.py index 96411c4..8385233 100644 --- a/sequencer_utils.py +++ b/sequencer_utils.py @@ -8,7 +8,7 @@ import bpy from bpy.app.handlers import persistent from vse_toolbox.bl_utils import get_scene_settings, get_strip_settings -from vse_toolbox.file_utils import install_module +from vse_toolbox.file_utils import install_module, parse from vse_toolbox.constants import SOUND_SUFFIXES #import multiprocessing #from multiprocessing.pool import ThreadPool @@ -130,8 +130,21 @@ def set_channels(): def get_strip_render_path(strip, template): scn = bpy.context.scene + settings = get_scene_settings() + project = settings.active_project + suffix = Path(scn.render.frame_path()).suffix - render_path = template.format(strip_name=strip.name, ext=suffix[1:]) + + strip_data = parse(strip.name, template=project.shot_template) + + print(strip_data) + + index = int(strip_data['index']) + + sequence = get_strip_sequence_name(strip) + render_path = template.format(episode=project.episode_name, sequence=sequence, + strip=strip.name, index=index, ext=suffix[1:]) + return Path(os.path.abspath(bpy.path.abspath(render_path))) ''' @@ -392,6 +405,9 @@ def set_active_strip(scene): @persistent def update_text_strips(scene): + + print("update_text_strips") + scn = bpy.context.scene if not scn.sequence_editor: return