From c518ccf2b4d6e2cb8332a6cae12197986e47ade4 Mon Sep 17 00:00:00 2001 From: Clement Ducarteron Date: Fri, 17 Mar 2023 22:54:48 +0100 Subject: [PATCH] Order uilist by asset type --- properties.py | 51 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/properties.py b/properties.py index 829682a..7745db7 100644 --- a/properties.py +++ b/properties.py @@ -56,6 +56,7 @@ class Episode(PropertyGroup): class Asset(PropertyGroup): id : StringProperty(default='') + norm_name : StringProperty(default='') asset_type : StringProperty(default='') @@ -80,7 +81,7 @@ class Project(PropertyGroup): name="Episode Name", default="e{index:03d}") shot_template : StringProperty( - name="Shot Name", default="{episode}sh{index:04d}") + name="Shot Name", default="{episode}s{index:04d}") episode_name : EnumProperty(items=get_episodes_items) episodes : CollectionProperty(type=Episode) @@ -118,28 +119,50 @@ class VSETB_UL_casting(UIList): 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]) + split.label(text=f"{item.asset_type.title()}", icon=icons[item.asset_type]) elif self.layout_type in {'GRID'}: layout.alignment = 'CENTER' # layout.label(text="", icon = custom_icon) layout.label(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) + def draw_filter(self, context, layout): + row = layout.row() - # # 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) + 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') - # return filtered, ordered + + 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 + class VSETB_PGT_settings(PropertyGroup): _projects = []