prop_search

pull/5/head
Christophe SEUX 2023-04-23 13:07:33 +02:00
parent 5c35bae0e3
commit a7afedd49b
3 changed files with 33 additions and 15 deletions

View File

@ -631,7 +631,11 @@ class VSETB_OT_load_projects(Operator):
metadata_type = project.metadata_types.add() metadata_type = project.metadata_types.add()
metadata_type.name = metadata_data['name'] metadata_type.name = metadata_data['name']
metadata_type.field_name = metadata_data['field_name'] metadata_type.field_name = metadata_data['field_name']
metadata_type['choices'] = metadata_data['choices'] #metadata_type['choices'] = metadata_data['choices']
for choice in metadata_data['choices']:
choice_item = metadata_type.choices.add()
choice_item.name = choice
metadata_type['entity_type'] = metadata_data['entity_type'].upper() metadata_type['entity_type'] = metadata_data['entity_type'].upper()
for status_data in tracker.get_task_statuses(project_data): for status_data in tracker.get_task_statuses(project_data):

View File

@ -274,8 +274,24 @@ class VSETB_PT_metadata(VSETB_main, Panel):
layout.prop(strip_settings, 'description', text='DESCRIPTION') layout.prop(strip_settings, 'description', text='DESCRIPTION')
#col = layout.column() #col = layout.column()
for key in strip_settings.metadata.__annotations__.keys(): for metadata_type in project.metadata_types:
layout.prop(strip_settings.metadata, key, text=key.upper()) if metadata_type.entity_type == 'SHOT':
row = layout.row(align=True)
metadata_key = metadata_type.field_name
if metadata_type.choices:
metadata_value = getattr(strip_settings.metadata, metadata_key)
icon = 'LAYER_USED'
if metadata_value:
if metadata_value in metadata_type.choices:
icon = 'DOT'
else:
icon = 'ADD'
row.prop_search(strip_settings.metadata, metadata_key, metadata_type, 'choices',
results_are_suggestions=True, icon=icon)
else:
row.prop(strip_settings.metadata, metadata_key, text=metadata_key.upper())
classes = ( classes = (
VSETB_PT_main, VSETB_PT_main,

View File

@ -86,6 +86,7 @@ def get_preview_items(self, context):
return [] return []
class Asset(PropertyGroup): class Asset(PropertyGroup):
name : StringProperty(default='') name : StringProperty(default='')
id : StringProperty(default='') id : StringProperty(default='')
@ -97,7 +98,7 @@ class Asset(PropertyGroup):
@property @property
def label(self): def label(self):
return f"{self.asset_type} / {self.norm_name}" return f"{self.asset_type} / {self.tracker_name}"
@property @property
def icon_id(self): def icon_id(self):
@ -129,8 +130,8 @@ class AssetType(PropertyGroup):
class MetadataType(PropertyGroup): class MetadataType(PropertyGroup):
choices = [] #choices = []
choice : EnumProperty(items=lambda s, c: [(c, c.replace(' ', '_').upper(), '') for c in s['choices']]) choices : CollectionProperty(type=PropertyGroup)#EnumProperty(items=lambda s, c: [(c, c.replace(' ', '_').upper(), '') for c in s['choices']])
field_name : StringProperty() field_name : StringProperty()
entity_type : StringProperty() entity_type : StringProperty()
@ -255,10 +256,11 @@ class Project(PropertyGroup):
field_name = metadata_type.field_name field_name = metadata_type.field_name
name = metadata_type.name name = metadata_type.name
if metadata_type.get('choices'): #if metadata_type.get('choices'):
prop = bpy.props.EnumProperty(items=[(c, c, '') for c in ['/'] + metadata_type['choices']], name=name) # prop = #bpy.props.EnumProperty(items=[(c, c, '') for c in ['/'] + metadata_type['choices']], name=name)
else: #else:
prop = bpy.props.StringProperty(name=name) # prop = #bpy.props.StringProperty(name=name)
prop = bpy.props.StringProperty(name=name)
Metadata.__annotations__[field_name] = prop Metadata.__annotations__[field_name] = prop
setattr(Metadata, field_name, prop) setattr(Metadata, field_name, prop)
@ -436,17 +438,13 @@ def load_handler(dummy):
#settings.active_project.set_spreadsheet() #settings.active_project.set_spreadsheet()
os.environ['TRACKER_PROJECT_ID'] = settings.active_project.id os.environ['TRACKER_PROJECT_ID'] = settings.active_project.id
for asset in project.assets: for asset in project.assets:
preview_id = asset.preview preview_id = asset.preview
preview_path = Path(PREVIEWS_DIR / project.id / preview_id).with_suffix('.png') preview_path = Path(PREVIEWS_DIR / project.id / preview_id).with_suffix('.png')
if preview_path.exists() and preview_id not in ASSET_PREVIEWS: if preview_path.exists() and preview_id not in ASSET_PREVIEWS:
ASSET_PREVIEWS.load(preview_id, preview_path.as_posix(), 'IMAGE', True) ASSET_PREVIEWS.load(preview_id, preview_path.as_posix(), 'IMAGE', True)
print(preview_path)
print(ASSET_PREVIEWS)
def register(): def register():
for cls in classes: for cls in classes: