Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2021-10-25 18:01:07 +0300
committerHans Goudey <h.goudey@me.com>2021-10-25 18:01:07 +0300
commit972677b25e1d84e4c02d0e55b12ce87661faff5e (patch)
tree8d60d0d8da8aa5daa6dd8d719eca4b84f680263f /release/scripts/startup/bl_operators
parenta84f1c02d251a9ce6267030a46e02ed2d3ce22e1 (diff)
UI: Improve layout of custom property edit panel
This patch makes the layout of the custom property panel more coherent with the rest of the property editor interface, makes it less busy, allows more space for the buttons for the actual properties, and simplifies editing values of unsupported property types or long arrays. - Remove the box around each property. - Use an non-embossed X icon for deleting. - Use an "edit" icon instead of the text for the meta-data edit operator. The "gear" icon used for editing isn't ideal here. - Increase the max array length for drawing the values directly to 8. - Add an "Edit Property Value" operator for dictionaries or longer arrays. - Replace the "Library Override" text with an icon. - Use a proper split factor, the same as the rest of the UI. Differential Revision: https://developer.blender.org/D12805
Diffstat (limited to 'release/scripts/startup/bl_operators')
-rw-r--r--release/scripts/startup/bl_operators/wm.py74
1 files changed, 66 insertions, 8 deletions
diff --git a/release/scripts/startup/bl_operators/wm.py b/release/scripts/startup/bl_operators/wm.py
index 170b9f3ae44..4dbdc6e633e 100644
--- a/release/scripts/startup/bl_operators/wm.py
+++ b/release/scripts/startup/bl_operators/wm.py
@@ -1442,7 +1442,7 @@ class WM_OT_properties_edit(Operator):
# Convert an old property for a string, avoiding unhelpful string representations for custom list types.
@staticmethod
- def _convert_old_property_to_string(item, name):
+ def convert_custom_property_to_string(item, name):
# The IDProperty group view API currently doesn't have a "lookup" method.
for key, value in item.items():
if key == name:
@@ -1461,7 +1461,8 @@ class WM_OT_properties_edit(Operator):
# Retrieve the current type of the custom property on the RNA struct. Some properties like group properties
# can be created in the UI, but editing their meta-data isn't supported. In that case, return 'PYTHON'.
- def _get_property_type(self, item, property_name):
+ @staticmethod
+ def get_property_type(item, property_name):
from rna_prop_ui import (
rna_idprop_value_item_type,
)
@@ -1549,17 +1550,17 @@ class WM_OT_properties_edit(Operator):
return self._convert_new_value_single(item[name_old], float)
if prop_type_new == 'INT_ARRAY':
- prop_type_old = self._get_property_type(item, name_old)
+ prop_type_old = self.get_property_type(item, name_old)
if prop_type_old in {'INT', 'FLOAT', 'INT_ARRAY', 'FLOAT_ARRAY'}:
return self._convert_new_value_array(item[name_old], int, self.array_length)
if prop_type_new == 'FLOAT_ARRAY':
- prop_type_old = self._get_property_type(item, name_old)
+ prop_type_old = self.get_property_type(item, name_old)
if prop_type_old in {'INT', 'FLOAT', 'FLOAT_ARRAY', 'INT_ARRAY'}:
return self._convert_new_value_array(item[name_old], float, self.array_length)
if prop_type_new == 'STRING':
- return self._convert_old_property_to_string(item, name_old)
+ return self.convert_custom_property_to_string(item, name_old)
# If all else fails, create an empty string property. That should avoid errors later on anyway.
return ""
@@ -1672,7 +1673,7 @@ class WM_OT_properties_edit(Operator):
self.report({'ERROR'}, "Cannot edit properties from override data")
return {'CANCELLED'}
- prop_type_old = self._get_property_type(item, name_old)
+ prop_type_old = self.get_property_type(item, name_old)
prop_type_new = self.property_type
self._old_prop_name[:] = [name]
@@ -1716,14 +1717,14 @@ class WM_OT_properties_edit(Operator):
return {'CANCELLED'}
# Set operator's property type with the type of the existing property, to display the right settings.
- old_type = self._get_property_type(item, name)
+ old_type = self.get_property_type(item, name)
self.property_type = old_type
self.last_property_type = old_type
# So that the operator can do something for unsupported properties, change the property into
# a string, just for editing in the dialog. When the operator executes, it will be converted back
# into a python value. Always do this conversion, in case the Python property edit type is selected.
- self.eval_string = self._convert_old_property_to_string(item, name)
+ self.eval_string = self.convert_custom_property_to_string(item, name)
if old_type != 'PYTHON':
self._fill_old_ui_data(item, name)
@@ -1845,6 +1846,62 @@ class WM_OT_properties_edit(Operator):
layout.prop(self, "description")
+# Edit the value of a custom property with the given name on the RNA struct at the given data path.
+# For supported types, this simply acts as a convenient way to create a popup for a specific property
+# and draws the custom property value directly in the popup. For types like groups which can't be edited
+# directly with buttons, instead convert the value to a string, evaluate the changed string when executing.
+class WM_OT_properties_edit_value(Operator):
+ """Edit the value of a custom property"""
+ bl_idname = "wm.properties_edit_value"
+ bl_label = "Edit Property Value"
+ # register only because invoke_props_popup requires.
+ bl_options = {'REGISTER', 'INTERNAL'}
+
+ data_path: rna_path
+ property_name: rna_custom_property_name
+
+ # Store the value converted to a string as a fallback for otherwise unsupported types.
+ eval_string: StringProperty(
+ name="Value",
+ description="Value for custom property types that can only be edited as a Python expression"
+ )
+
+ def execute(self, context):
+ if self.eval_string:
+ rna_item = eval("context.%s" % self.data_path)
+ try:
+ new_value = eval(self.eval_string)
+ except Exception as ex:
+ self.report({'WARNING'}, "Python evaluation failed: " + str(ex))
+ return {'CANCELLED'}
+ rna_item[self.property_name] = new_value
+ return {'FINISHED'}
+
+ def invoke(self, context, _event):
+ rna_item = eval("context.%s" % self.data_path)
+
+ if WM_OT_properties_edit.get_property_type(rna_item, self.property_name) == 'PYTHON':
+ self.eval_string = WM_OT_properties_edit.convert_custom_property_to_string(rna_item,
+ self.property_name)
+ else:
+ self.eval_string = ""
+
+ wm = context.window_manager
+ return wm.invoke_props_dialog(self)
+
+ def draw(self, context):
+ from bpy.utils import escape_identifier
+
+ rna_item = eval("context.%s" % self.data_path)
+
+ layout = self.layout
+ if WM_OT_properties_edit.get_property_type(rna_item, self.property_name) == 'PYTHON':
+ layout.prop(self, "eval_string")
+ else:
+ col = layout.column(align=True)
+ col.prop(rna_item, '["%s"]' % escape_identifier(self.property_name), text="")
+
+
class WM_OT_properties_add(Operator):
"""Add your own property to the data-block"""
bl_idname = "wm.properties_add"
@@ -3056,6 +3113,7 @@ classes = (
WM_OT_properties_add,
WM_OT_properties_context_change,
WM_OT_properties_edit,
+ WM_OT_properties_edit_value,
WM_OT_properties_remove,
WM_OT_sysinfo,
WM_OT_owner_disable,