Refactor and Copy Paste Casting
parent
3cc254bdc9
commit
e14dc2136d
|
@ -26,10 +26,10 @@ from vse_toolbox.sequencer_utils import get_active_strip
|
|||
|
||||
|
||||
mods = (
|
||||
panels,
|
||||
properties,
|
||||
preferences,
|
||||
operators,
|
||||
panels,
|
||||
)
|
||||
|
||||
if 'bpy' in locals():
|
||||
|
|
|
@ -5,8 +5,12 @@ Generic Blender functions
|
|||
|
||||
import bpy
|
||||
|
||||
def get_settings():
|
||||
return bpy.context.window_manager.vsetb_settings
|
||||
def get_scene_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):
|
||||
cmd = [str(blender)] if blender else [bpy.app.binary_path]
|
||||
|
|
|
@ -2,6 +2,8 @@ import appdirs
|
|||
import bpy
|
||||
import os
|
||||
from pathlib import Path
|
||||
from tempfile import gettempdir
|
||||
|
||||
|
||||
MODULE_DIR = Path(__file__).parent
|
||||
TRACKERS_DIR = MODULE_DIR / 'resources' / 'trackers'
|
||||
|
@ -11,7 +13,7 @@ PROJECTS = []
|
|||
EDITS = [('NONE', 'None', '', 0)]
|
||||
MOVIES = [('NONE', 'None', '', 0)]
|
||||
SOUNDS = [('NONE', 'None', '', 0)]
|
||||
ASSETS = [('NONE', 'None', '', 0)]
|
||||
# ASSETS = [('NONE', 'None', '', 0)]
|
||||
|
||||
EDIT_SUFFIXES = ['.xml', '.edl']
|
||||
MOVIE_SUFFIXES = ['.mov', '.mp4']
|
||||
|
@ -21,3 +23,5 @@ CONFIG_DIR = Path(appdirs.user_config_dir(__package__.split('.')[0]))
|
|||
PREVIEWS_DIR = CONFIG_DIR / 'thumbnails'
|
||||
|
||||
ASSET_PREVIEWS = bpy.utils.previews.new()
|
||||
|
||||
CASTING_BUFFER = CONFIG_DIR / 'casting.json'
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
import bpy
|
||||
import importlib
|
||||
import json
|
||||
import re
|
||||
import vse_toolbox
|
||||
|
||||
|
@ -18,8 +19,8 @@ from bpy.types import (
|
|||
)
|
||||
from pathlib import Path
|
||||
from vse_toolbox.constants import (
|
||||
ASSETS,
|
||||
ASSET_PREVIEWS,
|
||||
CASTING_BUFFER,
|
||||
CONFIG_DIR,
|
||||
EDITS,
|
||||
EDIT_SUFFIXES,
|
||||
|
@ -41,7 +42,7 @@ from vse_toolbox.sequencer_utils import (
|
|||
render_strips,
|
||||
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
|
||||
|
||||
class VSETB_OT_export_csv(Operator):
|
||||
|
@ -166,7 +167,7 @@ class VSETB_OT_import_files(Operator):
|
|||
|
||||
def draw(self, context):
|
||||
scn = context.scene
|
||||
settings = get_settings()
|
||||
settings = get_scene_settings()
|
||||
|
||||
layout = self.layout
|
||||
layout.use_property_split = True
|
||||
|
@ -257,33 +258,19 @@ class VSETB_OT_load_assets(Operator):
|
|||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
settings = get_settings()
|
||||
settings = get_scene_settings()
|
||||
if settings.active_project:
|
||||
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):
|
||||
settings = get_settings()
|
||||
settings = get_scene_settings()
|
||||
prefs = get_addon_prefs()
|
||||
tracker = prefs.tracker
|
||||
|
||||
ASSETS.clear()
|
||||
settings.active_project.assets.clear()
|
||||
|
||||
tracker.connect()
|
||||
project = settings.active_project
|
||||
project.assets.clear()
|
||||
|
||||
assets = tracker.get_assets(project['id'])
|
||||
if not assets:
|
||||
self.report({'ERROR'}, f'No Assets found for {project.name}.')
|
||||
|
@ -291,23 +278,25 @@ class VSETB_OT_load_assets(Operator):
|
|||
for asset_data in assets:
|
||||
asset = project.assets.add()
|
||||
|
||||
asset.name = asset_data['id']
|
||||
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.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')
|
||||
if 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)
|
||||
|
||||
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')
|
||||
return {"FINISHED"}
|
||||
|
@ -324,7 +313,7 @@ class VSETB_OT_load_projects(Operator):
|
|||
return True
|
||||
|
||||
def execute(self, context):
|
||||
settings = get_settings()
|
||||
settings = get_scene_settings()
|
||||
prefs = get_addon_prefs()
|
||||
tracker = prefs.tracker
|
||||
|
||||
|
@ -341,12 +330,6 @@ class VSETB_OT_load_projects(Operator):
|
|||
episode.name = episode_data['name']
|
||||
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'}
|
||||
|
||||
|
||||
|
@ -364,12 +347,12 @@ class VSETB_OT_new_episode(Operator):
|
|||
|
||||
def invoke(self, context, event):
|
||||
scn = context.scene
|
||||
settings = get_settings()
|
||||
settings = get_scene_settings()
|
||||
|
||||
return context.window_manager.invoke_props_dialog(self)
|
||||
|
||||
def execute(self, context):
|
||||
settings = get_settings()
|
||||
settings = get_scene_settings()
|
||||
prefs = get_addon_prefs()
|
||||
tracker = prefs.tracker
|
||||
|
||||
|
@ -430,13 +413,13 @@ class VSETB_OT_rename(Operator):
|
|||
|
||||
def invoke(self, context, event):
|
||||
scn = context.scene
|
||||
settings = get_settings()
|
||||
settings = get_scene_settings()
|
||||
|
||||
return context.window_manager.invoke_props_dialog(self)
|
||||
|
||||
def draw(self, context):
|
||||
scn = context.scene
|
||||
settings = get_settings()
|
||||
settings = get_scene_settings()
|
||||
|
||||
layout = self.layout
|
||||
col = layout.column()
|
||||
|
@ -474,13 +457,13 @@ class VSETB_OT_render(Operator):
|
|||
|
||||
def invoke(self, context, event):
|
||||
scn = context.scene
|
||||
settings = get_settings()
|
||||
settings = get_scene_settings()
|
||||
|
||||
return context.window_manager.invoke_props_dialog(self)
|
||||
|
||||
def draw(self, context):
|
||||
scn = context.scene
|
||||
settings = get_settings()
|
||||
settings = get_scene_settings()
|
||||
|
||||
layout = self.layout
|
||||
col = layout.column()
|
||||
|
@ -491,7 +474,7 @@ class VSETB_OT_render(Operator):
|
|||
|
||||
def execute(self, context):
|
||||
scn = context.scene
|
||||
settings = get_settings()
|
||||
settings = get_scene_settings()
|
||||
strips = get_strips(channel=settings.channel, selected_only=self.selected_only)
|
||||
|
||||
render_strips(strips)
|
||||
|
@ -526,6 +509,12 @@ class VSETB_OT_set_scene(Operator):
|
|||
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):
|
||||
bl_idname = "vse_toolbox.casting_add"
|
||||
bl_label = "Casting Add"
|
||||
|
@ -533,8 +522,7 @@ class VSETB_OT_casting_add(Operator):
|
|||
bl_options = {"REGISTER", "UNDO"}
|
||||
bl_property = "asset_name"
|
||||
|
||||
asset_name : EnumProperty(name='', items=lambda s, c: ASSETS)
|
||||
|
||||
asset_name : EnumProperty(name='', items=get_asset_items)
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
active_strip = context.scene.sequence_editor.active_strip
|
||||
|
@ -543,30 +531,72 @@ class VSETB_OT_casting_add(Operator):
|
|||
|
||||
def invoke(self, context, event):
|
||||
context.window_manager.invoke_search_popup(self)
|
||||
return {"FINISHED"}
|
||||
return {'FINISHED'}
|
||||
|
||||
def execute(self, context):
|
||||
scn = context.scene
|
||||
settings = get_settings()
|
||||
active_strip = scn.sequence_editor.active_strip
|
||||
|
||||
settings = get_scene_settings()
|
||||
strip_settings = get_strip_settings()
|
||||
|
||||
project = settings.active_project
|
||||
|
||||
if active_strip.casting.get(self.asset_name):
|
||||
self.report({'WARNING'}, f"Asset {self.asset_name} already casted.")
|
||||
if strip_settings.casting.get(self.asset_name):
|
||||
asset = project.assets[self.asset_name]
|
||||
self.report({'WARNING'}, f"Asset {asset.label} already casted.")
|
||||
return {"CANCELLED"}
|
||||
|
||||
item = active_strip.casting.add()
|
||||
item.name = self.asset_name
|
||||
for k, v in project.assets[self.asset_name].items():
|
||||
setattr(item, k, v)
|
||||
item = strip_settings.casting.add()
|
||||
asset = project.assets[self.asset_name]
|
||||
|
||||
active_strip.casting.update()
|
||||
item.name = asset.name
|
||||
item.id = project.assets[self.asset_name].id
|
||||
|
||||
strip_settings.casting.update()
|
||||
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class VSETB_OT_casting_actions(Operator):
|
||||
bl_idname = "vse_toolbox.casting_actions"
|
||||
class VSETB_OT_casting_remove(Operator):
|
||||
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_description = "Actions to Add, Remove, Move casting items"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
@ -575,7 +605,6 @@ class VSETB_OT_casting_actions(Operator):
|
|||
items=(
|
||||
('UP', "Up", ""),
|
||||
('DOWN', "Down", ""),
|
||||
('REMOVE', "Remove", ""),
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -590,49 +619,99 @@ class VSETB_OT_casting_actions(Operator):
|
|||
def invoke(self, context, event):
|
||||
scn = context.scene
|
||||
|
||||
active_strip = scn.sequence_editor.active_strip
|
||||
idx = active_strip.casting_index
|
||||
strip_settings = get_strip_settings()
|
||||
idx = strip_settings.casting_index
|
||||
|
||||
try:
|
||||
item = active_strip.casting[idx]
|
||||
item = strip_settings.casting[idx]
|
||||
except IndexError:
|
||||
pass
|
||||
else:
|
||||
if self.action == 'DOWN' and idx < len(active_strip.casting) - 1:
|
||||
item_next = active_strip.casting[idx+1].name
|
||||
active_strip.casting.move(idx, idx+1)
|
||||
active_strip.casting_index += 1
|
||||
|
||||
info = f"Item {item.name} moved to position {(item.name, active_strip.casting_index + 1)}"
|
||||
self.report({'INFO'}, info)
|
||||
if self.action == 'DOWN' and idx < len(strip_settings.casting) - 1:
|
||||
item_next = strip_settings.casting[idx+1].name
|
||||
strip_settings.casting.move(idx, idx+1)
|
||||
strip_settings.casting_index += 1
|
||||
|
||||
elif self.action == 'UP' and idx >= 1:
|
||||
item_prev = active_strip.casting[idx-1].name
|
||||
active_strip.casting.move(idx, idx-1)
|
||||
active_strip.casting_index -= 1
|
||||
item_prev = strip_settings.casting[idx-1].name
|
||||
strip_settings.casting.move(idx, idx-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 == '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)
|
||||
info = f"Item {item.asset.label} moved to position {(item.asset.label, strip_settings.casting_index + 1)}"
|
||||
self.report({'INFO'}, info)
|
||||
|
||||
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=(
|
||||
VSETB_OT_auto_select_files,
|
||||
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_import_files,
|
||||
VSETB_OT_load_assets,
|
||||
|
|
40
panels.py
40
panels.py
|
@ -3,7 +3,7 @@
|
|||
import bpy
|
||||
from bpy.types import Panel
|
||||
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.sequencer_utils import get_active_strip
|
||||
|
||||
|
@ -25,7 +25,7 @@ class VSETB_PT_main(VSETB_main, Panel):
|
|||
wm = context.window_manager
|
||||
scn = context.scene
|
||||
|
||||
settings = get_settings()
|
||||
settings = get_scene_settings()
|
||||
prefs = get_addon_prefs()
|
||||
|
||||
project = settings.active_project
|
||||
|
@ -67,7 +67,7 @@ class VSETB_PT_rename(VSETB_main, Panel):
|
|||
|
||||
def draw(self, context):
|
||||
prefs = get_addon_prefs()
|
||||
settings = get_settings()
|
||||
settings = get_scene_settings()
|
||||
project = settings.active_project
|
||||
|
||||
if not project:
|
||||
|
@ -103,10 +103,13 @@ class VSETB_PT_casting(VSETB_main, Panel):
|
|||
layout = self.layout
|
||||
scn = context.scene
|
||||
active_strip = scn.sequence_editor.active_strip
|
||||
|
||||
if not active_strip:
|
||||
return
|
||||
|
||||
settings = get_settings()
|
||||
settings = get_scene_settings()
|
||||
strip_settings = get_strip_settings()
|
||||
|
||||
project = settings.active_project
|
||||
|
||||
if not project:
|
||||
|
@ -115,11 +118,12 @@ class VSETB_PT_casting(VSETB_main, Panel):
|
|||
if not project.assets:
|
||||
row = layout.row(align=True)
|
||||
row.label(text='No Assets found. Load Assets first.')
|
||||
row.operator('vse_toolbox.load_assets', icon='FILE_REFRESH', text='')
|
||||
else:
|
||||
row = layout.row(align=True)
|
||||
row.label(text=f'Assets for {project.name} successfully loaded.')
|
||||
|
||||
row.operator('vse_toolbox.load_assets', icon='FILE_REFRESH', text='')
|
||||
|
||||
row = layout.row()
|
||||
ico = ("RESTRICT_SELECT_OFF" if settings.auto_select_strip else "RESTRICT_SELECT_ON")
|
||||
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 = layout.row()
|
||||
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:
|
||||
active_asset = active_strip.casting[active_strip.casting_index]
|
||||
ico = ASSET_PREVIEWS.get(active_asset.preview)
|
||||
if ico:
|
||||
box = col.box()
|
||||
box.template_icon(icon_value=ico.icon_id, scale=7.5)
|
||||
if strip_settings.casting:
|
||||
casting_item = strip_settings.casting[strip_settings.casting_index]
|
||||
asset = casting_item.asset
|
||||
if asset:
|
||||
ico = ASSET_PREVIEWS.get(asset.preview)
|
||||
if ico:
|
||||
box = col.box()
|
||||
box.template_icon(icon_value=ico.icon_id, scale=7.5)
|
||||
|
||||
col_tool = row.column(align=True)
|
||||
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.operator('vse_toolbox.casting_actions', icon='TRIA_UP', text="").action = 'UP'
|
||||
col_tool.operator('vse_toolbox.casting_actions', icon='TRIA_DOWN', text="").action = 'DOWN'
|
||||
#TODO Add Nombre instance (IntProperty)
|
||||
col_tool.operator('vse_toolbox.casting_move', icon='TRIA_UP', text="").action = 'UP'
|
||||
col_tool.operator('vse_toolbox.casting_move', icon='TRIA_DOWN', text="").action = 'DOWN'
|
||||
col_tool.separator()
|
||||
col_tool.operator('sequencer.copy_casting', icon='COPYDOWN', text="")
|
||||
col_tool.operator('sequencer.paste_casting', icon='PASTEDOWN', text="")
|
||||
|
||||
|
||||
classes=(
|
||||
|
|
|
@ -17,7 +17,7 @@ from bpy.types import (
|
|||
AddonPreferences,
|
||||
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 (
|
||||
TRACKERS,
|
||||
TRACKERS_DIR,
|
||||
|
@ -29,9 +29,6 @@ from vse_toolbox.file_utils import (
|
|||
)
|
||||
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():
|
||||
from vse_toolbox.resources.trackers.tracker import Tracker
|
||||
|
||||
|
@ -63,6 +60,30 @@ def load_trackers():
|
|||
print(f'Could not register library_type {name}')
|
||||
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):
|
||||
def __iter__(self):
|
||||
|
@ -77,11 +98,11 @@ class VSETB_Prefs(AddonPreferences):
|
|||
|
||||
@property
|
||||
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):
|
||||
prefs = get_addon_prefs()
|
||||
settings = get_settings()
|
||||
settings = get_scene_settings()
|
||||
|
||||
layout = self.layout
|
||||
|
||||
|
@ -113,20 +134,12 @@ def register():
|
|||
|
||||
load_trackers()
|
||||
prefs = get_addon_prefs()
|
||||
settings = get_settings()
|
||||
|
||||
tracker_name = os.getenv('TRACKER_NAME')
|
||||
|
||||
if tracker_name:
|
||||
if tracker_name is not None:
|
||||
prefs['tracker_name'] = os.path.expandvars(norm_str(tracker_name, format=str.upper))
|
||||
tracker_prefs_file = os.getenv('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))
|
||||
load_tracker_prefs()
|
||||
|
||||
def unregister():
|
||||
for cls in reversed(classes + TRACKERS):
|
||||
|
|
|
@ -13,13 +13,13 @@ from bpy.props import (
|
|||
)
|
||||
from bpy.types import PropertyGroup, UIList
|
||||
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.file_utils import norm_str
|
||||
|
||||
|
||||
def get_episodes_items(self, context):
|
||||
settings = get_settings()
|
||||
settings = get_scene_settings()
|
||||
|
||||
project = settings.active_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())]
|
||||
|
||||
def update_episodes(self, context):
|
||||
settings = get_settings()
|
||||
settings = get_scene_settings()
|
||||
settings['episodes'] = 0
|
||||
|
||||
def get_tracker_items(self, context):
|
||||
|
@ -51,23 +51,41 @@ class Asset(PropertyGroup):
|
|||
norm_name : StringProperty(default='')
|
||||
asset_type : StringProperty(default='')
|
||||
tracker_name : StringProperty(default='')
|
||||
nombss : 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):
|
||||
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)
|
||||
|
||||
class AssetCasting(Asset):
|
||||
instance : IntProperty(default=1)
|
||||
|
||||
def to_dict(self):
|
||||
return {k: v for k,v in self.items()}
|
||||
|
||||
class Episode(PropertyGroup):
|
||||
id : StringProperty(default='')
|
||||
|
||||
@property
|
||||
def active(self):
|
||||
settings = get_settings()
|
||||
settings = get_scene_settings()
|
||||
return self.get(settings.project_name)
|
||||
|
||||
|
||||
|
@ -99,30 +117,35 @@ class Projects(PropertyGroup):
|
|||
pass
|
||||
# @property
|
||||
# def active(self):
|
||||
# settings = get_settings()
|
||||
# settings = get_scene_settings()
|
||||
# return self.get(settings.project_name)
|
||||
|
||||
|
||||
class VSETB_UL_casting(UIList):
|
||||
"""Demo UIList."""
|
||||
|
||||
order_by_type : BoolProperty(default=False)
|
||||
|
||||
def draw_item(self, context, layout, data, item, icon, active_data,
|
||||
active_propname, index):
|
||||
|
||||
settings = get_settings()
|
||||
settings = get_scene_settings()
|
||||
project = settings.active_project
|
||||
|
||||
ico = ASSET_PREVIEWS.get(item.preview)
|
||||
params = {'icon_value': ico.icon_id} if ico else {'icon': 'BLANK1'}
|
||||
# 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
|
||||
|
||||
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"{item.norm_name.title()}")
|
||||
split.label(text=f"{item.asset_type.title()}")
|
||||
split.label(text=f"{asset.norm_name.title()}")
|
||||
split.label(text=f"{asset.asset_type.title()}")
|
||||
split.prop(item, 'instance', text='')
|
||||
|
||||
elif self.layout_type in {'GRID'}:
|
||||
|
@ -154,15 +177,14 @@ class VSETB_UL_casting(UIList):
|
|||
reverse=self.use_filter_sort_alpha)
|
||||
# Order by types
|
||||
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
|
||||
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
|
||||
|
||||
|
||||
class VSETB_PGT_settings(PropertyGroup):
|
||||
_projects = []
|
||||
class VSETB_PGT_scene_settings(PropertyGroup):
|
||||
|
||||
projects : CollectionProperty(type=Project)
|
||||
project_name : EnumProperty(items=get_project_items, update=update_episodes)
|
||||
|
@ -187,7 +209,7 @@ class VSETB_PGT_settings(PropertyGroup):
|
|||
|
||||
@property
|
||||
def active_project(self):
|
||||
settings = get_settings()
|
||||
settings = get_scene_settings()
|
||||
return settings.projects.get(settings.project_name)
|
||||
|
||||
@property
|
||||
|
@ -197,13 +219,19 @@ class VSETB_PGT_settings(PropertyGroup):
|
|||
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=(
|
||||
Asset,
|
||||
Episode,
|
||||
Project,
|
||||
AssetCasting,
|
||||
VSETB_UL_casting,
|
||||
VSETB_PGT_settings,
|
||||
VSETB_PGT_scene_settings,
|
||||
VSETB_PGT_strip_settings,
|
||||
)
|
||||
|
||||
|
||||
|
@ -211,14 +239,13 @@ def register():
|
|||
for cls in classes:
|
||||
bpy.utils.register_class(cls)
|
||||
|
||||
bpy.types.WindowManager.vsetb_settings = PointerProperty(type=VSETB_PGT_settings)
|
||||
bpy.types.Sequence.casting = CollectionProperty(type=AssetCasting)
|
||||
bpy.types.Sequence.casting_index = IntProperty(name='Casting Index', default=0)
|
||||
bpy.types.Scene.vsetb_settings = PointerProperty(type=VSETB_PGT_scene_settings)
|
||||
bpy.types.Sequence.vsetb_strip_settings = PointerProperty(type=VSETB_PGT_strip_settings)
|
||||
|
||||
|
||||
def unregister():
|
||||
for cls in reversed(classes):
|
||||
bpy.utils.unregister_class(cls)
|
||||
|
||||
del bpy.types.Sequence.casting_index
|
||||
del bpy.types.Sequence.casting
|
||||
del bpy.types.WindowManager.vsetb_settings
|
||||
del bpy.types.Sequence.vsetb_strip_settings
|
||||
del bpy.types.Scene.vsetb_settings
|
||||
|
|
|
@ -8,7 +8,7 @@ import time
|
|||
|
||||
from bpy.props import PointerProperty, StringProperty
|
||||
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.resources.trackers.tracker import Tracker
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import re
|
|||
|
||||
from bpy.app.handlers import persistent
|
||||
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):
|
||||
|
@ -38,7 +38,7 @@ def get_shot_sequence(shot):
|
|||
def rename_strips(
|
||||
strips, template, increment=10, start_number=0, by_sequence=False):
|
||||
scn = bpy.context.scene
|
||||
settings = get_settings()
|
||||
settings = get_scene_settings()
|
||||
|
||||
project = settings.active_project
|
||||
episode = settings.active_episode
|
||||
|
@ -70,7 +70,7 @@ def rename_strips(
|
|||
|
||||
def set_channels():
|
||||
scn = bpy.context.scene
|
||||
settings = get_settings()
|
||||
settings = get_scene_settings()
|
||||
items = settings.rna_type.bl_rna.properties['channel'].enum_items
|
||||
|
||||
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.select = False
|
||||
strip.vsetb_strip_settings.source_name = child.name
|
||||
|
||||
except Exception as e:
|
||||
print('e: ', e)
|
||||
|
@ -213,7 +214,7 @@ def clean_sequencer(edit=False, movie=False, sound=False):
|
|||
@persistent
|
||||
def get_active_strip(scene):
|
||||
scn = bpy.context.scene
|
||||
settings = get_settings()
|
||||
settings = get_scene_settings()
|
||||
|
||||
if settings.auto_select_strip == False:
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue