From f9384c3d891a22f96c52ea617c9a1e353f04d9c8 Mon Sep 17 00:00:00 2001 From: Christophe SEUX Date: Wed, 3 May 2023 14:40:07 +0200 Subject: [PATCH] fix refacto --- operators/addon.py | 2 +- operators/imports.py | 4 +-- operators/sequencer.py | 4 +-- operators/spreadsheet.py | 2 +- sequencer_utils.py | 78 ++++++++++++++++++++-------------------- ui/panels.py | 6 ++-- 6 files changed, 50 insertions(+), 46 deletions(-) diff --git a/operators/addon.py b/operators/addon.py index c847505..4cac142 100644 --- a/operators/addon.py +++ b/operators/addon.py @@ -43,7 +43,7 @@ class VSETB_OT_load_settings(Operator): project = settings.active_project if not prefs.config_path: - return + return {'FINISHED'} addon_config = read_file(os.path.expandvars(prefs.config_path)) diff --git a/operators/imports.py b/operators/imports.py index 7531354..f000ea1 100644 --- a/operators/imports.py +++ b/operators/imports.py @@ -5,10 +5,10 @@ import bpy from bpy.types import Operator from bpy.props import (CollectionProperty, BoolProperty, EnumProperty, StringProperty) -from vse_toolbox.constants import (EDITS, EDIT_SUFFIXES, MOVIES, MOVIE_SUFFIXES, +from vse_toolbox.constants import (EDITS, EDIT_SUFFIXES, MOVIES, MOVIE_SUFFIXES, SOUNDS, SOUND_SUFFIXES) -from vse_toolbox.sequencer_utils import (clean_sequencer, import_edit, import_movie, +from vse_toolbox.sequencer_utils import (clean_sequencer, import_edit, import_movie, import_sound, get_strips) from vse_toolbox.bl_utils import get_scene_settings diff --git a/operators/sequencer.py b/operators/sequencer.py index fdff2bd..96c7ac9 100644 --- a/operators/sequencer.py +++ b/operators/sequencer.py @@ -3,8 +3,8 @@ import bpy 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) +from vse_toolbox.sequencer_utils import (get_strips, rename_strips, set_channels, + get_channel_index, new_text_strip) from vse_toolbox.bl_utils import get_scene_settings diff --git a/operators/spreadsheet.py b/operators/spreadsheet.py index 8669f21..b871503 100644 --- a/operators/spreadsheet.py +++ b/operators/spreadsheet.py @@ -166,7 +166,7 @@ class VSETB_OT_export_spreadsheet(Operator): spreadsheet = project.spreadsheet_export episode = settings.active_episode - cells = [cell for cell in project.spreadsheet if cell.enabled] + cells = [cell for cell in spreadsheet.cells if cell.enabled] rows = [] # Header diff --git a/sequencer_utils.py b/sequencer_utils.py index 6404185..d275450 100644 --- a/sequencer_utils.py +++ b/sequencer_utils.py @@ -101,7 +101,7 @@ def rename_strips( sequence_name = get_strip_sequence_name(strip) if (by_sequence and prev_sequence_name and - sequence_name and sequence != prev_sequence_name): + sequence_name and sequence_name != prev_sequence_name): strip_number = 0 name = template.format( @@ -239,9 +239,9 @@ def render_strips(strips, template): scn.render.filepath = render_path def import_edit(filepath, adapter="cmx_3600", channel='Shots'): - otio = install_module('opentimelineio') + opentimelineio = install_module('opentimelineio') - from otio.schema import ( + from opentimelineio.schema import ( Clip, ExternalReference, Gap, @@ -254,13 +254,9 @@ def import_edit(filepath, adapter="cmx_3600", channel='Shots'): scn = bpy.context.scene sequencer = scn.sequence_editor.sequences - if clear: - for strip in get_strips(channel='Shots'): - sequencer.remove(strip) - edl = Path(filepath) try: - timeline = otio.adapters.read_from_file( + timeline = opentimelineio.adapters.read_from_file( str(edl), adapter, rate=scn.render.fps, ignore_timecode_mismatch=True) except: print("[>.] read_from_file Failed. Using read_from_string method.") @@ -284,36 +280,37 @@ def import_edit(filepath, adapter="cmx_3600", channel='Shots'): continue channel = get_channel_index('Shots') - frame_start = otio.opentime.to_frames( + frame_start = opentimelineio.opentime.to_frames( child.range_in_parent().start_time) - frame_end = frame_start + otio.opentime.to_frames( + frame_end = frame_start + opentimelineio.opentime.to_frames( child.range_in_parent().duration) - try: - strip = next((s for s in sequencer.sequences if s.vsetb_strip_settings.source_name == child.name)) - if strip: - if frame_start != strip.frame_final_start or frame_end !=strip.frame_final_end: - self.report({'INFO'}, f'The strip {strip.name} is updated with new range') + #try: + strip = next((s for s in sequencer if s.vsetb_strip_settings.source_name == child.name), None) + if strip: + if frame_start != strip.frame_final_start or frame_end !=strip.frame_final_end: + print(f'The strip {strip.name} is updated with new range') + #self.report({'INFO'}, f'The strip {strip.name} is updated with new range') - strip.frame_final_start = frame_start - strip.frame_final_end = frame_end - else: - strip = sequencer.new_effect( - name=child.name, - type='COLOR', - channel=channel, - frame_start=frame_start, - frame_end=frame_end, - ) + strip.frame_final_start = frame_start + strip.frame_final_end = frame_end + else: + strip = sequencer.new_effect( + name=child.name, + type='COLOR', + channel=channel, + frame_start=frame_start, + frame_end=frame_end, + ) - strip.blend_alpha = 0.0 - strip.select = False - strip.vsetb_strip_settings.source_name = child.name + strip.blend_alpha = 0.0 + strip.select = False + strip.vsetb_strip_settings.source_name = child.name - except Exception as e: - print('e: ', e) - continue + #except Exception as e: + # print('e: ', e) + # continue scn.frame_end = frame_end-1 return timeline @@ -377,23 +374,28 @@ def clean_sequencer(edit=False, movie=False, sound=False): @persistent def set_active_strip(scene): - #scn = bpy.context.scene - settings = get_scene_settings() - - if not settings.auto_select_strip: + scn = bpy.context.scene + if not scn.sequence_editor: return - - bpy.ops.sequencer.select_all(action="DESELECT") + + if not get_scene_settings().auto_select_strip: + return + + #scene.sequence_editor.active_strip = None shot_strip = get_strip_at('Shots') if shot_strip: + bpy.ops.sequencer.select_all(action="DESELECT") shot_strip.select = True scene.sequence_editor.active_strip = shot_strip @persistent def update_text_strips(scene): - #scn = bpy.context.scene + scn = bpy.context.scene + if not scn.sequence_editor: + return + format_data = { 'scene': scene, 'active_shot_name': 'None', diff --git a/ui/panels.py b/ui/panels.py index 4b8184c..1617c6a 100644 --- a/ui/panels.py +++ b/ui/panels.py @@ -280,6 +280,8 @@ class VSETB_PT_metadata(VSETB_main, Panel): if metadata_type.entity_type == 'SHOT': row = layout.row(align=False) metadata_key = metadata_type.field_name + metadata_label = metadata_key.upper() + if metadata_type.choices: metadata_value = getattr(strip_settings.metadata, metadata_key) icon = 'LAYER_USED' @@ -289,11 +291,11 @@ class VSETB_PT_metadata(VSETB_main, Panel): else: icon = 'ADD' - row.prop_search(strip_settings.metadata, metadata_key, metadata_type, 'choices', + row.prop_search(strip_settings.metadata, metadata_label, metadata_type, 'choices', results_are_suggestions=True, icon=icon) else: - row.prop(strip_settings.metadata, metadata_key, text=metadata_key.upper()) + row.prop(strip_settings.metadata, metadata_key, text=metadata_label) #row.operator('vse_toolbox.copy_metadata', icon='PASTEDOWN', text='', emboss=False).metadata = metadata_key