Add Remove MoveUp-Down for Casting

pull/5/head
Clément Ducarteron 2023-03-17 20:03:38 +01:00
parent 4dc52b1268
commit 538c0bf60a
7 changed files with 332 additions and 57 deletions

View File

@ -21,6 +21,7 @@ from vse_toolbox import panels
from vse_toolbox import preferences
from vse_toolbox import properties
from vse_toolbox import operators
from vse_toolbox.sequencer_utils import get_active_strip
mods = (
@ -44,10 +45,13 @@ def register():
for mod in mods:
mod.register()
bpy.app.handlers.frame_change_post.append(get_active_strip)
def unregister():
if bpy.app.background:
return
bpy.app.handlers.frame_change_post.remove(get_active_strip)
for mod in reversed(mods):
mod.unregister()

View File

@ -9,6 +9,7 @@ PROJECTS = []
EDITS = [('NONE', 'None', '', 0)]
MOVIES = [('NONE', 'None', '', 0)]
SOUNDS = [('NONE', 'None', '', 0)]
ASSETS = [('NONE', 'None', '', 0)]
EDIT_SUFFIXES = ['.xml', '.edl']
MOVIE_SUFFIXES = ['.mov', '.mp4']

View File

@ -18,6 +18,7 @@ from bpy.types import (
)
from pathlib import Path
from vse_toolbox.constants import (
ASSETS,
EDITS,
MOVIES,
SOUNDS,
@ -29,6 +30,7 @@ from vse_toolbox.sequencer_utils import (
clean_sequencer,
get_shot_sequence,
get_strips,
get_active_strip,
import_edit,
import_movie,
import_sound,
@ -213,6 +215,49 @@ class VSETB_OT_import(Operator):
return {"FINISHED"}
class VSETB_OT_load_assets(Operator):
bl_idname = "vse_toolbox.load_assets"
bl_label = "Load Assets for current projects"
bl_description = "Load Assets"
bl_options = {"REGISTER", "UNDO"}
@classmethod
def poll(cls, context):
settings = get_settings()
if settings.active_project:
return True
def get_items(self, items=[]):
if not items:
return [('NONE', 'None', '', 0)]
item_sorted = [(e.name, e.name, '', i) for i, e in enumerate(sorted(items, key=lambda x:x.name))]
return item_sorted
def execute(self, context):
settings = get_settings()
prefs = get_addon_prefs()
tracker = prefs.tracker
ASSETS.clear()
settings.active_project.assets.clear()
project = settings.active_project
assets = tracker.get_assets(project['id'])
if not assets:
self.report({'ERROR'}, f'No Assets found for {project.name}.')
for asset_data in assets:
asset = project.assets.add()
asset.name = asset_data['name']
asset.id = asset_data['id']
asset.asset_type = asset_data['asset_type']
ASSETS.extend(self.get_items(items=project.assets))
self.report({'INFO'}, f'Assets for {project.name} successfully loaded')
return {"FINISHED"}
class VSETB_OT_load_projects(Operator):
bl_idname = "vse_toolbox.load_projects"
bl_label = "Load Projects"
@ -241,6 +286,12 @@ 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'}
@ -394,7 +445,7 @@ class VSETB_OT_render(Operator):
class VSETB_OT_set_scene(Operator):
bl_idname = "scene.set_scene"
bl_idname = "vse_toolbox.set_scene"
bl_label = "Set Scene"
bl_description = "Set Scene for Breakdown"
bl_options = {"REGISTER", "UNDO"}
@ -420,10 +471,115 @@ class VSETB_OT_set_scene(Operator):
return {"FINISHED"}
class VSETB_OT_casting_add(Operator):
bl_idname = "vse_toolbox.casting_add"
bl_label = "Casting Add"
bl_description = "Add Asset to Castin"
bl_options = {"REGISTER", "UNDO"}
bl_property = "asset_name"
asset_name : EnumProperty(name='', items=lambda s, c: ASSETS)
@classmethod
def poll(cls, context):
active_strip = context.scene.sequence_editor.active_strip
if active_strip:
return True
def invoke(self, context, event):
context.window_manager.invoke_search_popup(self)
return {"FINISHED"}
def execute(self, context):
scn = context.scene
settings = get_settings()
active_strip = scn.sequence_editor.active_strip
project = settings.active_project
if active_strip.casting.get(self.asset_name):
self.report({'WARNING'}, f"Asset {self.asset_name} already casted.")
return {"CANCELLED"}
item = active_strip.casting.add()
item.name = self.asset_name
item.asset_type = project.assets[self.asset_name].asset_type
active_strip.casting.update()
return {"FINISHED"}
class VSETB_OT_casting_actions(Operator):
bl_idname = "vse_toolbox.casting_actions"
bl_label = "Casting Actions"
bl_description = "Actions to Add, Remove, Move casting items"
bl_options = {"REGISTER", "UNDO"}
action: EnumProperty(
items=(
('UP', "Up", ""),
('DOWN', "Down", ""),
('REMOVE', "Remove", ""),
)
)
asset_name : StringProperty()
@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
active_strip = scn.sequence_editor.active_strip
idx = active_strip.casting_index
try:
item = active_strip.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)
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
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)
return {"FINISHED"}
classes=(
VSETB_OT_auto_select_files,
VSETB_OT_casting_add,
VSETB_OT_casting_actions,
VSETB_OT_export_csv,
VSETB_OT_import,
VSETB_OT_load_assets,
VSETB_OT_load_projects,
VSETB_OT_new_episode,
VSETB_OT_reload_addon,

View File

@ -2,7 +2,9 @@
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.sequencer_utils import get_active_strip
class VSETB_main:
bl_space_type = "SEQUENCE_EDITOR"
@ -31,7 +33,7 @@ class VSETB_PT_main(VSETB_main, Panel):
col = layout.column()
row = col.row(align=True)
row.operator('scene.set_scene', text='Set Scene', icon='SCENE_DATA')
row.operator('vse_toolbox.set_scene', text='Set Scene', icon='SCENE_DATA')
row.prop(settings, 'toogle_prefs', text='', icon='PREFERENCES', toggle=True)
if settings.toogle_prefs:
@ -85,8 +87,7 @@ class VSETB_PT_rename(VSETB_main, Panel):
row.separator()
op = row.operator(
'sequencer.strips_rename', text='Rename Shots', icon='SORTALPHA')
op = row.operator('sequencer.strips_rename', text='Rename Shots', icon='SORTALPHA')
op.channel_name = 'Shots'
op.template = project.shot_template
op.increment = project.shot_increment
@ -94,10 +95,70 @@ class VSETB_PT_rename(VSETB_main, Panel):
row.label(text=f'{shot_template}')
#-# REGISTER
class VSETB_PT_casting(VSETB_main, Panel):
bl_label = "Shot Casting"
bl_parent_id = "VSETB_PT_main"
# def draw_header(self, context):
# settings = get_settings()
# project = settings.active_project
# if not project or not project.assets:
# ico = 'ERROR'
# else:
# ico = 'REFRESH'
# layout = self.layout
# row = layout.row()
# row.operator('vse_toolbox.load_assets', icon=ico, text='')
def draw(self, context):
layout = self.layout
scn = context.scene
active_strip = scn.sequence_editor.active_strip
if not active_strip:
return
settings = get_settings()
project = settings.active_project
if not project:
return
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 = layout.row()
ico = ("RESTRICT_SELECT_OFF" if settings.auto_select_strip else "RESTRICT_SELECT_ON")
row.prop(settings, "auto_select_strip", icon=ico)
row = layout.row()
row.label(text=f"Current Shot: {Path(active_strip.name).stem}")
row = layout.row()
row.template_list(
"VSETB_UL_casting", "shot_casting",
active_strip, "casting",
active_strip, "casting_index"
)
col = row.column(align=True)
col.operator('vse_toolbox.casting_add', icon='ADD', text="")
col.operator('vse_toolbox.casting_actions', icon='REMOVE', text="").action = 'REMOVE'
col.separator()
col.operator('vse_toolbox.casting_actions', icon='TRIA_UP', text="").action = 'UP'
col.operator('vse_toolbox.casting_actions', icon='TRIA_DOWN', text="").action = 'DOWN'
classes=(
VSETB_PT_main,
VSETB_PT_rename,
VSETB_PT_casting,
)
def register():

View File

@ -17,6 +17,7 @@ from vse_toolbox.bl_utils import get_addon_prefs, get_settings
from vse_toolbox.constants import TRACKERS
from vse_toolbox.file_utils import norm_str
def get_episodes_items(self, context):
settings = get_settings()
@ -53,6 +54,16 @@ class Episode(PropertyGroup):
return self.get(settings.project_name)
class Asset(PropertyGroup):
id : StringProperty(default='')
asset_type : StringProperty(default='')
class CastingItem(PropertyGroup):
name : StringProperty(default='')
asset_type : StringProperty(default='')
class Project(PropertyGroup):
id : StringProperty(default='')
@ -73,6 +84,7 @@ class Project(PropertyGroup):
episode_name : EnumProperty(items=get_episodes_items)
episodes : CollectionProperty(type=Episode)
assets : CollectionProperty(type=Asset)
#FIXME Trouver une solution pour mettre des method dans les CollectionProperty
@ -84,26 +96,49 @@ class Projects(PropertyGroup):
# return self.get(settings.project_name)
class VSETB_UL_channels(UIList):
class VSETB_UL_casting(UIList):
"""Demo UIList."""
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
order_by_type : BoolProperty(default=True)
items = bpy.types.GPTRACER_OT_add_property.__annotations__['enum'].keywords['items']
def draw_item(self, context, layout, data, item, icon, active_data,
active_propname, index):
enum_item = next((i for i in items if i[0]==item.name), None)
if not enum_item:
return
settings = get_settings()
project = settings.active_project
# We could write some code to decide which icon to use here...
icons = {
'camera':'CAMERA_DATA',
'chars':'COMMUNITY',
'props':'OBJECT_DATAMODE',
'sets':'SMOOTHCURVE',
}
layout.label(text=enum_item[1], icon=enum_item[-2])
# Make sure your code supports all 3 layout types
if self.layout_type in {'DEFAULT', 'COMPACT'}:
split = layout.split(factor=0.6)
split.label(text=f"{item.name}")
split.label(text=f"{item.asset_type}", icon=icons[item.asset_type])
settings = data.settings
prop = item.name
if '.' in prop:
settings, prop = prop.split('.')
settings = getattr(data.settings, settings)
elif self.layout_type in {'GRID'}:
layout.alignment = 'CENTER'
# layout.label(text="", icon = custom_icon)
layout.label(text="")
layout.prop(settings, prop, text='')
#FIXME Custom Order marche pas
# def filter_items(self, context, data, propname):
# """Filter and order items in the list."""
# filtered = []
# ordered = []
# items = getattr(data, propname)
# # Order by types
# if self.order_by_type:
# sort_items = bpy.types.UI_UL_list.sort_items_helper
# ordered = sort_items(items.keys(), key=lambda i: i.asset_type)
# return filtered, ordered
class VSETB_PGT_settings(PropertyGroup):
_projects = []
@ -112,7 +147,8 @@ class VSETB_PGT_settings(PropertyGroup):
project_name : EnumProperty(items=get_project_items, update=update_episodes)
tracker_name : EnumProperty(items=get_tracker_items)
toogle_prefs : BoolProperty(description='Toogle VSE ToolBox Preferences', default=True)
auto_select_strip : BoolProperty(
name='Auto Select Strip',description='Auto select strip', default=True)
channel : EnumProperty(
items=[
('AUDIO', 'Audio', '', 0),
@ -141,10 +177,12 @@ class VSETB_PGT_settings(PropertyGroup):
classes=(
Asset,
Episode,
Project,
CastingItem,
VSETB_UL_casting,
VSETB_PGT_settings,
# VSETB_UL_channels,
)
@ -153,9 +191,13 @@ def register():
bpy.utils.register_class(cls)
bpy.types.WindowManager.vsetb_settings = PointerProperty(type=VSETB_PGT_settings)
bpy.types.Sequence.casting = CollectionProperty(type=CastingItem)
bpy.types.Sequence.casting_index = IntProperty(name='Casting Index', default=0)
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

View File

@ -22,40 +22,12 @@ class Kitsu(Tracker):
password: StringProperty(subtype='PASSWORD')
project_name = None
# episode_name = None
def draw_prefs(self, layout):
layout.prop(self, 'url', text='Url')
layout.prop(self, 'login', text='Login')
layout.prop(self, 'password', text='Password')
# @property
# def project(self):
# settings = get_settings()
# return next(
# (p for p in settings._projects
# if norm_str(p['name']) == norm_str(settings.project_name)), {})
# @property
# def project_name(self):
# return self.project.get('name', '')
# @property
# def all_episodes(self):
# return self.project.get('episodes', {})
# @property
# def episode_name(self):
# return self.episode.get('name', '')
# @property
# def episode(self):
# settings = get_settings()
# return next(
# (e for e in self.project.get('episodes', {})
# if norm_str(e['name']) == norm_str(settings.episode_template)), {})
def get_projects(self):
return gazu.project.all_open_projects()
@ -68,9 +40,18 @@ class Kitsu(Tracker):
def new_episode(self, name):
return gazu.shot.new_episode(self.project, name)
# def update_project(self):
# self.project['episode'] = tracker.get_episodes(p)
# return self.project
def get_asset_types(self, project):
asset_types = gazu.asset.all_asset_types_for_project(project)
return {t['id']:t['name'] for t in asset_types}
def get_assets(self, project):
asset_types = self.get_asset_types(project)
assets = gazu.asset.all_assets_for_project(project)
for asset in assets:
asset['asset_type'] = asset_types[asset['entity_type_id']]
return assets
def connect(self, url=None, login=None, password=None):
'''Connect to kitsu api using provided url, login and password'''

View File

@ -3,9 +3,11 @@
import bpy
import re
from bpy.app.handlers import persistent
from pathlib import Path
from vse_toolbox.bl_utils import get_settings
def get_strips(channel=0, selected_only=False):
scn = bpy.context.scene
@ -115,7 +117,6 @@ def import_edit(filepath, adapter="cmx_3600", clean_sequencer=False):
0 if timeline.global_start_time is None else timeline.global_start_time
)
# scn.frame_end = otio.opentime.to_frames(timeline.duration())
for track in timeline.tracks:
for child in track.each_child(shallow_search=True):
@ -145,6 +146,7 @@ def import_edit(filepath, adapter="cmx_3600", clean_sequencer=False):
frame_end=frame_end,
)
strip.blend_alpha = 0.0
strip.select = False
except Exception as e:
print('e: ', e)
@ -195,7 +197,6 @@ def import_sound(filepath):
strip.show_waveform = True
return strip
def clean_sequencer(edit=False, movie=False, sound=False):
scn = bpy.context.scene
sequences = []
@ -209,3 +210,32 @@ def clean_sequencer(edit=False, movie=False, sound=False):
for sequence in sequences:
scn.sequence_editor.sequences.remove(sequence)
@persistent
def get_active_strip(scene):
scn = bpy.context.scene
settings = get_settings()
if settings.auto_select_strip == False:
return
screen = bpy.context.screen
bpy.ops.sequencer.select_all(action="DESELECT")
strip = None
frame_current = scn.frame_current
strips = bpy.context.sequences
strips = sorted(strips,key=lambda x: (x.channel, x.frame_final_start))
for strip in strips:
#FIXME Pas propre de mettre le channel name en dur
if strip.channel != get_channel('Shots') or 0:
continue
if (not strip.lock
and strip.frame_final_end >= frame_current
and strip.frame_final_start <= frame_current):
strip.select = True
scn.sequence_editor.active_strip = strip