From 4a5d150156ce2503173ead73b09c556c17d05b7a Mon Sep 17 00:00:00 2001 From: Colin Basnett Date: Fri, 7 Apr 2023 16:24:45 -0700 Subject: [PATCH 1/4] Add sub-types for float-type custom properties --- scripts/startup/bl_operators/wm.py | 48 +++++++++++++++++++----------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/scripts/startup/bl_operators/wm.py b/scripts/startup/bl_operators/wm.py index 5b4f1987e86..f7b3f30f70d 100644 --- a/scripts/startup/bl_operators/wm.py +++ b/scripts/startup/bl_operators/wm.py @@ -1356,9 +1356,18 @@ rna_custom_property_type_items = ( ('PYTHON', "Python", "Edit a python value directly, for unsupported property types"), ) -# Most useful entries of rna_enum_property_subtype_items for number arrays: +rna_number_subtype_items = ( + ('PIXEL', "Pixel", ""), + ('PERCENTAGE', "Percentage", ""), + ('FACTOR', "Factor", ""), + ('ANGLE', "Angle", ""), + ('TIME_ABSOLUTE', "Time", "Time specified in seconds"), + ('DISTANCE', "Distance", ""), + ('POWER', "Power", ""), + ('TEMPERATURE', "Temperature", ""), +) + rna_vector_subtype_items = ( - ('NONE', "Plain Data", "Data values without special behavior"), ('COLOR', "Linear Color", "Color in the linear space"), ('COLOR_GAMMA', "Gamma-Corrected Color", "Color in the gamma corrected space"), ('EULER', "Euler Angles", "Euler rotation angles in radians"), @@ -1366,6 +1375,21 @@ rna_vector_subtype_items = ( ) +def subtype_items_cb(self, context): + subtype_items = [ + ('NONE', "Plain Data", "Data values without special behavior") + ] + if self.property_type == 'FLOAT': + subtype_items.extend(rna_number_subtype_items) + elif self.property_type == 'FLOAT_ARRAY': + subtype_items.extend(rna_vector_subtype_items) + return subtype_items + + +def property_type_update_cb(self, context): + self.subtype = 'NONE' + + class WM_OT_properties_edit(Operator): """Change a custom property's type, or adjust how it is displayed in the interface""" bl_idname = "wm.properties_edit" @@ -1381,6 +1405,7 @@ class WM_OT_properties_edit(Operator): property_type: EnumProperty( name="Type", items=rna_custom_property_type_items, + update=property_type_update_cb ) is_overridable_library: BoolProperty( name="Library Overridable", @@ -1481,7 +1506,7 @@ class WM_OT_properties_edit(Operator): ) subtype: EnumProperty( name="Subtype", - items=WM_OT_properties_edit.subtype_items, + items=subtype_items_cb, ) # String properties. @@ -1497,9 +1522,6 @@ class WM_OT_properties_edit(Operator): description="Python value for unsupported custom property types", ) - type_items = rna_custom_property_type_items - subtype_items = rna_vector_subtype_items - # Helper method to avoid repetitive code to retrieve a single value from sequences and non-sequences. @staticmethod def _convert_new_value_single(old_value, new_type): @@ -1567,15 +1589,7 @@ class WM_OT_properties_edit(Operator): return 'PYTHON' def _init_subtype(self, subtype): - subtype = subtype or 'NONE' - subtype_items = rna_vector_subtype_items - - # Add a temporary enum entry to preserve unknown subtypes - if not any(subtype == item[0] for item in subtype_items): - subtype_items += ((subtype, subtype, ""),) - - WM_OT_properties_edit.subtype_items = subtype_items - self.subtype = subtype + self.subtype = subtype or 'NONE' # Fill the operator's properties with the UI data properties from the existing custom property. # Note that if the UI data doesn't exist yet, the access will create it and use those default values. @@ -1904,9 +1918,7 @@ class WM_OT_properties_edit(Operator): layout.prop(self, "step_float") layout.prop(self, "precision") - # Subtype is only supported for float properties currently. - if self.property_type != 'FLOAT': - layout.prop(self, "subtype") + layout.prop(self, "subtype") elif self.property_type in {'INT', 'INT_ARRAY'}: if self.property_type == 'INT_ARRAY': layout.prop(self, "array_length") -- 2.30.2 From d998573c9978e2a3e590c1cdcf20bdc069ba79dd Mon Sep 17 00:00:00 2001 From: Colin Basnett Date: Fri, 14 Apr 2023 02:08:19 -0700 Subject: [PATCH 2/4] Restored comment and moved callback functions into class scope --- scripts/startup/bl_operators/wm.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/scripts/startup/bl_operators/wm.py b/scripts/startup/bl_operators/wm.py index f7b3f30f70d..4122b59a96e 100644 --- a/scripts/startup/bl_operators/wm.py +++ b/scripts/startup/bl_operators/wm.py @@ -1345,6 +1345,7 @@ rna_custom_property_name = StringProperty( maxlen=63, ) +# Most useful entries of rna_enum_property_subtype_items: rna_custom_property_type_items = ( ('FLOAT', "Float", "A single floating-point value"), ('FLOAT_ARRAY', "Float Array", "An array of floating-point values"), @@ -1375,27 +1376,25 @@ rna_vector_subtype_items = ( ) -def subtype_items_cb(self, context): - subtype_items = [ - ('NONE', "Plain Data", "Data values without special behavior") - ] - if self.property_type == 'FLOAT': - subtype_items.extend(rna_number_subtype_items) - elif self.property_type == 'FLOAT_ARRAY': - subtype_items.extend(rna_vector_subtype_items) - return subtype_items - - -def property_type_update_cb(self, context): - self.subtype = 'NONE' - - class WM_OT_properties_edit(Operator): """Change a custom property's type, or adjust how it is displayed in the interface""" bl_idname = "wm.properties_edit" bl_label = "Edit Property" # register only because invoke_props_popup requires. bl_options = {'REGISTER', 'INTERNAL'} + + def subtype_items_cb(self, context): + subtype_items = [ + ('NONE', "Plain Data", "Data values without special behavior") + ] + if self.property_type == 'FLOAT': + subtype_items.extend(rna_number_subtype_items) + elif self.property_type == 'FLOAT_ARRAY': + subtype_items.extend(rna_vector_subtype_items) + return subtype_items + + def property_type_update_cb(self, context): + self.subtype = 'NONE' # Common settings used for all property types. Generally, separate properties are used for each # type to improve the experience when choosing UI data values. -- 2.30.2 From beec7a0ee95a3d4ed05b196a4b2b9e94b1654e2e Mon Sep 17 00:00:00 2001 From: Colin Basnett Date: Tue, 18 Apr 2023 21:07:17 -0700 Subject: [PATCH 3/4] Removed trailing whitespace --- scripts/startup/bl_operators/wm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/startup/bl_operators/wm.py b/scripts/startup/bl_operators/wm.py index 4122b59a96e..e80eec783d2 100644 --- a/scripts/startup/bl_operators/wm.py +++ b/scripts/startup/bl_operators/wm.py @@ -1382,7 +1382,7 @@ class WM_OT_properties_edit(Operator): bl_label = "Edit Property" # register only because invoke_props_popup requires. bl_options = {'REGISTER', 'INTERNAL'} - + def subtype_items_cb(self, context): subtype_items = [ ('NONE', "Plain Data", "Data values without special behavior") -- 2.30.2 From be8e0dbf50222f3a5e21007a9e51dcc9aa90927a Mon Sep 17 00:00:00 2001 From: Colin Basnett Date: Thu, 27 Apr 2023 20:13:25 -0700 Subject: [PATCH 4/4] Moved `NONE` type to a variable that is used when populating other subtype item lists --- scripts/startup/bl_operators/wm.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/scripts/startup/bl_operators/wm.py b/scripts/startup/bl_operators/wm.py index e80eec783d2..247cad330d7 100644 --- a/scripts/startup/bl_operators/wm.py +++ b/scripts/startup/bl_operators/wm.py @@ -1357,7 +1357,10 @@ rna_custom_property_type_items = ( ('PYTHON', "Python", "Edit a python value directly, for unsupported property types"), ) +rna_generic_subtype_none_item = ('NONE', "Plain Data", "Data values without special behavior") + rna_number_subtype_items = ( + rna_generic_subtype_none_item, ('PIXEL', "Pixel", ""), ('PERCENTAGE', "Percentage", ""), ('FACTOR', "Factor", ""), @@ -1369,6 +1372,7 @@ rna_number_subtype_items = ( ) rna_vector_subtype_items = ( + rna_generic_subtype_none_item, ('COLOR', "Linear Color", "Color in the linear space"), ('COLOR_GAMMA', "Gamma-Corrected Color", "Color in the gamma corrected space"), ('EULER', "Euler Angles", "Euler rotation angles in radians"), @@ -1384,14 +1388,11 @@ class WM_OT_properties_edit(Operator): bl_options = {'REGISTER', 'INTERNAL'} def subtype_items_cb(self, context): - subtype_items = [ - ('NONE', "Plain Data", "Data values without special behavior") - ] if self.property_type == 'FLOAT': - subtype_items.extend(rna_number_subtype_items) + return rna_number_subtype_items elif self.property_type == 'FLOAT_ARRAY': - subtype_items.extend(rna_vector_subtype_items) - return subtype_items + return rna_vector_subtype_items + return [] def property_type_update_cb(self, context): self.subtype = 'NONE' -- 2.30.2