vse_toolbox/properties.py

227 lines
6.7 KiB
Python
Raw Normal View History

2023-03-14 13:38:04 +01:00
# SPDX-License-Identifier: GPL-2.0-or-later
import bpy
import os
from bpy.props import (
BoolProperty,
CollectionProperty,
EnumProperty,
IntProperty,
PointerProperty,
StringProperty,
)
2023-03-16 18:32:17 +01:00
from bpy.types import PropertyGroup, UIList
2023-03-14 13:38:04 +01:00
from pprint import pprint as pp
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
2023-03-17 20:03:38 +01:00
2023-03-14 13:38:04 +01:00
def get_episodes_items(self, context):
settings = get_settings()
project = settings.active_project
if not project:
return [('NONE', 'None', '', 0)]
episodes = project.episodes
if not episodes:
return [('NONE', 'None', '', 0)]
return [(e, e, '', i) for i, e in enumerate(episodes.keys())]
def get_project_items(self, context):
if not self.projects:
return [('NONE', 'None', '', 0)]
return [(p, p, '', i) for i, p in enumerate(self.projects.keys())]
def update_episodes(self, context):
settings = get_settings()
settings['episodes'] = 0
def get_tracker_items(self, context):
return [(norm_str(a.name, format=str.upper), a.name, "", i) for i, a in enumerate(TRACKERS)]
class Episode(PropertyGroup):
id : StringProperty(default='')
@property
def active(self):
settings = get_settings()
return self.get(settings.project_name)
2023-03-17 20:03:38 +01:00
class Asset(PropertyGroup):
id : StringProperty(default='')
2023-03-17 22:54:48 +01:00
norm_name : StringProperty(default='')
2023-03-17 20:03:38 +01:00
asset_type : StringProperty(default='')
class CastingItem(PropertyGroup):
name : StringProperty(default='')
asset_type : StringProperty(default='')
2023-03-14 13:38:04 +01:00
class Project(PropertyGroup):
id : StringProperty(default='')
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="e{index:03d}")
shot_template : StringProperty(
2023-03-17 22:54:48 +01:00
name="Shot Name", default="{episode}s{index:04d}")
2023-03-14 13:38:04 +01:00
episode_name : EnumProperty(items=get_episodes_items)
episodes : CollectionProperty(type=Episode)
2023-03-17 20:03:38 +01:00
assets : CollectionProperty(type=Asset)
2023-03-14 13:38:04 +01:00
2023-03-16 18:32:17 +01:00
2023-03-14 13:38:04 +01:00
#FIXME Trouver une solution pour mettre des method dans les CollectionProperty
class Projects(PropertyGroup):
pass
# @property
# def active(self):
# settings = get_settings()
# return self.get(settings.project_name)
2023-03-17 20:03:38 +01:00
class VSETB_UL_casting(UIList):
2023-03-16 18:32:17 +01:00
"""Demo UIList."""
2023-03-17 20:03:38 +01:00
order_by_type : BoolProperty(default=True)
2023-03-16 18:32:17 +01:00
2023-03-17 20:03:38 +01:00
def draw_item(self, context, layout, data, item, icon, active_data,
active_propname, index):
2023-03-16 18:32:17 +01:00
2023-03-17 20:03:38 +01:00
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',
}
# 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}")
2023-03-17 22:54:48 +01:00
split.label(text=f"{item.asset_type.title()}", icon=icons[item.asset_type])
2023-03-17 20:03:38 +01:00
elif self.layout_type in {'GRID'}:
layout.alignment = 'CENTER'
# layout.label(text="", icon = custom_icon)
layout.label(text="")
2023-03-16 18:32:17 +01:00
2023-03-17 22:54:48 +01:00
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, "use_filter_sort_alpha", text="", icon='SORTALPHA')
# subrow.prop(self, "use_filter_sort_reverse", text="", icon='SORT_ASC')
subrow.separator()
subrow.prop(self, "order_by_type", text="Order by Type", icon='MESH_DATA')
2023-03-16 18:32:17 +01:00
2023-03-17 22:54:48 +01:00
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, asset) for idx, asset in enumerate(items)]
sort_items = helper_funcs.sort_items_helper
ordered = sort_items(_sort, lambda x: (x[1].name, x[1].asset_type))
return filtered, ordered
2023-03-17 20:03:38 +01:00
2023-03-17 22:54:48 +01:00
2023-03-14 13:38:04 +01:00
class VSETB_PGT_settings(PropertyGroup):
_projects = []
projects : CollectionProperty(type=Project)
project_name : EnumProperty(items=get_project_items, update=update_episodes)
tracker_name : EnumProperty(items=get_tracker_items)
2023-03-16 18:39:15 +01:00
toogle_prefs : BoolProperty(description='Toogle VSE ToolBox Preferences', default=True)
2023-03-17 20:03:38 +01:00
auto_select_strip : BoolProperty(
name='Auto Select Strip',description='Auto select strip', default=True)
2023-03-16 18:32:17 +01:00
channel : EnumProperty(
2023-03-14 13:38:04 +01:00
items=[
('AUDIO', 'Audio', '', 0),
('MOVIE', 'Movie', '', 1),
('SHOTS', 'Shots', '', 2),
('SEQUENCES', 'Sequences', '', 3),
]
)
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_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)
2023-03-16 18:32:17 +01:00
2023-03-14 13:38:04 +01:00
classes=(
2023-03-17 20:03:38 +01:00
Asset,
2023-03-14 13:38:04 +01:00
Episode,
Project,
2023-03-17 20:03:38 +01:00
CastingItem,
VSETB_UL_casting,
2023-03-14 13:38:04 +01:00
VSETB_PGT_settings,
)
def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.WindowManager.vsetb_settings = PointerProperty(type=VSETB_PGT_settings)
2023-03-17 20:03:38 +01:00
bpy.types.Sequence.casting = CollectionProperty(type=CastingItem)
bpy.types.Sequence.casting_index = IntProperty(name='Casting Index', default=0)
2023-03-14 13:38:04 +01:00
def unregister():
for cls in reversed(classes):
bpy.utils.unregister_class(cls)
2023-03-17 20:03:38 +01:00
del bpy.types.Sequence.casting_index
del bpy.types.Sequence.casting
2023-03-14 13:38:04 +01:00
del bpy.types.WindowManager.vsetb_settings