UI: Add initial UI support for ID pointers custom properties.
Customprops to IDs are supported since years through code, but were never exposed directly in the UI of customporperties. This commit mainly: * Adds a new `DATA_BLOCK` type to UI customprops types. * Exposes the existing `id_type` settings to python API. Pull Request: https://projects.blender.org/blender/blender/pulls/110458
This commit is contained in:
@@ -80,6 +80,7 @@ def rna_idprop_ui_create(
|
||||
description=None,
|
||||
overridable=False,
|
||||
subtype=None,
|
||||
id_type='OBJECT',
|
||||
):
|
||||
"""Create and initialize a custom property with limits, defaults and other settings."""
|
||||
|
||||
@@ -91,11 +92,16 @@ def rna_idprop_ui_create(
|
||||
proptype, _ = rna_idprop_value_item_type(default)
|
||||
|
||||
if (proptype is bool) or (proptype is str):
|
||||
ui_data = item.id_properties_ui(prop)
|
||||
ui_data.update(
|
||||
description=description,
|
||||
default=default,
|
||||
)
|
||||
elif proptype is type(None) or issubclass(proptype, bpy.types.ID):
|
||||
ui_data.update(
|
||||
description=description,
|
||||
default=default,
|
||||
id_type=id_type,
|
||||
)
|
||||
else:
|
||||
if soft_min is None:
|
||||
soft_min = min
|
||||
@@ -156,6 +162,7 @@ def draw(layout, context, context_member, property_type, *, use_edit=True):
|
||||
|
||||
to_dict = getattr(value, "to_dict", None)
|
||||
to_list = getattr(value, "to_list", None)
|
||||
is_datablock = value is None or isinstance(value, bpy.types.ID)
|
||||
|
||||
if to_dict:
|
||||
value = to_dict()
|
||||
@@ -178,6 +185,8 @@ def draw(layout, context, context_member, property_type, *, use_edit=True):
|
||||
props = value_column.operator("wm.properties_edit_value", text="Edit Value")
|
||||
props.data_path = context_member
|
||||
props.property_name = key
|
||||
elif is_datablock:
|
||||
value_column.template_ID(rna_item, '["%s"]' % escape_identifier(key), text="")
|
||||
else:
|
||||
value_column.prop(rna_item, '["%s"]' % escape_identifier(key), text="")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user