From be7e2d01a89d3c29374a683390e16201f4216fbb Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Fri, 22 Sep 2023 12:38:37 +0300 Subject: [PATCH] Python: support the step and precision arguments in rna_idprop_ui_create. Support the property settings that were implemented some time ago. As an aside, change the defaults for min and max to integers: integer values can be implicitly cast to float, but the reverse results in an error. Also, pointer properties don't support a default value. Pull Request: https://projects.blender.org/blender/blender/pulls/112712 --- scripts/modules/rna_prop_ui.py | 38 +++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/scripts/modules/rna_prop_ui.py b/scripts/modules/rna_prop_ui.py index 843948eef43..27b7238c409 100644 --- a/scripts/modules/rna_prop_ui.py +++ b/scripts/modules/rna_prop_ui.py @@ -75,11 +75,13 @@ def rna_idprop_ui_prop_default_set(item, prop, value): def rna_idprop_ui_create( item, prop, *, default, - min=0.0, max=1.0, + min=0, max=1, soft_min=None, soft_max=None, description=None, overridable=False, subtype=None, + step=None, + precision=None, id_type='OBJECT', ): """Create and initialize a custom property with limits, defaults and other settings.""" @@ -91,6 +93,11 @@ def rna_idprop_ui_create( ui_data = item.id_properties_ui(prop) proptype, _ = rna_idprop_value_item_type(default) + if soft_min is None: + soft_min = min + if soft_max is None: + soft_max = max + if (proptype is bool) or (proptype is str): ui_data.update( description=description, @@ -99,14 +106,13 @@ def rna_idprop_ui_create( 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 - if soft_max is None: - soft_max = max + elif proptype is float: + if step is None: + step = 0.1 + if precision is None: + precision = 3 ui_data.update( subtype=subtype, @@ -114,9 +120,27 @@ def rna_idprop_ui_create( max=max, soft_min=soft_min, soft_max=soft_max, + step=step, + precision=precision, description=description, default=default, ) + elif proptype is int: + if step is None: + step = 1 + + ui_data.update( + subtype=subtype, + min=min, + max=max, + soft_min=soft_min, + soft_max=soft_max, + step=step, + description=description, + default=default, + ) + else: + raise TypeError("Unexpected value type") prop_path = rna_idprop_quote_path(prop)