refacto
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
from vse_toolbox.ui import (panels, preferences, properties)
|
||||
|
||||
modules = (
|
||||
panels,
|
||||
preferences,
|
||||
properties
|
||||
)
|
||||
|
||||
if 'bpy' in locals():
|
||||
import importlib
|
||||
|
||||
for mod in modules:
|
||||
importlib.reload(mod)
|
||||
|
||||
import bpy
|
||||
|
||||
def register():
|
||||
for mod in modules:
|
||||
mod.register()
|
||||
|
||||
def unregister():
|
||||
for mod in modules:
|
||||
mod.unregister()
|
||||
+337
@@ -0,0 +1,337 @@
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import bpy
|
||||
from bpy.types import Panel
|
||||
from bl_ui.utils import PresetPanel
|
||||
|
||||
from vse_toolbox.bl_utils import (get_addon_prefs, get_scene_settings, get_strip_settings)
|
||||
from vse_toolbox.constants import ASSET_PREVIEWS
|
||||
from vse_toolbox.sequencer_utils import (set_active_strip, get_channel_name, get_strips)
|
||||
|
||||
|
||||
class VSETB_main:
|
||||
bl_space_type = "SEQUENCE_EDITOR"
|
||||
bl_region_type = "UI"
|
||||
bl_category = "VSE ToolBox"
|
||||
bl_label = "VSE ToolBox"
|
||||
|
||||
|
||||
class VSETB_PT_main(VSETB_main, Panel):
|
||||
|
||||
def draw_header_preset(self, context):
|
||||
self.layout.operator('vse_toolbox.load_projects', icon='FILE_REFRESH', text='', emboss=False)
|
||||
|
||||
def draw(self, context):
|
||||
wm = context.window_manager
|
||||
scn = context.scene
|
||||
|
||||
settings = get_scene_settings()
|
||||
prefs = get_addon_prefs()
|
||||
|
||||
project = settings.active_project
|
||||
|
||||
layout = self.layout
|
||||
col = layout.column()
|
||||
|
||||
col.prop(settings, 'project_name', text='Project')
|
||||
|
||||
if project:
|
||||
if project.type == 'TVSHOW':
|
||||
col.prop(project, 'episode_name', text='Episodes')
|
||||
|
||||
#col.separator()
|
||||
|
||||
#row = col.row(align=True)
|
||||
|
||||
#row.prop(settings, 'toogle_prefs', text='', icon='PREFERENCES', toggle=True)
|
||||
|
||||
'''
|
||||
if settings.toogle_prefs:
|
||||
box = col.box()
|
||||
col = box.column(align=True)
|
||||
col.use_property_split = True
|
||||
col.use_property_decorate = False
|
||||
|
||||
col.prop(settings, 'project_name', text='Projects')
|
||||
|
||||
if project:
|
||||
if project.type == 'TV Shows':
|
||||
col.prop(project, 'episode_name', text='Episodes')
|
||||
|
||||
#col.prop(project, 'sequence_template')
|
||||
#col.prop(project, 'shot_template')
|
||||
# col.separator()
|
||||
# col.operator('vse_toolbox.new_episode', text='Add Episode', icon='IMPORT')
|
||||
'''
|
||||
|
||||
# Rename
|
||||
|
||||
|
||||
class VSETB_PT_sequencer(VSETB_main, Panel):
|
||||
bl_label = "Sequencer"
|
||||
bl_parent_id = "VSETB_PT_main"
|
||||
|
||||
def draw_header_preset(self, context):
|
||||
settings = get_scene_settings()
|
||||
|
||||
audio_strips = get_strips('Audio')
|
||||
|
||||
depress = any(s.show_waveform for s in audio_strips)
|
||||
self.layout.operator('vse_toolbox.show_waveform', text="", icon="IPO_ELASTIC", depress=depress).enabled = not depress
|
||||
|
||||
ico = ("RESTRICT_SELECT_OFF" if settings.auto_select_strip else "RESTRICT_SELECT_ON")
|
||||
self.layout.prop(settings, "auto_select_strip", text="", icon=ico)
|
||||
|
||||
def draw(self, context):
|
||||
prefs = get_addon_prefs()
|
||||
layout = self.layout
|
||||
settings = get_scene_settings()
|
||||
project = settings.active_project
|
||||
|
||||
col = layout.column()
|
||||
col.operator('vse_toolbox.set_sequencer', text='Set-Up Sequencer', icon='SEQ_SEQUENCER')
|
||||
|
||||
#row = col.row()
|
||||
shot_label = ''
|
||||
sequence_label = ''
|
||||
|
||||
if project:
|
||||
episode = project.episode_name
|
||||
sequence_label = project.sequence_template.format(episode=episode, index=project.sequence_start_number)
|
||||
shot_label = project.shot_template.format(episode=episode, sequence=sequence_label, index=project.shot_start_number)
|
||||
|
||||
#row.separator()
|
||||
|
||||
strip = context.active_sequence_strip
|
||||
channel_name = get_channel_name(strip) or ''
|
||||
if channel_name == 'Shots':
|
||||
label = shot_label
|
||||
elif channel_name == 'Sequences':
|
||||
label = sequence_label
|
||||
else:
|
||||
label = 'Not Supported'
|
||||
|
||||
row = col.row(align=True)
|
||||
if label == 'Not Supported':
|
||||
row.enabled = False
|
||||
|
||||
op = row.operator('vse_toolbox.strips_rename', text=f'Rename {channel_name} ( {label} )', icon='SORTALPHA')
|
||||
op.channel_name = channel_name
|
||||
|
||||
col.operator('vse_toolbox.set_stamps', text='Set Stamps', icon='COLOR')
|
||||
|
||||
|
||||
class VSETB_PT_settings(VSETB_main, Panel):
|
||||
bl_label = "Settings"
|
||||
bl_parent_id = "VSETB_PT_main"
|
||||
bl_options = {'DEFAULT_CLOSED'}
|
||||
|
||||
#def draw_header_preset(self, context):
|
||||
# self.layout.operator('vse_toolbox.import_files', icon='IMPORT', text='', emboss=False)
|
||||
|
||||
def draw(self, context):
|
||||
prefs = get_addon_prefs()
|
||||
layout = self.layout
|
||||
settings = get_scene_settings()
|
||||
project = settings.active_project
|
||||
|
||||
col = layout.column()
|
||||
#row = col.row(align=True)
|
||||
col.prop(project, 'sequence_template')
|
||||
col.prop(project, 'shot_template')
|
||||
col.prop(project, 'render_template')
|
||||
|
||||
|
||||
class VSETB_PT_imports(VSETB_main, Panel):
|
||||
bl_label = "Imports"
|
||||
bl_parent_id = "VSETB_PT_main"
|
||||
bl_options = {'DEFAULT_CLOSED'}
|
||||
|
||||
def draw_header_preset(self, context):
|
||||
self.layout.operator('vse_toolbox.import_files', icon='IMPORT', text='', emboss=False)
|
||||
|
||||
def draw(self, context):
|
||||
prefs = get_addon_prefs()
|
||||
layout = self.layout
|
||||
settings = get_scene_settings()
|
||||
project = settings.active_project
|
||||
|
||||
col = layout.column()
|
||||
#row = col.row(align=True)
|
||||
col.operator('vse_toolbox.import_files', text='Import', icon='IMPORT')
|
||||
|
||||
|
||||
class VSETB_PT_presets(PresetPanel, Panel):
|
||||
bl_label = 'Spreadsheet Presets'
|
||||
preset_subdir = 'vse_toolbox'
|
||||
preset_operator = 'script.execute_preset'
|
||||
preset_add_operator = "vse_toolbox.add_spreadsheet_preset"
|
||||
|
||||
|
||||
class VSETB_PT_exports(VSETB_main, Panel):
|
||||
bl_label = "Exports"
|
||||
bl_parent_id = "VSETB_PT_main"
|
||||
bl_options = {'DEFAULT_CLOSED'}
|
||||
|
||||
def draw_header_preset(self, context):
|
||||
self.layout.operator('vse_toolbox.export_spreadsheet', icon='EXPORT', text='', emboss=False)
|
||||
|
||||
def draw(self, context):
|
||||
prefs = get_addon_prefs()
|
||||
layout = self.layout
|
||||
settings = get_scene_settings()
|
||||
project = settings.active_project
|
||||
|
||||
# TODO FAIRE DES VRAIS OPS
|
||||
layout.operator('vse_toolbox.strips_render', text='Render Strips', icon='SEQUENCE')
|
||||
|
||||
tracker_label = settings.tracker_name.title().replace('_', ' ')
|
||||
layout.operator('vse_toolbox.upload_to_tracker', text=f'Upload to {tracker_label}', icon='EXPORT')
|
||||
layout.operator('vse_toolbox.export_spreadsheet', text='Export Spreadsheet', icon='SPREADSHEET')
|
||||
|
||||
|
||||
class VSETB_PT_casting(VSETB_main, Panel):
|
||||
bl_label = "Casting"
|
||||
bl_parent_id = "VSETB_PT_main"
|
||||
|
||||
def draw_header_preset(self, context):
|
||||
active_strip = context.scene.sequence_editor.active_strip
|
||||
self.layout.label(text=active_strip.name)
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
strip = context.scene.sequence_editor.active_strip
|
||||
return strip and get_channel_name(strip) == 'Shots'
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
settings = get_scene_settings()
|
||||
strip_settings = get_strip_settings()
|
||||
|
||||
project = settings.active_project
|
||||
|
||||
if not project:
|
||||
return
|
||||
|
||||
if not project.assets:
|
||||
row = layout.row(align=True)
|
||||
row.label(text='No Assets in this Project')
|
||||
else:
|
||||
|
||||
row = layout.row()
|
||||
col = row.column()
|
||||
col.template_list("VSETB_UL_casting", "shot_casting", strip_settings, "casting", strip_settings, "casting_index", rows=6)
|
||||
|
||||
col_tool = row.column(align=True)
|
||||
col_tool.operator('vse_toolbox.casting_add', icon='ADD', text="")
|
||||
col_tool.operator('vse_toolbox.casting_remove', icon='REMOVE', text="")
|
||||
col_tool.separator()
|
||||
col_tool.operator('vse_toolbox.casting_move', icon='TRIA_UP', text="").direction = 'UP'
|
||||
col_tool.operator('vse_toolbox.casting_move', icon='TRIA_DOWN', text="").direction = 'DOWN'
|
||||
col_tool.separator()
|
||||
col_tool.operator('vse_toolbox.copy_casting', icon='COPYDOWN', text="")
|
||||
col_tool.operator('vse_toolbox.paste_casting', icon='PASTEDOWN', text="")
|
||||
col_tool.separator()
|
||||
|
||||
col_tool.operator('vse_toolbox.casting_replace', icon='ZOOM_ALL', text="")
|
||||
|
||||
if strip_settings.casting:
|
||||
casting_item = strip_settings.casting[strip_settings.casting_index]
|
||||
asset = casting_item.asset
|
||||
if asset:
|
||||
if asset.icon_id:
|
||||
row = col.row(align=True)
|
||||
#row.scale_y = 0.5
|
||||
# box = col.box()
|
||||
# box.template_icon(icon_value=ico.icon_id, scale=7.5)
|
||||
|
||||
row.template_icon_view(asset, "previews", show_labels=False)
|
||||
|
||||
|
||||
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
|
||||
|
||||
row = layout.row()
|
||||
layout.prop(strip_settings, 'description', text='DESCRIPTION')
|
||||
|
||||
#col = layout.column()
|
||||
for metadata_type in project.metadata_types:
|
||||
if metadata_type.entity_type == 'SHOT':
|
||||
row = layout.row(align=False)
|
||||
metadata_key = metadata_type.field_name
|
||||
if metadata_type.choices:
|
||||
metadata_value = getattr(strip_settings.metadata, metadata_key)
|
||||
icon = 'LAYER_USED'
|
||||
if metadata_value:
|
||||
if metadata_value in metadata_type.choices:
|
||||
icon = 'DOT'
|
||||
else:
|
||||
icon = 'ADD'
|
||||
|
||||
row.prop_search(strip_settings.metadata, metadata_key, metadata_type, 'choices',
|
||||
results_are_suggestions=True, icon=icon)
|
||||
|
||||
else:
|
||||
row.prop(strip_settings.metadata, metadata_key, text=metadata_key.upper())
|
||||
|
||||
#row.operator('vse_toolbox.copy_metadata', icon='PASTEDOWN', text='', emboss=False).metadata = metadata_key
|
||||
|
||||
def context_menu_prop(self, context):
|
||||
if not hasattr(context, 'button_prop') or context.space_data.type != 'SEQUENCE_EDITOR':
|
||||
return
|
||||
|
||||
settings = get_strip_settings()
|
||||
if not settings:
|
||||
return
|
||||
|
||||
button_prop = context.button_prop
|
||||
if button_prop not in settings.metadata.bl_rna.properties.values():
|
||||
return
|
||||
|
||||
layout = self.layout
|
||||
layout.separator()
|
||||
layout.operator('vse_toolbox.copy_metadata', icon='PASTEDOWN', text='Copy metadata to selected').metadata = button_prop.name
|
||||
|
||||
|
||||
classes = (
|
||||
VSETB_PT_main,
|
||||
VSETB_PT_imports,
|
||||
VSETB_PT_sequencer,
|
||||
VSETB_PT_casting,
|
||||
VSETB_PT_metadata,
|
||||
VSETB_PT_presets,
|
||||
VSETB_PT_exports,
|
||||
)
|
||||
|
||||
def register():
|
||||
for cls in classes:
|
||||
bpy.utils.register_class(cls)
|
||||
|
||||
bpy.types.UI_MT_button_context_menu.append(context_menu_prop)
|
||||
|
||||
def unregister():
|
||||
for cls in reversed(classes):
|
||||
bpy.utils.unregister_class(cls)
|
||||
|
||||
bpy.types.UI_MT_button_context_menu.remove(context_menu_prop)
|
||||
@@ -0,0 +1,159 @@
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
import bpy
|
||||
import inspect
|
||||
import os
|
||||
|
||||
from bpy.props import (
|
||||
BoolProperty,
|
||||
EnumProperty,
|
||||
FloatProperty,
|
||||
IntProperty,
|
||||
PointerProperty,
|
||||
StringProperty,
|
||||
)
|
||||
|
||||
from bpy.types import (
|
||||
AddonPreferences,
|
||||
PropertyGroup,
|
||||
)
|
||||
from vse_toolbox.bl_utils import get_addon_prefs, get_scene_settings
|
||||
from vse_toolbox.constants import (
|
||||
TRACKERS,
|
||||
TRACKERS_DIR,
|
||||
)
|
||||
from vse_toolbox.file_utils import (
|
||||
import_module_from_path,
|
||||
norm_str,
|
||||
read_file,
|
||||
)
|
||||
from vse_toolbox.resources.trackers.kitsu import Kitsu
|
||||
|
||||
def load_trackers():
|
||||
from vse_toolbox.resources.trackers.tracker import Tracker
|
||||
|
||||
TRACKERS.clear()
|
||||
tracker_files = list(TRACKERS_DIR.glob('*.py'))
|
||||
|
||||
for tracker_file in tracker_files:
|
||||
if tracker_file.stem.startswith('_'):
|
||||
continue
|
||||
|
||||
mod = import_module_from_path(tracker_file)
|
||||
for name, obj in inspect.getmembers(mod):
|
||||
|
||||
if not inspect.isclass(obj):
|
||||
continue
|
||||
|
||||
if not Tracker in obj.__mro__:
|
||||
continue
|
||||
|
||||
if obj is Tracker or name in (a.__name__ for a in TRACKERS):
|
||||
continue
|
||||
|
||||
try:
|
||||
print(f'Register Tracker {name}')
|
||||
bpy.utils.register_class(obj)
|
||||
#obj.register()
|
||||
|
||||
setattr(Trackers, norm_str(name), PointerProperty(type=obj))
|
||||
TRACKERS.append(obj)
|
||||
except Exception as e:
|
||||
print(f'Could not register Tracker {name}')
|
||||
print(e)
|
||||
|
||||
def load_prefs():
|
||||
prefs = get_addon_prefs()
|
||||
prefs_config_file = prefs.config_path
|
||||
|
||||
if not prefs_config_file:
|
||||
return
|
||||
|
||||
prefs_datas = read_file(os.path.expandvars(prefs_config_file))
|
||||
|
||||
for tracker_data in prefs_datas['trackers']:
|
||||
tracker_name = norm_str(tracker_data['name'])
|
||||
if not hasattr(prefs.trackers, tracker_name):
|
||||
continue
|
||||
|
||||
tracker_pref = getattr(prefs.trackers, tracker_name)
|
||||
|
||||
if not tracker_pref:
|
||||
continue
|
||||
|
||||
for k, v in tracker_data.items():
|
||||
if k in ('name',):
|
||||
continue
|
||||
setattr(tracker_pref, k, os.path.expandvars(v))
|
||||
|
||||
prefs['tracker_name'] = prefs_datas['tracker_name']
|
||||
|
||||
|
||||
class Trackers(PropertyGroup):
|
||||
def __iter__(self):
|
||||
return (getattr(self, p) for p in self.bl_rna.properties.keys() if p not in ('rna_type', 'name'))
|
||||
|
||||
|
||||
class VSETB_Prefs(AddonPreferences):
|
||||
bl_idname = __package__
|
||||
|
||||
trackers : PointerProperty(type=Trackers)
|
||||
expand_settings: BoolProperty(default=False)
|
||||
config_path : StringProperty(subtype='FILE_PATH')
|
||||
sort_metadata_items : BoolProperty(default=True)
|
||||
|
||||
@property
|
||||
def tracker(self):
|
||||
return getattr(self.trackers, norm_str(get_scene_settings().tracker_name))
|
||||
|
||||
def draw(self, context):
|
||||
prefs = get_addon_prefs()
|
||||
settings = get_scene_settings()
|
||||
|
||||
layout = self.layout
|
||||
|
||||
layout.prop(self, 'config_path', text='Config Path')
|
||||
layout.prop(self, "sort_metadata_items", text='Sort Metadata Items')
|
||||
|
||||
col = layout.column(align=True)
|
||||
box = col.box()
|
||||
row = box.row(align=True)
|
||||
icon = "DISCLOSURE_TRI_DOWN" if self.expand_settings else "DISCLOSURE_TRI_RIGHT"
|
||||
row.prop(self, 'expand_settings', icon=icon, emboss=False, text='')
|
||||
row.label(icon='PREFERENCES')
|
||||
row.label(text='Tracker')
|
||||
subrow = row.row()
|
||||
subrow.alignment = 'RIGHT'
|
||||
subrow.operator("vse_toolbox.reload_addon", text='Reload Addon')
|
||||
|
||||
if self.expand_settings:
|
||||
box.prop(settings, 'tracker_name', text='Tracker')
|
||||
self.tracker.draw_prefs(box)
|
||||
#row = box.row()
|
||||
box.operator("vse_toolbox.tracker_connect", text='Connect')
|
||||
|
||||
|
||||
classes = [
|
||||
Trackers,
|
||||
VSETB_Prefs,
|
||||
]
|
||||
|
||||
|
||||
def register():
|
||||
for cls in classes:
|
||||
bpy.utils.register_class(cls)
|
||||
|
||||
load_trackers()
|
||||
prefs = get_addon_prefs()
|
||||
|
||||
config_path = os.getenv('VSE_TOOLBOX_CONFIG')
|
||||
if config_path:
|
||||
prefs['config_path'] = os.path.expandvars(config_path)
|
||||
|
||||
load_prefs()
|
||||
|
||||
def unregister():
|
||||
for cls in reversed(classes + TRACKERS):
|
||||
bpy.utils.unregister_class(cls)
|
||||
|
||||
TRACKERS.clear()
|
||||
@@ -0,0 +1,488 @@
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
import bpy
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from bpy.props import (
|
||||
BoolProperty,
|
||||
CollectionProperty,
|
||||
EnumProperty,
|
||||
IntProperty,
|
||||
PointerProperty,
|
||||
StringProperty,
|
||||
)
|
||||
from bpy.types import PropertyGroup, UIList
|
||||
from pprint import pprint as pp
|
||||
from vse_toolbox.bl_utils import get_addon_prefs, get_scene_settings
|
||||
from vse_toolbox.constants import ASSET_PREVIEWS, TRACKERS, PREVIEWS_DIR
|
||||
from vse_toolbox.file_utils import norm_str
|
||||
|
||||
|
||||
def get_episodes_items(self, context):
|
||||
settings = get_scene_settings()
|
||||
|
||||
project = settings.active_project
|
||||
if not project:
|
||||
return [('/', '/', '', 0)]
|
||||
|
||||
episodes = project.episodes
|
||||
if not episodes:
|
||||
return [('/', '/', '', 0)]
|
||||
|
||||
return [(e, e, '', i) for i, e in enumerate(episodes.keys())]
|
||||
|
||||
def get_project_items(self, context):
|
||||
if not self.projects:
|
||||
return [('/', '/', '', 0)]
|
||||
|
||||
return [(p, p, '', i) for i, p in enumerate(self.projects.keys())]
|
||||
|
||||
def on_project_updated(self, context):
|
||||
settings = get_scene_settings()
|
||||
settings['episodes'] = 0
|
||||
|
||||
#print('Update active Project')
|
||||
|
||||
bpy.ops.vse_toolbox.load_assets()
|
||||
|
||||
if settings.active_project:
|
||||
settings.active_project.set_strip_metadata()
|
||||
|
||||
os.environ['TRACKER_PROJECT_ID'] = settings.active_project.id
|
||||
|
||||
def on_episode_updated(self, context):
|
||||
settings = get_scene_settings()
|
||||
os.environ['TRACKER_EPISODE_ID'] = settings.active_episode.id
|
||||
|
||||
def get_tracker_items(self, context):
|
||||
return [(norm_str(a.__name__, format=str.upper), a.__name__, "", i) for i, a in enumerate(TRACKERS)]
|
||||
|
||||
|
||||
class CollectionPropertyGroup(PropertyGroup):
|
||||
def __iter__(self):
|
||||
return (v for v in self.values())
|
||||
|
||||
def props(self):
|
||||
return [p for p in self.bl_rna.properties if p.identifier not in ('rna_type', 'name')]
|
||||
|
||||
def keys(self):
|
||||
return [k for k in self.bl_rna.properties.keys() if k not in ('rna_type', 'name')]
|
||||
|
||||
def values(self):
|
||||
return [getattr(self, k) for k in self.keys()]
|
||||
|
||||
def items(self):
|
||||
return self.to_dict().items()
|
||||
|
||||
def to_dict(self, use_name=True):
|
||||
if use_name:
|
||||
return {p.name: getattr(self, p.identifier) for p in self.props()}
|
||||
else:
|
||||
return {k: getattr(self, k) for k in self.keys()}
|
||||
|
||||
|
||||
def get_preview_items(self, context):
|
||||
if self.icon_id:
|
||||
return [(self.preview, self.tracker_name, '', self.icon_id, 0)]
|
||||
|
||||
return []
|
||||
|
||||
|
||||
class Asset(PropertyGroup):
|
||||
name : StringProperty(default='')
|
||||
id : StringProperty(default='')
|
||||
norm_name : StringProperty(default='')
|
||||
asset_type : StringProperty(default='')
|
||||
tracker_name : StringProperty(default='')
|
||||
preview : StringProperty(default='')
|
||||
previews : EnumProperty(items=get_preview_items)
|
||||
|
||||
@property
|
||||
def label(self):
|
||||
return f"{self.asset_type} / {self.tracker_name}"
|
||||
|
||||
@property
|
||||
def icon_id(self):
|
||||
ico = ASSET_PREVIEWS.get(self.preview)
|
||||
if ico:
|
||||
return ico.icon_id
|
||||
|
||||
|
||||
class AssetCasting(PropertyGroup):
|
||||
id : StringProperty(default='')
|
||||
instance : IntProperty(default=1)
|
||||
|
||||
@property
|
||||
def asset(self):
|
||||
settings = get_scene_settings()
|
||||
project = settings.active_project
|
||||
return project.assets.get(self.id)
|
||||
|
||||
def to_dict(self):
|
||||
return {'id': self.id,
|
||||
'instance': self.instance,
|
||||
'name': self.asset.name if self.asset else None,
|
||||
'_name': self.get('_name')
|
||||
}
|
||||
|
||||
|
||||
class AssetType(PropertyGroup):
|
||||
__annotations__ = {}
|
||||
|
||||
|
||||
class MetadataType(PropertyGroup):
|
||||
#choices = []
|
||||
choices : CollectionProperty(type=PropertyGroup)#EnumProperty(items=lambda s, c: [(c, c.replace(' ', '_').upper(), '') for c in s['choices']])
|
||||
field_name : StringProperty()
|
||||
entity_type : StringProperty()
|
||||
|
||||
|
||||
class TaskType(PropertyGroup):
|
||||
__annotations__ = {}
|
||||
|
||||
|
||||
class TaskStatus(PropertyGroup):
|
||||
__annotations__ = {}
|
||||
|
||||
|
||||
class Metadata(CollectionPropertyGroup):
|
||||
__annotations__ = {}
|
||||
|
||||
|
||||
class Episode(PropertyGroup):
|
||||
id : StringProperty(default='')
|
||||
|
||||
@property
|
||||
def active(self):
|
||||
settings = get_scene_settings()
|
||||
return self.get(settings.project_name)
|
||||
|
||||
|
||||
class SpreadsheetCell(PropertyGroup):
|
||||
export_name : StringProperty()
|
||||
enabled : BoolProperty(default=True)
|
||||
field_name : StringProperty()
|
||||
type : EnumProperty(items=[(t, t, "") for t in ('METADATA', 'SHOT', 'ASSET_TYPE')])
|
||||
#sort : BoolProperty(default=True)
|
||||
|
||||
|
||||
def get_custom_name_items(self, context):
|
||||
settings = get_scene_settings()
|
||||
project = settings.active_project
|
||||
return [(m.field_name, m.name, '') for m in project.metadata_types if m.entity_type=='ASSET']
|
||||
|
||||
class SpreadsheetImport(PropertyGroup):
|
||||
format : EnumProperty(items=[(i, i, '') for i in ('CSV', 'XLSX')])
|
||||
separator : StringProperty(default='\\n')
|
||||
delimiter : StringProperty(default=';')
|
||||
export_path : StringProperty(default='//export')
|
||||
use_custom_name : BoolProperty(default=False)
|
||||
custom_name : EnumProperty(items=get_custom_name_items,
|
||||
description='Use a custom name for asset using a metadata value')
|
||||
|
||||
open_folder : BoolProperty(default=False)
|
||||
show_settings : BoolProperty(default=False)
|
||||
cells: CollectionProperty(type=SpreadsheetCell)
|
||||
cell_index : IntProperty(name='Spreadsheet Index', default=0)
|
||||
|
||||
|
||||
class Project(PropertyGroup):
|
||||
id : StringProperty(default='')
|
||||
|
||||
shot_start_number : IntProperty(name="Shot Start Number", default=10, min=0)
|
||||
sequence_start_number : IntProperty(name="Sequence Start Number", default=10, min=0)
|
||||
|
||||
reset_by_sequence : BoolProperty(
|
||||
name="Reset By Sequence",
|
||||
description="Reset Start Number for each sequence",
|
||||
default=False
|
||||
)
|
||||
|
||||
sequence_increment : IntProperty(
|
||||
name="Sequence Increment", default=10, min=0, step=10)
|
||||
|
||||
shot_increment : IntProperty(
|
||||
name="Shot Increment", default=10, min=0, step=10)
|
||||
|
||||
sequence_template : StringProperty(
|
||||
name="Sequence Name", default="sq{index:03d}")
|
||||
|
||||
episode_template : StringProperty(
|
||||
name="Episode Name", default="ep{index:03d}")
|
||||
|
||||
shot_template : StringProperty(
|
||||
name="Shot Name", default="{sequence}_sh{index:04d}")
|
||||
|
||||
render_template : StringProperty(
|
||||
name="Render Name", default="//render/{strip_name}.{ext}")
|
||||
|
||||
episode_name : EnumProperty(items=get_episodes_items, update=on_episode_updated)
|
||||
episodes : CollectionProperty(type=Episode)
|
||||
assets : CollectionProperty(type=Asset)
|
||||
asset_types : CollectionProperty(type=AssetType)
|
||||
metadata_types : CollectionProperty(type=MetadataType)
|
||||
task_types : CollectionProperty(type=TaskType)
|
||||
task_statuses : CollectionProperty(type=TaskStatus)
|
||||
|
||||
spreadsheet_import: PointerProperty(type=Spreadsheet)
|
||||
spreadsheet_export: PointerProperty(type=Spreadsheet)
|
||||
|
||||
type : StringProperty()
|
||||
|
||||
def set_spreadsheet(self):
|
||||
cell_names = ['Sequence', 'Shot', 'Frames', 'Description']
|
||||
if self.type == 'TVSHOW':
|
||||
cell_names.insert(0, 'Episode')
|
||||
|
||||
for cell_name in cell_names:
|
||||
cell = self.spreadsheet.add()
|
||||
cell.name = cell_name
|
||||
cell.export_name = 'Name' if cell_name == 'Shot' else cell_name
|
||||
cell.field_name = cell_name.upper()
|
||||
cell.type = "SHOT"
|
||||
|
||||
for metadata_type in self.metadata_types:
|
||||
if not metadata_type['entity_type'] == "SHOT":
|
||||
continue
|
||||
cell = self.spreadsheet.add()
|
||||
cell.name = metadata_type.name
|
||||
cell.export_name = metadata_type.name
|
||||
cell.field_name = metadata_type.field_name
|
||||
cell.type = "METADATA"
|
||||
|
||||
for asset_type in self.asset_types:
|
||||
cell = self.spreadsheet.add()
|
||||
cell.name = asset_type.name
|
||||
cell.export_name = asset_type.name
|
||||
cell.field_name = asset_type.name.upper()
|
||||
cell.type = "ASSET_TYPE"
|
||||
|
||||
|
||||
def set_strip_metadata(self):
|
||||
|
||||
# Clear Metadatas
|
||||
for attr in list(Metadata.__annotations__.keys()):
|
||||
if hasattr(Metadata, attr):
|
||||
delattr(Metadata, attr)
|
||||
del Metadata.__annotations__[attr]
|
||||
|
||||
for metadata_type in self.metadata_types:
|
||||
if not metadata_type.entity_type == "SHOT":
|
||||
continue
|
||||
|
||||
field_name = metadata_type.field_name
|
||||
name = metadata_type.name
|
||||
|
||||
#if metadata_type.get('choices'):
|
||||
# prop = #bpy.props.EnumProperty(items=[(c, c, '') for c in ['/'] + metadata_type['choices']], name=name)
|
||||
#else:
|
||||
# prop = #bpy.props.StringProperty(name=name)
|
||||
prop = bpy.props.StringProperty(name=name)
|
||||
|
||||
Metadata.__annotations__[field_name] = prop
|
||||
setattr(Metadata, field_name, prop)
|
||||
|
||||
|
||||
class VSETB_UL_casting(UIList):
|
||||
|
||||
order_by_type : BoolProperty(default=False)
|
||||
|
||||
def draw_item(self, context, layout, data, item, icon, active_data,
|
||||
active_propname, index):
|
||||
|
||||
settings = get_scene_settings()
|
||||
project = settings.active_project
|
||||
|
||||
asset = item.asset
|
||||
if asset is None:
|
||||
layout.label(text=f'Asset not Found ({item.get("_name", "...")})')
|
||||
return
|
||||
|
||||
icon_id = asset.icon_id
|
||||
params = {'icon_value': icon_id} if icon_id else {'icon': 'BLANK1'}
|
||||
|
||||
# Make sure your code supports all 3 layout types
|
||||
if self.layout_type in {'DEFAULT', 'COMPACT'}:
|
||||
layout.label(**params)
|
||||
split = layout.split(factor=0.6)
|
||||
split.label(text=f"{asset.norm_name.title()}")
|
||||
split.label(text=f"{asset.asset_type.title()}")
|
||||
sub = layout.row(align=True)
|
||||
sub.alignment = 'RIGHT'
|
||||
sub.prop(item, 'instance', text='')
|
||||
|
||||
elif self.layout_type in {'GRID'}:
|
||||
layout.alignment = 'CENTER'
|
||||
layout.label(text="")
|
||||
|
||||
def draw_filter(self, context, layout):
|
||||
row = layout.row()
|
||||
|
||||
subrow = row.row(align=True)
|
||||
subrow.prop(self, "filter_name", text="")
|
||||
subrow.prop(self, "use_filter_invert", text="", icon='ARROW_LEFTRIGHT')
|
||||
|
||||
subrow.separator()
|
||||
subrow.prop(self, "order_by_type", text="Order by Type", icon='MESH_DATA')
|
||||
|
||||
def filter_items(self, context, data, propname):
|
||||
"""Filter and order items in the list."""
|
||||
|
||||
helper_funcs = bpy.types.UI_UL_list
|
||||
|
||||
filtered = []
|
||||
ordered = []
|
||||
items = getattr(data, propname)
|
||||
|
||||
# Filtering by name
|
||||
if self.filter_name:
|
||||
filtered = helper_funcs.filter_items_by_name(self.filter_name, self.bitflag_filter_item, items, "name",
|
||||
reverse=self.use_filter_sort_alpha)
|
||||
# Order by types
|
||||
if self.order_by_type:
|
||||
_sort = [(idx, casting_item) for idx, casting_item in enumerate(items)]
|
||||
sort_items = helper_funcs.sort_items_helper
|
||||
ordered = sort_items(_sort, lambda x: x[1].asset.label)
|
||||
|
||||
return filtered, ordered
|
||||
|
||||
|
||||
class VSETB_UL_spreadsheet(UIList):
|
||||
def draw_item(self, context, layout, data, item, icon, active_data,
|
||||
active_propname, index):
|
||||
|
||||
settings = get_scene_settings()
|
||||
project = settings.active_project
|
||||
|
||||
layout.use_property_split = True
|
||||
layout.use_property_decorate = False
|
||||
|
||||
row = layout.row(align=True)
|
||||
row.alignment = 'LEFT'
|
||||
|
||||
row.prop(item, 'enabled', text='')
|
||||
layout.label(text=item.name)
|
||||
layout.prop(item, 'export_name', text='')
|
||||
|
||||
def draw_filter(self, context, layout):
|
||||
row = layout.row()
|
||||
|
||||
subrow = row.row(align=True)
|
||||
subrow.prop(self, "filter_name", text="")
|
||||
subrow.prop(self, "use_filter_invert", text="", icon='ARROW_LEFTRIGHT')
|
||||
|
||||
subrow.separator()
|
||||
subrow.prop(self, "order_by_type", text="Order by Type", icon='MESH_DATA')
|
||||
|
||||
|
||||
class VSETB_PGT_scene_settings(PropertyGroup):
|
||||
|
||||
projects : CollectionProperty(type=Project)
|
||||
project_name : EnumProperty(items=get_project_items, update=on_project_updated)
|
||||
tracker_name : EnumProperty(items=get_tracker_items)
|
||||
|
||||
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),
|
||||
('MOVIE', 'Movie', '', 1),
|
||||
('SHOTS', 'Shots', '', 2),
|
||||
('SEQUENCES', 'Sequences', '', 3),
|
||||
('STAMPS', 'Sequences', '', 4),
|
||||
]
|
||||
)
|
||||
|
||||
sequence_channel_name : StringProperty(
|
||||
name="Sequences Channel Name", default="Sequences")
|
||||
|
||||
shot_channel_name : StringProperty(
|
||||
name="Shot Channel Name", default="Shots")
|
||||
|
||||
@property
|
||||
def active_project(self):
|
||||
settings = get_scene_settings()
|
||||
return settings.projects.get(settings.project_name)
|
||||
|
||||
@property
|
||||
def active_episode(self):
|
||||
project = self.active_project
|
||||
if project:
|
||||
return project.episodes.get(project.episode_name)
|
||||
|
||||
|
||||
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)
|
||||
description : StringProperty()
|
||||
|
||||
|
||||
classes = (
|
||||
Asset,
|
||||
AssetCasting,
|
||||
SpreadsheetCell,
|
||||
AssetType,
|
||||
TaskStatus,
|
||||
Episode,
|
||||
Metadata,
|
||||
MetadataType,
|
||||
TaskType,
|
||||
Spreadsheet,
|
||||
Project,
|
||||
VSETB_UL_spreadsheet,
|
||||
VSETB_UL_casting,
|
||||
VSETB_PGT_scene_settings,
|
||||
VSETB_PGT_strip_settings,
|
||||
)
|
||||
|
||||
|
||||
|
||||
from bpy.app.handlers import persistent
|
||||
|
||||
|
||||
|
||||
|
||||
@persistent
|
||||
def load_handler(dummy):
|
||||
settings = get_scene_settings()
|
||||
project = settings.active_project
|
||||
|
||||
if project:
|
||||
project.set_strip_metadata()
|
||||
#settings.active_project.set_spreadsheet()
|
||||
os.environ['TRACKER_PROJECT_ID'] = settings.active_project.id
|
||||
|
||||
for asset in project.assets:
|
||||
preview_id = asset.preview
|
||||
preview_path = Path(PREVIEWS_DIR / project.id / preview_id).with_suffix('.png')
|
||||
|
||||
if preview_path.exists() and preview_id not in ASSET_PREVIEWS:
|
||||
ASSET_PREVIEWS.load(preview_id, preview_path.as_posix(), 'IMAGE', True)
|
||||
|
||||
|
||||
def register():
|
||||
for cls in classes:
|
||||
bpy.utils.register_class(cls)
|
||||
|
||||
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()
|
||||
bpy.app.handlers.load_post.append(load_handler)
|
||||
|
||||
|
||||
def unregister():
|
||||
for cls in reversed(classes):
|
||||
bpy.utils.unregister_class(cls)
|
||||
|
||||
del bpy.types.Sequence.vsetb_strip_settings
|
||||
del bpy.types.Scene.vsetb_settings
|
||||
|
||||
bpy.app.handlers.load_post.remove(load_handler)
|
||||
Reference in New Issue
Block a user