Changeset View
Changeset View
Standalone View
Standalone View
release/scripts/startup/bl_operators/wm.py
| Show First 20 Lines • Show All 1,361 Lines • ▼ Show 20 Lines | def _cmp_props_get(self): | ||||
| # Changing these properties will refresh the UI | # Changing these properties will refresh the UI | ||||
| return { | return { | ||||
| "use_soft_limits": self.use_soft_limits, | "use_soft_limits": self.use_soft_limits, | ||||
| "soft_range": (self.soft_min, self.soft_max), | "soft_range": (self.soft_min, self.soft_max), | ||||
| "hard_range": (self.min, self.max), | "hard_range": (self.min, self.max), | ||||
| } | } | ||||
| def get_value_eval(self): | def get_value_eval(self): | ||||
| failed = False | |||||
| try: | try: | ||||
| value_eval = eval(self.value) | value_eval = eval(self.value) | ||||
| # assert else None -> None, not "None", see T33431. | # assert else None -> None, not "None", see T33431. | ||||
| assert(type(value_eval) in {str, float, int, bool, tuple, list}) | assert(type(value_eval) in {str, float, int, bool, tuple, list}) | ||||
| except: | except: | ||||
| failed = True | |||||
| value_eval = self.value | value_eval = self.value | ||||
| return value_eval | return value_eval, failed | ||||
| def get_default_eval(self): | def get_default_eval(self): | ||||
| failed = False | |||||
| try: | try: | ||||
| default_eval = eval(self.default) | default_eval = eval(self.default) | ||||
| # assert else None -> None, not "None", see T33431. | # assert else None -> None, not "None", see T33431. | ||||
| assert(type(default_eval) in {str, float, int, bool, tuple, list}) | assert(type(default_eval) in {str, float, int, bool, tuple, list}) | ||||
| except: | except: | ||||
| failed = True | |||||
| default_eval = self.default | default_eval = self.default | ||||
| return default_eval | return default_eval, failed | ||||
| def execute(self, context): | def execute(self, context): | ||||
| from rna_prop_ui import ( | from rna_prop_ui import ( | ||||
| rna_idprop_ui_prop_clear, | |||||
| rna_idprop_ui_prop_update, | rna_idprop_ui_prop_update, | ||||
| rna_idprop_value_item_type, | rna_idprop_value_item_type, | ||||
| ) | ) | ||||
| data_path = self.data_path | data_path = self.data_path | ||||
| prop = self.property | prop = self.property | ||||
| prop_escape = bpy.utils.escape_identifier(prop) | prop_escape = bpy.utils.escape_identifier(prop) | ||||
| prop_old = getattr(self, "_last_prop", [None])[0] | prop_old = getattr(self, "_last_prop", [None])[0] | ||||
| if prop_old is None: | if prop_old is None: | ||||
| self.report({'ERROR'}, "Direct execution not supported") | self.report({'ERROR'}, "Direct execution not supported") | ||||
| return {'CANCELLED'} | return {'CANCELLED'} | ||||
| value_eval = self.get_value_eval() | value_eval, value_failed = self.get_value_eval() | ||||
| default_eval = self.get_default_eval() | default_eval, default_failed = self.get_default_eval() | ||||
| # First remove | # First remove | ||||
| item = eval("context.%s" % data_path) | item = eval("context.%s" % data_path) | ||||
| if (item.id_data and item.id_data.override_library and item.id_data.override_library.reference): | if (item.id_data and item.id_data.override_library and item.id_data.override_library.reference): | ||||
| self.report({'ERROR'}, "Cannot edit properties from override data") | self.report({'ERROR'}, "Cannot edit properties from override data") | ||||
| return {'CANCELLED'} | return {'CANCELLED'} | ||||
| prop_type_old = type(item[prop_old]) | prop_type_old = type(item[prop_old]) | ||||
| rna_idprop_ui_prop_clear(item, prop_old) | |||||
| del item[prop_old] | del item[prop_old] | ||||
campbellbarton: Not sure why clearing the UI property is no longer done, it seems that deleting the property… | |||||
| # Reassign | # Reassign | ||||
| item[prop] = value_eval | item[prop] = value_eval | ||||
| item.property_overridable_library_set('["%s"]' % prop_escape, self.is_overridable_library) | item.property_overridable_library_set('["%s"]' % prop_escape, self.is_overridable_library) | ||||
| rna_idprop_ui_prop_update(item, prop) | rna_idprop_ui_prop_update(item, prop) | ||||
| self._last_prop[:] = [prop] | self._last_prop[:] = [prop] | ||||
| Show All 26 Lines | def execute(self, context): | ||||
| min=self.min, | min=self.min, | ||||
| max=self.max, | max=self.max, | ||||
| soft_min=self.soft_min, | soft_min=self.soft_min, | ||||
| soft_max=self.soft_max, | soft_max=self.soft_max, | ||||
| default=default_eval, | default=default_eval, | ||||
| subtype=self.subtype, | subtype=self.subtype, | ||||
| description=self.description | description=self.description | ||||
| ) | ) | ||||
| elif prop_type == str and not is_array: # String arrays do not support UI data. | elif prop_type == str and not is_array and not default_failed: # String arrays do not support UI data. | ||||
| ui_data = item.id_properties_ui(prop) | ui_data = item.id_properties_ui(prop) | ||||
| ui_data.update( | ui_data.update( | ||||
| default=self.default, | default=self.default, | ||||
| subtype=self.subtype, | subtype=self.subtype, | ||||
| description=self.description | description=self.description | ||||
| ) | ) | ||||
| # If we have changed the type of the property, update its potential anim curves! | # If we have changed the type of the property, update its potential anim curves! | ||||
| ▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | def invoke(self, context, _event): | ||||
| self.report({'ERROR'}, "Cannot edit properties from override data") | self.report({'ERROR'}, "Cannot edit properties from override data") | ||||
| return {'CANCELLED'} | return {'CANCELLED'} | ||||
| # retrieve overridable static | # retrieve overridable static | ||||
| is_overridable = item.is_property_overridable_library('["%s"]' % prop_escape) | is_overridable = item.is_property_overridable_library('["%s"]' % prop_escape) | ||||
| self.is_overridable_library = bool(is_overridable) | self.is_overridable_library = bool(is_overridable) | ||||
| # default default value | # default default value | ||||
| prop_type, is_array = rna_idprop_value_item_type(self.get_value_eval()) | value, value_failed = self.get_value_eval() | ||||
| prop_type, is_array = rna_idprop_value_item_type(value) | |||||
| if prop_type in {int, float}: | if prop_type in {int, float}: | ||||
| self.default = str(prop_type(0)) | self.default = str(prop_type(0)) | ||||
| else: | else: | ||||
| self.default = "" | self.default = "" | ||||
| # setup defaults | # setup defaults | ||||
| if prop_type in {int, float}: | if prop_type in {int, float}: | ||||
| ui_data = item.id_properties_ui(prop) | ui_data = item.id_properties_ui(prop) | ||||
| rna_data = ui_data.as_dict() | rna_data = ui_data.as_dict() | ||||
| self.subtype = rna_data["subtype"] | self.subtype = rna_data["subtype"] | ||||
| self.min = rna_data["min"] | self.min = rna_data["min"] | ||||
| self.max = rna_data["max"] | self.max = rna_data["max"] | ||||
| self.soft_min = rna_data["soft_min"] | self.soft_min = rna_data["soft_min"] | ||||
| self.soft_max = rna_data["soft_max"] | self.soft_max = rna_data["soft_max"] | ||||
| self.use_soft_limits = ( | self.use_soft_limits = ( | ||||
| self.min != self.soft_min or | self.min != self.soft_min or | ||||
| self.max != self.soft_max | self.max != self.soft_max | ||||
| ) | ) | ||||
| self.default = str(rna_data["default"]) | self.default = str(rna_data["default"]) | ||||
| if prop_type == str and not is_array: # String arrays do not support UI data. | if prop_type == str and not is_array and not value_failed: # String arrays do not support UI data. | ||||
| ui_data = item.id_properties_ui(prop) | ui_data = item.id_properties_ui(prop) | ||||
| rna_data = ui_data.as_dict() | rna_data = ui_data.as_dict() | ||||
| self.subtype = rna_data["subtype"] | self.subtype = rna_data["subtype"] | ||||
| self.default = str(rna_data["default"]) | self.default = str(rna_data["default"]) | ||||
| self._init_subtype(prop_type, is_array, self.subtype) | self._init_subtype(prop_type, is_array, self.subtype) | ||||
| # store for comparison | # store for comparison | ||||
| ▲ Show 20 Lines • Show All 1,297 Lines • Show Last 20 Lines | |||||
Not sure why clearing the UI property is no longer done, it seems that deleting the property should be paired with removing the UI property.
Since it's not obvious why the UI property is kept, this deserves a comment explaining why the property can be deleted and not the ui-property-data.