From 3e8cfec634238233821146d3f885dc8b29846e7c Mon Sep 17 00:00:00 2001 From: Clement Ducarteron Date: Fri, 17 Mar 2023 22:55:06 +0100 Subject: [PATCH] Ui improvment --- file_utils.py | 20 +++++++++++++++ operators/operators.py | 57 +++++++++++++++++++++++++++++++++++------- panels.py | 4 +-- 3 files changed, 70 insertions(+), 11 deletions(-) diff --git a/file_utils.py b/file_utils.py index 820d988..d587bec 100644 --- a/file_utils.py +++ b/file_utils.py @@ -54,6 +54,26 @@ def norm_str(string, separator='_', format=str.lower, padding=0): return string +def norm_name(string, separator='_', format=str.lower, padding=0): + string = str(string) + string = string.split('/')[-1] #used to remove first slash -> albert / albert_casque -> albert_casque + string = string.replace('_', ' ') + string = string.replace('-', ' ') + string = re.sub('[ ]+', ' ', string) + string = re.sub('[ ]+\/[ ]+', '/', string) + string = string.strip() + + if format: + string = format(string) + + # Padd rightest number + string = re.sub(r'(\d+)(?!.*\d)', lambda x : x.group(1).zfill(padding), string) + + string = string.replace(' ', separator) + string = unicodedata.normalize('NFKD', string).encode('ASCII', 'ignore').decode("utf-8") + + return string + def read_file(path): '''Read a file with an extension in (json, yaml, yml, txt)''' diff --git a/operators/operators.py b/operators/operators.py index 92c1b61..20d0ecd 100644 --- a/operators/operators.py +++ b/operators/operators.py @@ -39,7 +39,7 @@ from vse_toolbox.sequencer_utils import ( set_channels, ) from vse_toolbox.bl_utils import get_addon_prefs, get_settings -from vse_toolbox.file_utils import install_module, norm_str +from vse_toolbox.file_utils import install_module, norm_name, norm_str class VSETB_OT_export_csv(Operator): bl_idname = "sequencer.export_csv" @@ -102,8 +102,34 @@ class VSETB_OT_auto_select_files(Operator): return {'FINISHED'} -class VSETB_OT_import(Operator): - bl_idname = "sequencer.import" +# class VSETB_OT_select_file(Operator): +# bl_idname = "import.select_file" +# bl_label = "Select File" +# bl_description = "Select Active as File" +# bl_options = {"REGISTER", "UNDO"} + +# type : StringProperty('') + +# @classmethod +# def poll(cls, context): +# return True + +# def execute(self, context): +# params = context.space_data.params + +# print(params.filename) +# if self.type == 'edit': +# bpy.ops.sequencer.import_files(edit=params.filename) +# elif self.type == 'movie': +# bpy.ops.sequencer.import_files(movie=params.filename) +# elif self.type == 'sound': +# bpy.ops.sequencer.import_files(sound=params.filename) + +# return {'FINISHED'} + + +class VSETB_OT_import_files(Operator): + bl_idname = "sequencer.import_files" bl_label = "Import" bl_description = "Import Edit" bl_options = {"REGISTER", "UNDO"} @@ -116,7 +142,6 @@ class VSETB_OT_import(Operator): subtype='FILE_PATH', ) files : CollectionProperty(type=bpy.types.OperatorFileListElement) - clean_sequencer : BoolProperty( name="Clean Sequencer", default=False, @@ -149,21 +174,27 @@ class VSETB_OT_import(Operator): row = self.layout.row(heading="Import Edit", align=True) row.prop(self, 'import_edit') - sub = row.row() + sub = row.row(align=True) sub.active = self.import_edit sub.prop(self, 'edit') + # op = sub.operator('import.select_file', text="", icon='EYEDROPPER') + # op.type = 'edit' row = self.layout.row(heading="Import Movie", align=True) row.prop(self, 'import_movie') sub = row.row() sub.active = self.import_movie sub.prop(self, 'movie') + # op = sub.operator('import.select_file', text="", icon='EYEDROPPER') + # op.type = 'movie' row = self.layout.row(heading="Import Sound", align=True) row.prop(self, 'import_sound') sub = row.row() sub.active = self.import_sound sub.prop(self, 'sound') + # op = sub.operator('import.select_file', text="", icon='EYEDROPPER') + # op.type = 'sound' col = layout.column() col.separator() @@ -230,10 +261,16 @@ class VSETB_OT_load_assets(Operator): def get_items(self, items=[]): if not items: return [('NONE', 'None', '', 0)] - - item_sorted = [(e.name, e.name, '', i) for i, e in enumerate(sorted(items, key=lambda x:x.name))] - return item_sorted + icons = { + 'camera':'CAMERA_DATA', + 'chars':'COMMUNITY', + 'props':'OBJECT_DATAMODE', + 'sets':'SMOOTHCURVE', + } + # return [(e.name, e.norm_name, '', i) for i, e in enumerate(items)] + return [(e.name, e.name, '', icons[e.asset_type], i) for i, e in enumerate(items)] + def execute(self, context): settings = get_settings() prefs = get_addon_prefs() @@ -249,6 +286,7 @@ class VSETB_OT_load_assets(Operator): for asset_data in assets: asset = project.assets.add() asset.name = asset_data['name'] + # asset.norm_name = norm_name(asset_data['name'], separator=' ', format=str.title) asset.id = asset_data['id'] asset.asset_type = asset_data['asset_type'] @@ -578,13 +616,14 @@ classes=( VSETB_OT_casting_add, VSETB_OT_casting_actions, VSETB_OT_export_csv, - VSETB_OT_import, + VSETB_OT_import_files, VSETB_OT_load_assets, VSETB_OT_load_projects, VSETB_OT_new_episode, VSETB_OT_reload_addon, VSETB_OT_rename, VSETB_OT_render, + # VSETB_OT_select_file, VSETB_OT_set_scene, ) diff --git a/panels.py b/panels.py index ea6b2ce..3ab3e58 100644 --- a/panels.py +++ b/panels.py @@ -52,10 +52,10 @@ class VSETB_PT_main(VSETB_main, Panel): col.separator() col.operator('vse_toolbox.new_episode', text='Add Episode', icon='IMPORT') - # TODO FAIRE DES VRAIS OPS col = layout.column() row = col.row(align=True) - row.operator('sequencer.import', text='Import', icon='IMPORT') + row.operator('sequencer.import_files', text='Import', icon='IMPORT') + # TODO FAIRE DES VRAIS OPS row.operator('sequencer.export_csv', text='Export', icon='EXPORT') op = col.operator('sequencer.strips_render', text='Render Strips', icon='RENDER_ANIMATION')