Refactor and Copy Paste Casting

pull/5/head
Clément Ducarteron 2023-03-21 18:33:29 +01:00
parent 3cc254bdc9
commit e14dc2136d
9 changed files with 297 additions and 161 deletions

View File

@ -26,10 +26,10 @@ from vse_toolbox.sequencer_utils import get_active_strip
mods = ( mods = (
panels,
properties, properties,
preferences, preferences,
operators, operators,
panels,
) )
if 'bpy' in locals(): if 'bpy' in locals():

View File

@ -5,9 +5,13 @@ Generic Blender functions
import bpy import bpy
def get_settings(): def get_scene_settings():
return bpy.context.window_manager.vsetb_settings return bpy.context.scene.vsetb_settings
def get_strip_settings():
scn = bpy.context.scene
return scn.sequence_editor.active_strip.vsetb_strip_settings
def get_bl_cmd(blender=None, background=False, focus=True, blendfile=None, script=None, **kargs): def get_bl_cmd(blender=None, background=False, focus=True, blendfile=None, script=None, **kargs):
cmd = [str(blender)] if blender else [bpy.app.binary_path] cmd = [str(blender)] if blender else [bpy.app.binary_path]

View File

@ -2,6 +2,8 @@ import appdirs
import bpy import bpy
import os import os
from pathlib import Path from pathlib import Path
from tempfile import gettempdir
MODULE_DIR = Path(__file__).parent MODULE_DIR = Path(__file__).parent
TRACKERS_DIR = MODULE_DIR / 'resources' / 'trackers' TRACKERS_DIR = MODULE_DIR / 'resources' / 'trackers'
@ -11,7 +13,7 @@ PROJECTS = []
EDITS = [('NONE', 'None', '', 0)] EDITS = [('NONE', 'None', '', 0)]
MOVIES = [('NONE', 'None', '', 0)] MOVIES = [('NONE', 'None', '', 0)]
SOUNDS = [('NONE', 'None', '', 0)] SOUNDS = [('NONE', 'None', '', 0)]
ASSETS = [('NONE', 'None', '', 0)] # ASSETS = [('NONE', 'None', '', 0)]
EDIT_SUFFIXES = ['.xml', '.edl'] EDIT_SUFFIXES = ['.xml', '.edl']
MOVIE_SUFFIXES = ['.mov', '.mp4'] MOVIE_SUFFIXES = ['.mov', '.mp4']
@ -20,4 +22,6 @@ SOUND_SUFFIXES = ['.mp3', '.aaf', '.flac']
CONFIG_DIR = Path(appdirs.user_config_dir(__package__.split('.')[0])) CONFIG_DIR = Path(appdirs.user_config_dir(__package__.split('.')[0]))
PREVIEWS_DIR = CONFIG_DIR / 'thumbnails' PREVIEWS_DIR = CONFIG_DIR / 'thumbnails'
ASSET_PREVIEWS = bpy.utils.previews.new() ASSET_PREVIEWS = bpy.utils.previews.new()
CASTING_BUFFER = CONFIG_DIR / 'casting.json'

View File

@ -2,6 +2,7 @@
import bpy import bpy
import importlib import importlib
import json
import re import re
import vse_toolbox import vse_toolbox
@ -18,8 +19,8 @@ from bpy.types import (
) )
from pathlib import Path from pathlib import Path
from vse_toolbox.constants import ( from vse_toolbox.constants import (
ASSETS,
ASSET_PREVIEWS, ASSET_PREVIEWS,
CASTING_BUFFER,
CONFIG_DIR, CONFIG_DIR,
EDITS, EDITS,
EDIT_SUFFIXES, EDIT_SUFFIXES,
@ -41,7 +42,7 @@ from vse_toolbox.sequencer_utils import (
render_strips, render_strips,
set_channels, set_channels,
) )
from vse_toolbox.bl_utils import get_addon_prefs, get_settings from vse_toolbox.bl_utils import get_addon_prefs, get_scene_settings, get_strip_settings
from vse_toolbox.file_utils import install_module, norm_name, norm_str from vse_toolbox.file_utils import install_module, norm_name, norm_str
class VSETB_OT_export_csv(Operator): class VSETB_OT_export_csv(Operator):
@ -166,7 +167,7 @@ class VSETB_OT_import_files(Operator):
def draw(self, context): def draw(self, context):
scn = context.scene scn = context.scene
settings = get_settings() settings = get_scene_settings()
layout = self.layout layout = self.layout
layout.use_property_split = True layout.use_property_split = True
@ -257,57 +258,45 @@ class VSETB_OT_load_assets(Operator):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
settings = get_settings() settings = get_scene_settings()
if settings.active_project: if settings.active_project:
return True return True
def get_items(self, items=[]):
if not items:
return [('NONE', 'None', '', 0)]
icons = {
'camera':'CAMERA_DATA',
'chars':'COMMUNITY',
'props':'OBJECT_DATAMODE',
'sets':'SMOOTHCURVE',
}
#TODO Mettre la preview dans le popup search
return [(e.norm_name, e.norm_name.title(), '', icons[e.asset_type], i) for i, e in enumerate(items)]
# return [(e.norm_name, e.norm_name.title(), '', ASSET_PREVIEWS[e.preview].icon_id, i) for i, e in enumerate(items)]
def execute(self, context): def execute(self, context):
settings = get_settings() settings = get_scene_settings()
prefs = get_addon_prefs() prefs = get_addon_prefs()
tracker = prefs.tracker tracker = prefs.tracker
ASSETS.clear() tracker.connect()
settings.active_project.assets.clear()
project = settings.active_project project = settings.active_project
project.assets.clear()
assets = tracker.get_assets(project['id']) assets = tracker.get_assets(project['id'])
if not assets: if not assets:
self.report({'ERROR'}, f'No Assets found for {project.name}.') self.report({'ERROR'}, f'No Assets found for {project.name}.')
for asset_data in assets: for asset_data in assets:
asset = project.assets.add() asset = project.assets.add()
asset.name = asset_data['id']
asset.norm_name = norm_name(asset_data['name'], separator=' ', format=str.lower) asset.norm_name = norm_name(asset_data['name'], separator=' ', format=str.lower)
asset.name = asset.norm_name
asset.tracker_name = asset_data['name'] asset.tracker_name = asset_data['name']
asset.id = asset_data['id'] asset.id = asset_data['id']
asset.asset_type = asset_data['asset_type'] asset.asset_type = asset_data['asset_type']
asset.nombss = asset_data['data'].get('nombss', '') datas = asset_data.get('data', {})
for key, values in datas.items():
asset[key] = values
preview_id = asset_data.get('preview_file_id') preview_id = asset_data.get('preview_file_id')
if preview_id: if preview_id:
asset.preview = preview_id asset.preview = preview_id
preview_path = Path(PREVIEWS_DIR / project.name.lower() / preview_id).with_suffix('.png') preview_path = Path(PREVIEWS_DIR / project.id / preview_id).with_suffix('.png')
tracker.download_preview(preview_id, preview_path) tracker.download_preview(preview_id, preview_path)
ASSET_PREVIEWS.load(preview_id, preview_path.as_posix(), 'IMAGE') ASSET_PREVIEWS.load(preview_id, preview_path.as_posix(), 'IMAGE')
ASSETS.extend(self.get_items(items=project.assets))
self.report({'INFO'}, f'Assets for {project.name} successfully loaded') self.report({'INFO'}, f'Assets for {project.name} successfully loaded')
return {"FINISHED"} return {"FINISHED"}
@ -324,7 +313,7 @@ class VSETB_OT_load_projects(Operator):
return True return True
def execute(self, context): def execute(self, context):
settings = get_settings() settings = get_scene_settings()
prefs = get_addon_prefs() prefs = get_addon_prefs()
tracker = prefs.tracker tracker = prefs.tracker
@ -340,12 +329,6 @@ class VSETB_OT_load_projects(Operator):
episode = project.episodes.add() episode = project.episodes.add()
episode.name = episode_data['name'] episode.name = episode_data['name']
episode.id = episode_data['id'] episode.id = episode_data['id']
# for asset_data in tracker.get_assets(project_data):
# asset = project.assets.add()
# asset.name = asset_data['name']
# asset.id = asset_data['id']
# asset.asset_type = asset_data['asset_type']
return {'FINISHED'} return {'FINISHED'}
@ -364,12 +347,12 @@ class VSETB_OT_new_episode(Operator):
def invoke(self, context, event): def invoke(self, context, event):
scn = context.scene scn = context.scene
settings = get_settings() settings = get_scene_settings()
return context.window_manager.invoke_props_dialog(self) return context.window_manager.invoke_props_dialog(self)
def execute(self, context): def execute(self, context):
settings = get_settings() settings = get_scene_settings()
prefs = get_addon_prefs() prefs = get_addon_prefs()
tracker = prefs.tracker tracker = prefs.tracker
@ -430,13 +413,13 @@ class VSETB_OT_rename(Operator):
def invoke(self, context, event): def invoke(self, context, event):
scn = context.scene scn = context.scene
settings = get_settings() settings = get_scene_settings()
return context.window_manager.invoke_props_dialog(self) return context.window_manager.invoke_props_dialog(self)
def draw(self, context): def draw(self, context):
scn = context.scene scn = context.scene
settings = get_settings() settings = get_scene_settings()
layout = self.layout layout = self.layout
col = layout.column() col = layout.column()
@ -474,13 +457,13 @@ class VSETB_OT_render(Operator):
def invoke(self, context, event): def invoke(self, context, event):
scn = context.scene scn = context.scene
settings = get_settings() settings = get_scene_settings()
return context.window_manager.invoke_props_dialog(self) return context.window_manager.invoke_props_dialog(self)
def draw(self, context): def draw(self, context):
scn = context.scene scn = context.scene
settings = get_settings() settings = get_scene_settings()
layout = self.layout layout = self.layout
col = layout.column() col = layout.column()
@ -491,7 +474,7 @@ class VSETB_OT_render(Operator):
def execute(self, context): def execute(self, context):
scn = context.scene scn = context.scene
settings = get_settings() settings = get_scene_settings()
strips = get_strips(channel=settings.channel, selected_only=self.selected_only) strips = get_strips(channel=settings.channel, selected_only=self.selected_only)
render_strips(strips) render_strips(strips)
@ -526,6 +509,12 @@ class VSETB_OT_set_scene(Operator):
return {"FINISHED"} return {"FINISHED"}
def get_asset_items(self, context):
settings = get_scene_settings()
project = settings.active_project
return [(a.id, a.label, '', i) for i, a in enumerate(project.assets)]
class VSETB_OT_casting_add(Operator): class VSETB_OT_casting_add(Operator):
bl_idname = "vse_toolbox.casting_add" bl_idname = "vse_toolbox.casting_add"
bl_label = "Casting Add" bl_label = "Casting Add"
@ -533,40 +522,81 @@ class VSETB_OT_casting_add(Operator):
bl_options = {"REGISTER", "UNDO"} bl_options = {"REGISTER", "UNDO"}
bl_property = "asset_name" bl_property = "asset_name"
asset_name : EnumProperty(name='', items=lambda s, c: ASSETS) asset_name : EnumProperty(name='', items=get_asset_items)
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
active_strip = context.scene.sequence_editor.active_strip active_strip = context.scene.sequence_editor.active_strip
if active_strip: if active_strip:
return True return True
def invoke(self, context, event): def invoke(self, context, event):
context.window_manager.invoke_search_popup(self) context.window_manager.invoke_search_popup(self)
return {"FINISHED"} return {'FINISHED'}
def execute(self, context): def execute(self, context):
scn = context.scene scn = context.scene
settings = get_settings()
active_strip = scn.sequence_editor.active_strip active_strip = scn.sequence_editor.active_strip
settings = get_scene_settings()
strip_settings = get_strip_settings()
project = settings.active_project project = settings.active_project
if active_strip.casting.get(self.asset_name): if strip_settings.casting.get(self.asset_name):
self.report({'WARNING'}, f"Asset {self.asset_name} already casted.") asset = project.assets[self.asset_name]
self.report({'WARNING'}, f"Asset {asset.label} already casted.")
return {"CANCELLED"} return {"CANCELLED"}
item = active_strip.casting.add() item = strip_settings.casting.add()
item.name = self.asset_name asset = project.assets[self.asset_name]
for k, v in project.assets[self.asset_name].items():
setattr(item, k, v)
active_strip.casting.update() item.name = asset.name
item.id = project.assets[self.asset_name].id
strip_settings.casting.update()
return {"FINISHED"} return {"FINISHED"}
class VSETB_OT_casting_actions(Operator): class VSETB_OT_casting_remove(Operator):
bl_idname = "vse_toolbox.casting_actions" bl_idname = "vse_toolbox.casting_remove"
bl_label = "Remove Item from Casting"
bl_description = "Remove Item from Casting"
bl_options = {"REGISTER", "UNDO"}
@classmethod
def poll(cls, context):
active_strip = context.scene.sequence_editor.active_strip
if active_strip:
return True
def invoke(self, context, event):
scn = context.scene
strip_settings = get_strip_settings()
idx = strip_settings.casting_index
try:
item = strip_settings.casting[idx]
except IndexError:
pass
else:
item = strip_settings.casting[strip_settings.casting_index]
info = f"Item {item.asset.label} removed from casting"
strip_settings.casting.remove(idx)
if strip_settings.casting_index == 0:
strip_settings.casting_index = 0
else:
strip_settings.casting_index -= 1
self.report({'INFO'}, info)
return {"FINISHED"}
class VSETB_OT_casting_move(Operator):
bl_idname = "vse_toolbox.casting_move"
bl_label = "Casting Actions" bl_label = "Casting Actions"
bl_description = "Actions to Add, Remove, Move casting items" bl_description = "Actions to Add, Remove, Move casting items"
bl_options = {"REGISTER", "UNDO"} bl_options = {"REGISTER", "UNDO"}
@ -575,7 +605,6 @@ class VSETB_OT_casting_actions(Operator):
items=( items=(
('UP', "Up", ""), ('UP', "Up", ""),
('DOWN', "Down", ""), ('DOWN', "Down", ""),
('REMOVE', "Remove", ""),
) )
) )
@ -589,50 +618,100 @@ class VSETB_OT_casting_actions(Operator):
def invoke(self, context, event): def invoke(self, context, event):
scn = context.scene scn = context.scene
active_strip = scn.sequence_editor.active_strip strip_settings = get_strip_settings()
idx = active_strip.casting_index idx = strip_settings.casting_index
try: try:
item = active_strip.casting[idx] item = strip_settings.casting[idx]
except IndexError: except IndexError:
pass pass
else: else:
if self.action == 'DOWN' and idx < len(active_strip.casting) - 1: if self.action == 'DOWN' and idx < len(strip_settings.casting) - 1:
item_next = active_strip.casting[idx+1].name item_next = strip_settings.casting[idx+1].name
active_strip.casting.move(idx, idx+1) strip_settings.casting.move(idx, idx+1)
active_strip.casting_index += 1 strip_settings.casting_index += 1
info = f"Item {item.name} moved to position {(item.name, active_strip.casting_index + 1)}"
self.report({'INFO'}, info)
elif self.action == 'UP' and idx >= 1: elif self.action == 'UP' and idx >= 1:
item_prev = active_strip.casting[idx-1].name item_prev = strip_settings.casting[idx-1].name
active_strip.casting.move(idx, idx-1) strip_settings.casting.move(idx, idx-1)
active_strip.casting_index -= 1 strip_settings.casting_index -= 1
info = f"Item {item.name} moved to position {(item.name, active_strip.casting_index + 1)}" info = f"Item {item.asset.label} moved to position {(item.asset.label, strip_settings.casting_index + 1)}"
self.report({'INFO'}, info) self.report({'INFO'}, info)
elif self.action == 'REMOVE':
item = active_strip.casting[active_strip.casting_index]
active_strip.casting.remove(idx)
if active_strip.casting_index == 0:
active_strip.casting_index = 0
else:
active_strip.casting_index -= 1
info = f"Item {item.name} removed from casting"
self.report({'INFO'}, info)
return {"FINISHED"} return {"FINISHED"}
class VSETB_OT_copy_casting(Operator):
bl_idname = "sequencer.copy_casting"
bl_label = "Casting Actions"
bl_description = "Copy Casting from active strip"
bl_options = {"REGISTER", "UNDO"}
@classmethod
def poll(cls, context):
active_strip = context.scene.sequence_editor.active_strip
strip_settings = get_strip_settings()
if active_strip and strip_settings.casting:
return True
def execute(self, context):
scn = context.scene
active_strip = scn.sequence_editor.active_strip
strip_settings = get_strip_settings()
datas = [c.to_dict() for c in strip_settings.casting]
CASTING_BUFFER.write_text(json.dumps(datas), encoding='utf-8')
return {"FINISHED"}
class VSETB_OT_paste_casting(Operator):
bl_idname = "sequencer.paste_casting"
bl_label = "Casting Actions"
bl_description = "Copy Casting from active strip"
bl_options = {"REGISTER", "UNDO"}
@classmethod
def poll(cls, context):
active_strip = context.scene.sequence_editor.active_strip
if active_strip:
return True
def execute(self, context):
scn = context.scene
strip_settings = get_strip_settings()
if not CASTING_BUFFER.exists():
self.report({'ERROR'}, f'No Casting to copy.')
return {"CANCELLED"}
casting_datas = json.loads(CASTING_BUFFER.read_text())
for casting_item in casting_datas:
for strip in context.selected_sequences:
strip_settings = strip.vsetb_strip_settings
if strip_settings.casting.get(casting_item['name']):
continue
item = strip.vsetb_strip_settings.casting.add()
for k, v in casting_item.items():
setattr(item, k, v)
strip_settings.casting.update()
return {"FINISHED"}
classes=( classes=(
VSETB_OT_auto_select_files, VSETB_OT_auto_select_files,
VSETB_OT_casting_add, VSETB_OT_casting_add,
VSETB_OT_casting_actions, VSETB_OT_casting_remove,
VSETB_OT_casting_move,
VSETB_OT_copy_casting,
VSETB_OT_paste_casting,
VSETB_OT_export_csv, VSETB_OT_export_csv,
VSETB_OT_import_files, VSETB_OT_import_files,
VSETB_OT_load_assets, VSETB_OT_load_assets,

View File

@ -3,7 +3,7 @@
import bpy import bpy
from bpy.types import Panel from bpy.types import Panel
from pathlib import Path from pathlib import Path
from vse_toolbox.bl_utils import get_addon_prefs, get_settings 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.constants import ASSET_PREVIEWS
from vse_toolbox.sequencer_utils import get_active_strip from vse_toolbox.sequencer_utils import get_active_strip
@ -25,7 +25,7 @@ class VSETB_PT_main(VSETB_main, Panel):
wm = context.window_manager wm = context.window_manager
scn = context.scene scn = context.scene
settings = get_settings() settings = get_scene_settings()
prefs = get_addon_prefs() prefs = get_addon_prefs()
project = settings.active_project project = settings.active_project
@ -67,7 +67,7 @@ class VSETB_PT_rename(VSETB_main, Panel):
def draw(self, context): def draw(self, context):
prefs = get_addon_prefs() prefs = get_addon_prefs()
settings = get_settings() settings = get_scene_settings()
project = settings.active_project project = settings.active_project
if not project: if not project:
@ -103,10 +103,13 @@ class VSETB_PT_casting(VSETB_main, Panel):
layout = self.layout layout = self.layout
scn = context.scene scn = context.scene
active_strip = scn.sequence_editor.active_strip active_strip = scn.sequence_editor.active_strip
if not active_strip: if not active_strip:
return return
settings = get_settings() settings = get_scene_settings()
strip_settings = get_strip_settings()
project = settings.active_project project = settings.active_project
if not project: if not project:
@ -115,11 +118,12 @@ class VSETB_PT_casting(VSETB_main, Panel):
if not project.assets: if not project.assets:
row = layout.row(align=True) row = layout.row(align=True)
row.label(text='No Assets found. Load Assets first.') row.label(text='No Assets found. Load Assets first.')
row.operator('vse_toolbox.load_assets', icon='FILE_REFRESH', text='')
else: else:
row = layout.row(align=True) row = layout.row(align=True)
row.label(text=f'Assets for {project.name} successfully loaded.') row.label(text=f'Assets for {project.name} successfully loaded.')
row.operator('vse_toolbox.load_assets', icon='FILE_REFRESH', text='')
row = layout.row() row = layout.row()
ico = ("RESTRICT_SELECT_OFF" if settings.auto_select_strip else "RESTRICT_SELECT_ON") ico = ("RESTRICT_SELECT_OFF" if settings.auto_select_strip else "RESTRICT_SELECT_ON")
row.prop(settings, "auto_select_strip", icon=ico) row.prop(settings, "auto_select_strip", icon=ico)
@ -128,22 +132,26 @@ class VSETB_PT_casting(VSETB_main, Panel):
row.label(text=f"Current Shot: {Path(active_strip.name).stem}") row.label(text=f"Current Shot: {Path(active_strip.name).stem}")
row = layout.row() row = layout.row()
col = row.column() col = row.column()
col.template_list("VSETB_UL_casting", "shot_casting", active_strip, "casting", active_strip, "casting_index") col.template_list("VSETB_UL_casting", "shot_casting", strip_settings, "casting", strip_settings, "casting_index", rows=6)
if active_strip.casting: if strip_settings.casting:
active_asset = active_strip.casting[active_strip.casting_index] casting_item = strip_settings.casting[strip_settings.casting_index]
ico = ASSET_PREVIEWS.get(active_asset.preview) asset = casting_item.asset
if ico: if asset:
box = col.box() ico = ASSET_PREVIEWS.get(asset.preview)
box.template_icon(icon_value=ico.icon_id, scale=7.5) if ico:
box = col.box()
box.template_icon(icon_value=ico.icon_id, scale=7.5)
col_tool = row.column(align=True) col_tool = row.column(align=True)
col_tool.operator('vse_toolbox.casting_add', icon='ADD', text="") col_tool.operator('vse_toolbox.casting_add', icon='ADD', text="")
col_tool.operator('vse_toolbox.casting_actions', icon='REMOVE', text="").action = 'REMOVE' col_tool.operator('vse_toolbox.casting_remove', icon='REMOVE', text="")
col_tool.separator() col_tool.separator()
col_tool.operator('vse_toolbox.casting_actions', icon='TRIA_UP', text="").action = 'UP' col_tool.operator('vse_toolbox.casting_move', icon='TRIA_UP', text="").action = 'UP'
col_tool.operator('vse_toolbox.casting_actions', icon='TRIA_DOWN', text="").action = 'DOWN' col_tool.operator('vse_toolbox.casting_move', icon='TRIA_DOWN', text="").action = 'DOWN'
#TODO Add Nombre instance (IntProperty) col_tool.separator()
col_tool.operator('sequencer.copy_casting', icon='COPYDOWN', text="")
col_tool.operator('sequencer.paste_casting', icon='PASTEDOWN', text="")
classes=( classes=(

View File

@ -17,7 +17,7 @@ from bpy.types import (
AddonPreferences, AddonPreferences,
PropertyGroup, PropertyGroup,
) )
from vse_toolbox.bl_utils import get_addon_prefs, get_settings from vse_toolbox.bl_utils import get_addon_prefs, get_scene_settings
from vse_toolbox.constants import ( from vse_toolbox.constants import (
TRACKERS, TRACKERS,
TRACKERS_DIR, TRACKERS_DIR,
@ -29,9 +29,6 @@ from vse_toolbox.file_utils import (
) )
from vse_toolbox.resources.trackers.kitsu import Kitsu from vse_toolbox.resources.trackers.kitsu import Kitsu
def get_tracker_items(self, context):
return [(norm_str(a.name, format=str.upper), a.name, "", i) for i, a in enumerate(TRACKERS)]
def load_trackers(): def load_trackers():
from vse_toolbox.resources.trackers.tracker import Tracker from vse_toolbox.resources.trackers.tracker import Tracker
@ -63,6 +60,30 @@ def load_trackers():
print(f'Could not register library_type {name}') print(f'Could not register library_type {name}')
print(e) print(e)
def load_tracker_prefs():
prefs = get_addon_prefs()
tracker_prefs_file = os.getenv('TRACKER_PREFS')
if not tracker_prefs_file:
return
tracker_datas = read_file(os.path.expandvars(tracker_prefs_file))
for tracker_data in tracker_datas:
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))
class Trackers(PropertyGroup): class Trackers(PropertyGroup):
def __iter__(self): def __iter__(self):
@ -77,11 +98,11 @@ class VSETB_Prefs(AddonPreferences):
@property @property
def tracker(self): def tracker(self):
return getattr(self.trackers, norm_str(get_settings().tracker_name)) return getattr(self.trackers, norm_str(get_scene_settings().tracker_name))
def draw(self, context): def draw(self, context):
prefs = get_addon_prefs() prefs = get_addon_prefs()
settings = get_settings() settings = get_scene_settings()
layout = self.layout layout = self.layout
@ -113,20 +134,12 @@ def register():
load_trackers() load_trackers()
prefs = get_addon_prefs() prefs = get_addon_prefs()
settings = get_settings()
tracker_name = os.getenv('TRACKER_NAME') tracker_name = os.getenv('TRACKER_NAME')
if tracker_name is not None:
if tracker_name:
prefs['tracker_name'] = os.path.expandvars(norm_str(tracker_name, format=str.upper)) prefs['tracker_name'] = os.path.expandvars(norm_str(tracker_name, format=str.upper))
tracker_prefs_file = os.getenv('TRACKER_PREFS')
load_tracker_prefs()
if tracker_prefs_file:
tracker_prefs = read_file(os.path.expandvars(tracker_prefs_file))
tracker_data = tracker_prefs.get(norm_str(tracker_name), {})
for k, v in tracker_data.items():
setattr(prefs.tracker, k, os.path.expandvars(v))
def unregister(): def unregister():
for cls in reversed(classes + TRACKERS): for cls in reversed(classes + TRACKERS):

View File

@ -13,13 +13,13 @@ from bpy.props import (
) )
from bpy.types import PropertyGroup, UIList from bpy.types import PropertyGroup, UIList
from pprint import pprint as pp from pprint import pprint as pp
from vse_toolbox.bl_utils import get_addon_prefs, get_settings from vse_toolbox.bl_utils import get_addon_prefs, get_scene_settings
from vse_toolbox.constants import ASSET_PREVIEWS, TRACKERS from vse_toolbox.constants import ASSET_PREVIEWS, TRACKERS
from vse_toolbox.file_utils import norm_str from vse_toolbox.file_utils import norm_str
def get_episodes_items(self, context): def get_episodes_items(self, context):
settings = get_settings() settings = get_scene_settings()
project = settings.active_project project = settings.active_project
if not project: if not project:
@ -38,7 +38,7 @@ def get_project_items(self, context):
return [(p, p, '', i) for i, p in enumerate(self.projects.keys())] return [(p, p, '', i) for i, p in enumerate(self.projects.keys())]
def update_episodes(self, context): def update_episodes(self, context):
settings = get_settings() settings = get_scene_settings()
settings['episodes'] = 0 settings['episodes'] = 0
def get_tracker_items(self, context): def get_tracker_items(self, context):
@ -51,23 +51,41 @@ class Asset(PropertyGroup):
norm_name : StringProperty(default='') norm_name : StringProperty(default='')
asset_type : StringProperty(default='') asset_type : StringProperty(default='')
tracker_name : StringProperty(default='') tracker_name : StringProperty(default='')
nombss : StringProperty(default='')
preview : StringProperty(default='') preview : StringProperty(default='')
@property
def label(self):
return f"{self.asset_type} / {self.norm_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)
def __iter__(self): def __iter__(self):
return (getattr(self, p) for p in self.bl_rna.properties.keys() if p not in ('rna_type', 'name')) return (getattr(self, p) for p in self.bl_rna.properties.keys() if p not in ('rna_type', 'name'))
@property
def asset(self):
settings = get_scene_settings()
project = settings.active_project
return project.assets.get(self.id)
def to_dict(self):
class AssetCasting(Asset): return {k: v for k,v in self.items()}
instance : IntProperty(default=1)
class Episode(PropertyGroup): class Episode(PropertyGroup):
id : StringProperty(default='') id : StringProperty(default='')
@property @property
def active(self): def active(self):
settings = get_settings() settings = get_scene_settings()
return self.get(settings.project_name) return self.get(settings.project_name)
@ -99,30 +117,35 @@ class Projects(PropertyGroup):
pass pass
# @property # @property
# def active(self): # def active(self):
# settings = get_settings() # settings = get_scene_settings()
# return self.get(settings.project_name) # return self.get(settings.project_name)
class VSETB_UL_casting(UIList): class VSETB_UL_casting(UIList):
"""Demo UIList."""
order_by_type : BoolProperty(default=False) order_by_type : BoolProperty(default=False)
def draw_item(self, context, layout, data, item, icon, active_data, def draw_item(self, context, layout, data, item, icon, active_data,
active_propname, index): active_propname, index):
settings = get_settings() settings = get_scene_settings()
project = settings.active_project 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
ico = ASSET_PREVIEWS.get(item.preview) icon_id = asset.icon_id
params = {'icon_value': ico.icon_id} if ico else {'icon': 'BLANK1'} params = {'icon_value': icon_id} if icon_id else {'icon': 'BLANK1'}
# Make sure your code supports all 3 layout types # Make sure your code supports all 3 layout types
if self.layout_type in {'DEFAULT', 'COMPACT'}: if self.layout_type in {'DEFAULT', 'COMPACT'}:
layout.label(**params) layout.label(**params)
split = layout.split(factor=0.6) split = layout.split(factor=0.6)
split.label(text=f"{item.norm_name.title()}") split.label(text=f"{asset.norm_name.title()}")
split.label(text=f"{item.asset_type.title()}") split.label(text=f"{asset.asset_type.title()}")
split.prop(item, 'instance', text='') split.prop(item, 'instance', text='')
elif self.layout_type in {'GRID'}: elif self.layout_type in {'GRID'}:
@ -154,15 +177,14 @@ class VSETB_UL_casting(UIList):
reverse=self.use_filter_sort_alpha) reverse=self.use_filter_sort_alpha)
# Order by types # Order by types
if self.order_by_type: if self.order_by_type:
_sort = [(idx, asset) for idx, asset in enumerate(items)] _sort = [(idx, casting_item) for idx, casting_item in enumerate(items)]
sort_items = helper_funcs.sort_items_helper sort_items = helper_funcs.sort_items_helper
ordered = sort_items(_sort, lambda x: (x[1].asset_type, x[1].name)) ordered = sort_items(_sort, lambda x: x[1].asset.label)
return filtered, ordered return filtered, ordered
class VSETB_PGT_settings(PropertyGroup): class VSETB_PGT_scene_settings(PropertyGroup):
_projects = []
projects : CollectionProperty(type=Project) projects : CollectionProperty(type=Project)
project_name : EnumProperty(items=get_project_items, update=update_episodes) project_name : EnumProperty(items=get_project_items, update=update_episodes)
@ -187,7 +209,7 @@ class VSETB_PGT_settings(PropertyGroup):
@property @property
def active_project(self): def active_project(self):
settings = get_settings() settings = get_scene_settings()
return settings.projects.get(settings.project_name) return settings.projects.get(settings.project_name)
@property @property
@ -195,7 +217,12 @@ class VSETB_PGT_settings(PropertyGroup):
project = self.active_project project = self.active_project
if project: if project:
return project.episodes.get(project.episode_name) 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='')
classes=( classes=(
Asset, Asset,
@ -203,7 +230,8 @@ classes=(
Project, Project,
AssetCasting, AssetCasting,
VSETB_UL_casting, VSETB_UL_casting,
VSETB_PGT_settings, VSETB_PGT_scene_settings,
VSETB_PGT_strip_settings,
) )
@ -211,14 +239,13 @@ def register():
for cls in classes: for cls in classes:
bpy.utils.register_class(cls) bpy.utils.register_class(cls)
bpy.types.WindowManager.vsetb_settings = PointerProperty(type=VSETB_PGT_settings) bpy.types.Scene.vsetb_settings = PointerProperty(type=VSETB_PGT_scene_settings)
bpy.types.Sequence.casting = CollectionProperty(type=AssetCasting) bpy.types.Sequence.vsetb_strip_settings = PointerProperty(type=VSETB_PGT_strip_settings)
bpy.types.Sequence.casting_index = IntProperty(name='Casting Index', default=0)
def unregister(): def unregister():
for cls in reversed(classes): for cls in reversed(classes):
bpy.utils.unregister_class(cls) bpy.utils.unregister_class(cls)
del bpy.types.Sequence.casting_index del bpy.types.Sequence.vsetb_strip_settings
del bpy.types.Sequence.casting del bpy.types.Scene.vsetb_settings
del bpy.types.WindowManager.vsetb_settings

View File

@ -8,7 +8,7 @@ import time
from bpy.props import PointerProperty, StringProperty from bpy.props import PointerProperty, StringProperty
from pathlib import Path from pathlib import Path
from vse_toolbox.bl_utils import get_addon_prefs, get_settings from vse_toolbox.bl_utils import get_addon_prefs, get_scene_settings
from vse_toolbox.file_utils import install_module, norm_str from vse_toolbox.file_utils import install_module, norm_str
from vse_toolbox.resources.trackers.tracker import Tracker from vse_toolbox.resources.trackers.tracker import Tracker

View File

@ -5,7 +5,7 @@ import re
from bpy.app.handlers import persistent from bpy.app.handlers import persistent
from pathlib import Path from pathlib import Path
from vse_toolbox.bl_utils import get_settings from vse_toolbox.bl_utils import get_scene_settings, get_strip_settings
def get_strips(channel=0, selected_only=False): def get_strips(channel=0, selected_only=False):
@ -38,7 +38,7 @@ def get_shot_sequence(shot):
def rename_strips( def rename_strips(
strips, template, increment=10, start_number=0, by_sequence=False): strips, template, increment=10, start_number=0, by_sequence=False):
scn = bpy.context.scene scn = bpy.context.scene
settings = get_settings() settings = get_scene_settings()
project = settings.active_project project = settings.active_project
episode = settings.active_episode episode = settings.active_episode
@ -70,7 +70,7 @@ def rename_strips(
def set_channels(): def set_channels():
scn = bpy.context.scene scn = bpy.context.scene
settings = get_settings() settings = get_scene_settings()
items = settings.rna_type.bl_rna.properties['channel'].enum_items items = settings.rna_type.bl_rna.properties['channel'].enum_items
for i, c in enumerate(items.keys(), start=1): for i, c in enumerate(items.keys(), start=1):
@ -146,6 +146,7 @@ def import_edit(filepath, adapter="cmx_3600", clean_sequencer=False):
) )
strip.blend_alpha = 0.0 strip.blend_alpha = 0.0
strip.select = False strip.select = False
strip.vsetb_strip_settings.source_name = child.name
except Exception as e: except Exception as e:
print('e: ', e) print('e: ', e)
@ -213,7 +214,7 @@ def clean_sequencer(edit=False, movie=False, sound=False):
@persistent @persistent
def get_active_strip(scene): def get_active_strip(scene):
scn = bpy.context.scene scn = bpy.context.scene
settings = get_settings() settings = get_scene_settings()
if settings.auto_select_strip == False: if settings.auto_select_strip == False:
return return