From 0e416a2927f50cb6440b9ab4ffffb62ba2be4674 Mon Sep 17 00:00:00 2001 From: Clement Ducarteron Date: Thu, 23 Mar 2023 17:33:49 +0100 Subject: [PATCH] add MetaData from Tracker --- panels.py | 27 +++++++++++++ properties.py | 75 ++++++++++++++++++++++++++++--------- resources/trackers/kitsu.py | 13 +++++-- 3 files changed, 94 insertions(+), 21 deletions(-) diff --git a/panels.py b/panels.py index c999c2a..09643cc 100644 --- a/panels.py +++ b/panels.py @@ -154,10 +154,37 @@ class VSETB_PT_casting(VSETB_main, Panel): col_tool.operator('sequencer.paste_casting', icon='PASTEDOWN', text="") +class VSETB_PT_metadata(VSETB_main, Panel): + bl_label = "Shot Metadata" + bl_parent_id = "VSETB_PT_casting" + bl_options = {"DEFAULT_CLOSED"} + + def draw(self, context): + layout = self.layout + scn = context.scene + active_strip = scn.sequence_editor.active_strip + + if not active_strip: + return + + settings = get_scene_settings() + strip_settings = get_strip_settings() + + project = settings.active_project + + if not project: + return + + col = layout.column() + for key in strip_settings.metadata.keys(): + print('key: ', key) + col.prop(strip_settings.metadata, key) + classes=( VSETB_PT_main, VSETB_PT_rename, VSETB_PT_casting, + VSETB_PT_metadata, ) def register(): diff --git a/properties.py b/properties.py index 7bcdde3..991bdc1 100644 --- a/properties.py +++ b/properties.py @@ -44,7 +44,6 @@ def update_episodes(self, context): def get_tracker_items(self, context): return [(norm_str(a.name, format=str.upper), a.name, "", i) for i, a in enumerate(TRACKERS)] - class Asset(PropertyGroup): name : StringProperty(default='') id : StringProperty(default='') @@ -80,6 +79,21 @@ class AssetCasting(PropertyGroup): def to_dict(self): return {k: v for k,v in self.items()} + +class MetaDataTypes(PropertyGroup): + choices : EnumProperty(items=[('NONE', 'None', '', 0)]) + + +class MetaData(PropertyGroup): + + notes : StringProperty() + + def __iter__(self): + return (getattr(self, k) for k in self.keys()) + + def keys(self): + return (p for p in self.bl_rna.properties.keys() if p not in ('rna_type', 'name')) + class Episode(PropertyGroup): id : StringProperty(default='') @@ -110,15 +124,7 @@ class Project(PropertyGroup): episode_name : EnumProperty(items=get_episodes_items) episodes : CollectionProperty(type=Episode) assets : CollectionProperty(type=Asset) - - -#FIXME Trouver une solution pour mettre des method dans les CollectionProperty -class Projects(PropertyGroup): - pass - # @property - # def active(self): - # settings = get_scene_settings() - # return self.get(settings.project_name) + metadata_types : CollectionProperty(type=MetaDataTypes) class VSETB_UL_casting(UIList): @@ -130,13 +136,13 @@ class VSETB_UL_casting(UIList): settings = get_scene_settings() project = settings.active_project - - # asset = next((a for a in project.assets if a.id == item.id), None) + asset = item.asset if asset is None: #TODO deal if asset was removed - pass - + layout.label(text='Load Assets') + return + icon_id = asset.icon_id params = {'icon_value': icon_id} if icon_id else {'icon': 'BLANK1'} @@ -189,9 +195,13 @@ class VSETB_PGT_scene_settings(PropertyGroup): projects : CollectionProperty(type=Project) project_name : EnumProperty(items=get_project_items, update=update_episodes) tracker_name : EnumProperty(items=get_tracker_items) - toogle_prefs : BoolProperty(description='Toogle VSE ToolBox Preferences', default=True) + + toogle_prefs : BoolProperty( + description='Toogle VSE ToolBox Preferences', default=True) + auto_select_strip : BoolProperty( name='Auto Select Strip',description='Auto select strip', default=True) + channel : EnumProperty( items=[ ('AUDIO', 'Audio', '', 0), @@ -203,7 +213,7 @@ class VSETB_PGT_scene_settings(PropertyGroup): sequence_channel_name : StringProperty( name="Sequences Channel Name", default="Sequences") - + shot_channel_name : StringProperty( name="Shot Channel Name", default="Shots") @@ -217,18 +227,46 @@ class VSETB_PGT_scene_settings(PropertyGroup): project = self.active_project if project: return project.episodes.get(project.episode_name) + """ + def load_metadata_types(self): + settings = get_scene_settings() + print('settings: ', settings) + + for project in settings.projects: + print('project: ', project) + + metadata_props = {'__annotations__': {key : StringProperty() for key in project.metadata_types.keys()}} + MetadataProps = type(f"{project.name}_MetaData", (PropertyGroup,), metadata_props) + bpy.utils.register_class(MetadataProps) + + setattr(VSETB_PGT_strip_settings, 'metadata', PointerProperty(type=MetadataProps)) + + # if "__annotations__" not in MetaData.__dict__: + # setattr(MetaData, "__annotations__", {}) + # for metadata_type in project.metadata_types: + # print('metadata_type: ', metadata_type) + # MetaData.__annotations__[metadata_type.name] = StringProperty() + + # bpy.utils.unregister_class(MetaData) + # bpy.utils.register_class(MetaData) + """ + class VSETB_PGT_strip_settings(PropertyGroup): casting : CollectionProperty(type=AssetCasting) casting_index : IntProperty(name='Casting Index', default=0) source_name : StringProperty(name='') + metadata : PointerProperty(type=MetaData) + classes=( Asset, - Episode, - Project, AssetCasting, + Episode, + MetaData, + MetaDataTypes, + Project, VSETB_UL_casting, VSETB_PGT_scene_settings, VSETB_PGT_strip_settings, @@ -242,6 +280,7 @@ def register(): bpy.types.Scene.vsetb_settings = PointerProperty(type=VSETB_PGT_scene_settings) bpy.types.Sequence.vsetb_strip_settings = PointerProperty(type=VSETB_PGT_strip_settings) + # load_metadata_types() def unregister(): for cls in reversed(classes): diff --git a/resources/trackers/kitsu.py b/resources/trackers/kitsu.py index 91ac7f9..9b4450e 100644 --- a/resources/trackers/kitsu.py +++ b/resources/trackers/kitsu.py @@ -37,9 +37,6 @@ class Kitsu(Tracker): def get_episode(self, name): return gazu.shot.get_episode_by_name(self.project, name) - def new_episode(self, name): - return gazu.shot.new_episode(self.project, name) - def get_asset_types(self, project): asset_types = gazu.asset.all_asset_types_for_project(project) return {t['id']:t['name'] for t in asset_types} @@ -53,6 +50,16 @@ class Kitsu(Tracker): return assets + def get_shots_metadata(self, project): + metadata = [] + for md in gazu.project.all_metadata_descriptors(project): + entity_type = md.get('entity_type') + field_name = md.get('field_name') + if entity_type and entity_type.lower() == 'shot' and field_name: + metadata.append(field_name) + + return metadata + def download_preview(self, preview_id, filepath): if isinstance(filepath, str): filepath = Path(filepath)