Changeset View
Changeset View
Standalone View
Standalone View
release/scripts/startup/bl_operators/wm.py
| Show First 20 Lines • Show All 2,477 Lines • ▼ Show 20 Lines | case_method: EnumProperty( | ||||
| items=( | items=( | ||||
| ('UPPER', "Upper Case", ""), | ('UPPER', "Upper Case", ""), | ||||
| ('LOWER', "Lower Case", ""), | ('LOWER', "Lower Case", ""), | ||||
| ('TITLE', "Title Case", ""), | ('TITLE', "Title Case", ""), | ||||
| ), | ), | ||||
| ) | ) | ||||
| # Weak, add/remove as properties. | # Weak, add/remove as properties. | ||||
| op_add: BoolProperty() | op_add: BoolProperty(name="Add") | ||||
| op_remove: BoolProperty() | op_remove: BoolProperty(name="Remove") | ||||
| class WM_OT_batch_rename(Operator): | class WM_OT_batch_rename(Operator): | ||||
| bl_idname = "wm.batch_rename" | bl_idname = "wm.batch_rename" | ||||
| bl_label = "Batch Rename" | bl_label = "Batch Rename" | ||||
| bl_description = "Rename multiple items at once" | bl_description = "Rename multiple items at once" | ||||
| bl_options = {'UNDO'} | bl_options = {'UNDO'} | ||||
| ▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | def _data_from_context(cls, context, data_type, only_selected, *, check_context=False): | ||||
| if check_context: | if check_context: | ||||
| return data_type_test | return data_type_test | ||||
| if data_type == data_type_test: | if data_type == data_type_test: | ||||
| data = ( | data = ( | ||||
| context.selected_sequences | context.selected_sequences | ||||
| if only_selected else | if only_selected else | ||||
| scene.sequence_editor.sequences_all, | scene.sequence_editor.sequences_all, | ||||
| "name", | "name", | ||||
| "Strip(s)", | iface_("Strip(s)"), | ||||
| ) | ) | ||||
| elif space_type == 'NODE_EDITOR': | elif space_type == 'NODE_EDITOR': | ||||
| data_type_test = 'NODE' | data_type_test = 'NODE' | ||||
| if check_context: | if check_context: | ||||
| return data_type_test | return data_type_test | ||||
| if data_type == data_type_test: | if data_type == data_type_test: | ||||
| data = ( | data = ( | ||||
| context.selected_nodes | context.selected_nodes | ||||
| if only_selected else | if only_selected else | ||||
| list(space.node_tree.nodes), | list(space.node_tree.nodes), | ||||
| "name", | "name", | ||||
| "Node(s)", | iface_("Node(s)"), | ||||
| ) | ) | ||||
| elif space_type == 'OUTLINER': | elif space_type == 'OUTLINER': | ||||
| data_type_test = 'COLLECTION' | data_type_test = 'COLLECTION' | ||||
| if check_context: | if check_context: | ||||
| return data_type_test | return data_type_test | ||||
| if data_type == data_type_test: | if data_type == data_type_test: | ||||
| data = ( | data = ( | ||||
| cls._selected_ids_from_outliner_by_type(context, bpy.types.Collection) | cls._selected_ids_from_outliner_by_type(context, bpy.types.Collection) | ||||
| if only_selected else | if only_selected else | ||||
| scene.collection.children_recursive, | scene.collection.children_recursive, | ||||
| "name", | "name", | ||||
| "Collection(s)", | iface_("Collection(s)"), | ||||
| ) | ) | ||||
| else: | else: | ||||
| if mode == 'POSE' or (mode == 'WEIGHT_PAINT' and context.pose_object): | if mode == 'POSE' or (mode == 'WEIGHT_PAINT' and context.pose_object): | ||||
| data_type_test = 'BONE' | data_type_test = 'BONE' | ||||
| if check_context: | if check_context: | ||||
| return data_type_test | return data_type_test | ||||
| if data_type == data_type_test: | if data_type == data_type_test: | ||||
| data = ( | data = ( | ||||
| [pchan.bone for pchan in context.selected_pose_bones] | [pchan.bone for pchan in context.selected_pose_bones] | ||||
| if only_selected else | if only_selected else | ||||
| [pbone.bone for ob in context.objects_in_mode_unique_data for pbone in ob.pose.bones], | [pbone.bone for ob in context.objects_in_mode_unique_data for pbone in ob.pose.bones], | ||||
| "name", | "name", | ||||
| "Bone(s)", | iface_("Bone(s)"), | ||||
| ) | ) | ||||
| elif mode == 'EDIT_ARMATURE': | elif mode == 'EDIT_ARMATURE': | ||||
| data_type_test = 'BONE' | data_type_test = 'BONE' | ||||
| if check_context: | if check_context: | ||||
| return data_type_test | return data_type_test | ||||
| if data_type == data_type_test: | if data_type == data_type_test: | ||||
| data = ( | data = ( | ||||
| context.selected_editable_bones | context.selected_editable_bones | ||||
| if only_selected else | if only_selected else | ||||
| [ebone for ob in context.objects_in_mode_unique_data for ebone in ob.data.edit_bones], | [ebone for ob in context.objects_in_mode_unique_data for ebone in ob.data.edit_bones], | ||||
| "name", | "name", | ||||
| "Edit Bone(s)", | iface_("Edit Bone(s)"), | ||||
| ) | ) | ||||
| if check_context: | if check_context: | ||||
| return 'OBJECT' | return 'OBJECT' | ||||
| object_data_type_attrs_map = { | object_data_type_attrs_map = { | ||||
| 'MESH': ("meshes", "Mesh(es)", bpy.types.Mesh), | 'MESH': ("meshes", iface_("Mesh(es)"), bpy.types.Mesh), | ||||
| 'CURVE': ("curves", "Curve(s)", bpy.types.Curve), | 'CURVE': ("curves", iface_("Curve(s)"), bpy.types.Curve), | ||||
| 'META': ("metaballs", "Metaball(s)", bpy.types.MetaBall), | 'META': ("metaballs", iface_("Metaball(s)"), bpy.types.MetaBall), | ||||
| 'VOLUME': ("volumes", "Volume(s)", bpy.types.Volume), | 'VOLUME': ("volumes", iface_("Volume(s)"), bpy.types.Volume), | ||||
| 'GPENCIL': ("grease_pencils", "Grease Pencil(s)", bpy.types.GreasePencil), | 'GPENCIL': ("grease_pencils", iface_("Grease Pencil(s)"), bpy.types.GreasePencil), | ||||
| 'ARMATURE': ("armatures", "Armature(s)", bpy.types.Armature), | 'ARMATURE': ("armatures", iface_("Armature(s)"), bpy.types.Armature), | ||||
| 'LATTICE': ("lattices", "Lattice(s)", bpy.types.Lattice), | 'LATTICE': ("lattices", iface_("Lattice(s)"), bpy.types.Lattice), | ||||
| 'LIGHT': ("lights", "Light(s)", bpy.types.Light), | 'LIGHT': ("lights", iface_("Light(s)"), bpy.types.Light), | ||||
| 'LIGHT_PROBE': ("light_probes", "Light Probe(s)", bpy.types.LightProbe), | 'LIGHT_PROBE': ("light_probes", iface_("Light Probe(s)"), bpy.types.LightProbe), | ||||
| 'CAMERA': ("cameras", "Camera(s)", bpy.types.Camera), | 'CAMERA': ("cameras", iface_("Camera(s)"), bpy.types.Camera), | ||||
| 'SPEAKER': ("speakers", "Speaker(s)", bpy.types.Speaker), | 'SPEAKER': ("speakers", iface_("Speaker(s)"), bpy.types.Speaker), | ||||
| } | } | ||||
| # Finish with space types. | # Finish with space types. | ||||
| if data is None: | if data is None: | ||||
| if data_type == 'OBJECT': | if data_type == 'OBJECT': | ||||
| data = ( | data = ( | ||||
| ( | ( | ||||
| # Outliner. | # Outliner. | ||||
| cls._selected_ids_from_outliner_by_type(context, bpy.types.Object) | cls._selected_ids_from_outliner_by_type(context, bpy.types.Object) | ||||
| if space_type == 'OUTLINER' else | if space_type == 'OUTLINER' else | ||||
| # 3D View (default). | # 3D View (default). | ||||
| context.selected_editable_objects | context.selected_editable_objects | ||||
| ) | ) | ||||
| if only_selected else | if only_selected else | ||||
| [id for id in bpy.data.objects if id.library is None], | [id for id in bpy.data.objects if id.library is None], | ||||
| "name", | "name", | ||||
| "Object(s)", | iface_("Object(s)"), | ||||
| ) | ) | ||||
| elif data_type == 'COLLECTION': | elif data_type == 'COLLECTION': | ||||
| data = ( | data = ( | ||||
| # Outliner case is handled already. | # Outliner case is handled already. | ||||
| tuple(set( | tuple(set( | ||||
| ob.instance_collection | ob.instance_collection | ||||
| for ob in context.selected_objects | for ob in context.selected_objects | ||||
| if ((ob.instance_type == 'COLLECTION') and | if ((ob.instance_type == 'COLLECTION') and | ||||
| (collection := ob.instance_collection) is not None and | (collection := ob.instance_collection) is not None and | ||||
| (collection.library is None)) | (collection.library is None)) | ||||
| )) | )) | ||||
| if only_selected else | if only_selected else | ||||
| [id for id in bpy.data.collections if id.library is None], | [id for id in bpy.data.collections if id.library is None], | ||||
| "name", | "name", | ||||
| "Collection(s)", | iface_("Collection(s)"), | ||||
| ) | ) | ||||
| elif data_type == 'MATERIAL': | elif data_type == 'MATERIAL': | ||||
| data = ( | data = ( | ||||
| ( | ( | ||||
| # Outliner. | # Outliner. | ||||
| cls._selected_ids_from_outliner_by_type(context, bpy.types.Material) | cls._selected_ids_from_outliner_by_type(context, bpy.types.Material) | ||||
| if space_type == 'OUTLINER' else | if space_type == 'OUTLINER' else | ||||
| # 3D View (default). | # 3D View (default). | ||||
| tuple(set( | tuple(set( | ||||
| id | id | ||||
| for ob in context.selected_objects | for ob in context.selected_objects | ||||
| for slot in ob.material_slots | for slot in ob.material_slots | ||||
| if (id := slot.material) is not None and id.library is None | if (id := slot.material) is not None and id.library is None | ||||
| )) | )) | ||||
| ) | ) | ||||
| if only_selected else | if only_selected else | ||||
| [id for id in bpy.data.materials if id.library is None], | [id for id in bpy.data.materials if id.library is None], | ||||
| "name", | "name", | ||||
| "Material(s)", | iface_("Material(s)"), | ||||
| ) | ) | ||||
| elif data_type in object_data_type_attrs_map.keys(): | elif data_type in object_data_type_attrs_map.keys(): | ||||
| attr, descr, ty = object_data_type_attrs_map[data_type] | attr, descr, ty = object_data_type_attrs_map[data_type] | ||||
| data = ( | data = ( | ||||
| ( | ( | ||||
| # Outliner. | # Outliner. | ||||
| cls._selected_ids_from_outliner_by_type_for_object_data(context, ty) | cls._selected_ids_from_outliner_by_type_for_object_data(context, ty) | ||||
| if space_type == 'OUTLINER' else | if space_type == 'OUTLINER' else | ||||
| ▲ Show 20 Lines • Show All 208 Lines • ▼ Show 20 Lines | def draw(self, context): | ||||
| row.label(text="Convert To") | row.label(text="Convert To") | ||||
| row.row().prop(action, "case_method", expand=True) | row.row().prop(action, "case_method", expand=True) | ||||
| # Column 2: add-remove. | # Column 2: add-remove. | ||||
| row = split.split(align=True) | row = split.split(align=True) | ||||
| row.prop(action, "op_remove", text="", icon='REMOVE') | row.prop(action, "op_remove", text="", icon='REMOVE') | ||||
| row.prop(action, "op_add", text="", icon='ADD') | row.prop(action, "op_add", text="", icon='ADD') | ||||
| layout.label(text="Rename %d %s" % (len(self._data[0]), self._data[2])) | layout.label(text=iface_("Rename %d %s") % (len(self._data[0]), self._data[2])) | ||||
mont29: Either you call `iface_` here, then you only need `n_` in all the entries above defining those… | |||||
| def check(self, context): | def check(self, context): | ||||
| changed = False | changed = False | ||||
| for i, action in enumerate(self.actions): | for i, action in enumerate(self.actions): | ||||
| if action.op_add: | if action.op_add: | ||||
| action.op_add = False | action.op_add = False | ||||
| self.actions.add() | self.actions.add() | ||||
| if i + 2 != len(self.actions): | if i + 2 != len(self.actions): | ||||
| ▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | def execute(self, context): | ||||
| for item in seq: | for item in seq: | ||||
| name_src = getattr(item, attr) | name_src = getattr(item, attr) | ||||
| name_dst = self._apply_actions(actions, name_src) | name_dst = self._apply_actions(actions, name_src) | ||||
| if name_src != name_dst: | if name_src != name_dst: | ||||
| setattr(item, attr, name_dst) | setattr(item, attr, name_dst) | ||||
| change_len += 1 | change_len += 1 | ||||
| total_len += 1 | total_len += 1 | ||||
| self.report({'INFO'}, "Renamed %d of %d %s" % (change_len, total_len, descr)) | self.report({'INFO'}, tip_("Renamed %d of %d %s") % (change_len, total_len, descr)) | ||||
Done Inline Actionsshould be tip_, this more an info message than a label. mont29: should be `tip_`, this more an info message than a label. | |||||
| return {'FINISHED'} | return {'FINISHED'} | ||||
| def invoke(self, context, event): | def invoke(self, context, event): | ||||
| self._data_update(context) | self._data_update(context) | ||||
| if not self.actions: | if not self.actions: | ||||
| ▲ Show 20 Lines • Show All 237 Lines • Show Last 20 Lines | |||||
Either you call iface_ here, then you only need n_ in all the entries above defining those strings, or you do not need to call iface_ here at all?