Changeset View
Changeset View
Standalone View
Standalone View
release/scripts/startup/bl_operators/wm.py
| Show All 17 Lines | |||||
| # <pep8 compliant> | # <pep8 compliant> | ||||
| from __future__ import annotations | from __future__ import annotations | ||||
| import bpy | import bpy | ||||
| from bpy.types import ( | from bpy.types import ( | ||||
| Menu, | Menu, | ||||
| Operator, | Operator, | ||||
| Collection, | |||||
| bpy_prop_array, | bpy_prop_array, | ||||
| ) | ) | ||||
| from bpy.props import ( | from bpy.props import ( | ||||
| BoolProperty, | BoolProperty, | ||||
| CollectionProperty, | CollectionProperty, | ||||
| EnumProperty, | EnumProperty, | ||||
| FloatProperty, | FloatProperty, | ||||
| IntProperty, | IntProperty, | ||||
| ▲ Show 20 Lines • Show All 2,428 Lines • ▼ Show 20 Lines | class WM_OT_batch_rename(Operator): | ||||
| bl_description = "Rename multiple items at once" | bl_description = "Rename multiple items at once" | ||||
| bl_options = {'UNDO'} | bl_options = {'UNDO'} | ||||
| data_type: EnumProperty( | data_type: EnumProperty( | ||||
| name="Type", | name="Type", | ||||
| items=( | items=( | ||||
| ('OBJECT', "Objects", ""), | ('OBJECT', "Objects", ""), | ||||
| ('COLLECTION', "Collections", ""), | |||||
| ('MATERIAL', "Materials", ""), | ('MATERIAL', "Materials", ""), | ||||
| None, | None, | ||||
| # Enum identifiers are compared with 'object.type'. | # Enum identifiers are compared with 'object.type'. | ||||
| ('MESH', "Meshes", ""), | ('MESH', "Meshes", ""), | ||||
| ('CURVE', "Curves", ""), | ('CURVE', "Curves", ""), | ||||
| ('META', "Metaballs", ""), | ('META', "Metaballs", ""), | ||||
| ('ARMATURE', "Armatures", ""), | ('ARMATURE', "Armatures", ""), | ||||
| ('LATTICE', "Lattices", ""), | ('LATTICE', "Lattices", ""), | ||||
| ▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | def _data_from_context(context, data_type, only_selected, *, check_context=False): | ||||
| 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)", | "Node(s)", | ||||
| ) | ) | ||||
| elif space_type == 'OUTLINER': | |||||
| data_type_test = 'COLLECTION' | |||||
| if check_context: | |||||
| return data_type_test | |||||
| if data_type == data_type_test: | |||||
| data = ( | |||||
| [id for id in context.selected_ids if isinstance(id, Collection)] | |||||
campbellbarton: Missed this last review:
Regarding: `id.rna_type.identifier == 'Collection'` - Accessing… | |||||
| if only_selected else | |||||
| scene.collection.children_recursive, | |||||
| "name", | |||||
| "Collection(s)", | |||||
| ) | |||||
| else: | else: | ||||
Done Inline ActionsCommitted children_recursive rB7c568e7d36710aba782a628dfff3b8bcea88be3b so this function doesn't need to be included in-line. campbellbarton: Committed `children_recursive` rB7c568e7d36710aba782a628dfff3b8bcea88be3b so this function… | |||||
| 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' | ||||
Done Inline ActionsExtra space. campbellbarton: Extra space. | |||||
| if check_context: | if check_context: | ||||
| return data_type_test | return data_type_test | ||||
Done Inline ActionsUse list comprehensions (following the convention of other functions here). campbellbarton: Use list comprehensions (following the convention of other functions here).
| |||||
| 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)", | "Bone(s)", | ||||
| ) | ) | ||||
| ▲ Show 20 Lines • Show All 594 Lines • Show Last 20 Lines | |||||
Missed this last review:
Regarding: id.rna_type.identifier == 'Collection' - Accessing rna_type is needed in some rare cases, in general though isinstance() should be used (or compare it's type if an exact check is what's intended).
eg: