diff --git a/scripts/startup/bl_operators/node.py b/scripts/startup/bl_operators/node.py index c07591c087d..1b3fa323dc3 100644 --- a/scripts/startup/bl_operators/node.py +++ b/scripts/startup/bl_operators/node.py @@ -42,8 +42,8 @@ switch_nodes = { } -# A context manager for temporarily unparenting nodes from their frames -# This gets rid of issues with framed nodes using relative coordinates +# A context manager for temporarily un-parenting nodes from their frames. +# This gets rid of issues with framed nodes using relative coordinates. class temporary_unframe: def __init__(self, nodes): self.parent_dict = {} @@ -100,7 +100,7 @@ def cast_value(source, target): ('RGBA', 'VECTOR'): lambda color: color[:len(target.default_value)], ('VECTOR', 'VALUE'): vector_to_float, ('VECTOR', 'INT'): lambda vector: int(vector_to_float(vector)), - # Even negative vectors get implicitly converted to True, hence to_bool is not used + # Even negative vectors get implicitly converted to True, hence `to_bool` is not used. ('VECTOR', 'BOOLEAN'): lambda vector: bool(vector_to_float(vector)), ('VECTOR', 'RGBA'): lambda vector: list(vector).extend([0.0] * (len(target.default_value) - len(vector))) } @@ -193,7 +193,7 @@ class NodeOperator: {'ERROR_INVALID_INPUT'}, rpt_("Node has no attribute {:s}").format(setting.name)) print(str(ex)) - # Continue despite invalid attribute + # Continue despite invalid attribute. return node @@ -210,7 +210,7 @@ class NodeAddOperator(NodeOperator): space = context.space_data tree = space.edit_tree - # convert mouse position to the View2D for later node placement + # Convert mouse position to the View2D for later node placement. if context.region.type == 'WINDOW': area = context.area horizontal_pad = int(area.width / 10) @@ -218,7 +218,7 @@ class NodeAddOperator(NodeOperator): inspace_x = min(max(horizontal_pad, event.mouse_region_x), area.width - horizontal_pad) inspace_y = min(max(vertical_pad, event.mouse_region_y), area.height - vertical_pad) - # convert mouse position to the View2D for later node placement + # Convert mouse position to the View2D for later node placement. space.cursor_location_from_region(inspace_x, inspace_y) else: space.cursor_location = tree.view_center @@ -226,18 +226,18 @@ class NodeAddOperator(NodeOperator): @classmethod def poll(cls, context): space = context.space_data - # needs active node editor and a tree to add nodes to + # Needs active node editor and a tree to add nodes to. return (space and (space.type == 'NODE_EDITOR') and space.edit_tree and space.edit_tree.is_editable) # Default invoke stores the mouse position to place the node correctly - # and optionally invokes the transform operator + # and optionally invokes the transform operator. def invoke(self, context, event): self.store_mouse_cursor(context, event) result = self.execute(context) if self.use_transform and ('FINISHED' in result): - # removes the node again if transform is canceled + # Removes the node again if transform is canceled. bpy.ops.node.translate_attach_remove_on_cancel('INVOKE_DEFAULT') return result @@ -391,8 +391,8 @@ class NodeSwapOperator(NodeOperator): if new_node.bl_idname == "GeometryNodeMenuSwitch": for i, old_item in enumerate(old_switch_items[:]): - # Change the menu item names to numerical indices - # This makes it so that later functions that match by socket name work on the switches + # Change the menu item names to numerical indices. + # This makes it so that later functions that match by socket name work on the switches. if hasattr(old_item, "name"): old_item.name = str(i) @@ -403,8 +403,8 @@ class NodeSwapOperator(NodeOperator): elif new_node.bl_idname == "GeometryNodeIndexSwitch": for i, old_item in enumerate(old_switch_items[:]): - # Change the menu item names to numerical indices - # This makes it so that later functions that match by socket name work on the switches + # Change the menu item names to numerical indices. + # This makes it so that later functions that match by socket name work on the switches. if hasattr(old_item, "name"): old_item.name = str(i) @@ -466,11 +466,11 @@ class NODE_OT_swap_node(NodeSwapOperator, Operator): @staticmethod def get_zone_pair(tree, node): - # Get paired output node + # Get paired output node. if hasattr(node, "paired_output"): return node, node.paired_output - # Get paired input node + # Get paired input node. for input_node in tree.nodes: if hasattr(input_node, "paired_output"): if input_node.paired_output == node: @@ -539,8 +539,8 @@ class NODE_OT_add_empty_group(NodeAddOperator, bpy.types.Operator): bl_description = "Add a group node with an empty group" bl_options = {'REGISTER', 'UNDO'} - # Override inherited method from NodeOperator - # Return None so that bl_description is used + # Override inherited method from NodeOperator. + # Return None so that bl_description is used. @classmethod def description(cls, _context, properties): ... @@ -575,8 +575,8 @@ class NODE_OT_swap_empty_group(NodeSwapOperator, bpy.types.Operator): bl_description = "Replace active node with an empty group" bl_options = {'REGISTER', 'UNDO'} - # Override inherited method from NodeOperator - # Return None so that bl_description is used + # Override inherited method from NodeOperator. + # Return None so that bl_description is used. @classmethod def description(cls, _context, properties): ... @@ -634,7 +634,7 @@ class ZoneOperator: def description(cls, _context, properties): input_node_type = getattr(properties, "input_node_type", None) - # For Add Zone operators, use class variable instead of operator property + # For Add Zone operators, use class variable instead of operator property. if input_node_type is None: input_node_type = cls.input_node_type @@ -719,11 +719,11 @@ class NODE_OT_swap_zone(ZoneOperator, NodeSwapOperator, Operator): @staticmethod def get_zone_pair(tree, node): - # Get paired output node + # Get paired output node. if hasattr(node, "paired_output"): return node, node.paired_output - # Get paired input node + # Get paired input node. for input_node in tree.nodes: if hasattr(input_node, "paired_output"): if input_node.paired_output == node: @@ -864,7 +864,7 @@ class NODE_OT_collapse_hide_unused_toggle(Operator): @classmethod def poll(cls, context): space = context.space_data - # needs active node editor and a tree + # Needs active node editor and a tree. return (space and (space.type == 'NODE_EDITOR') and (space.edit_tree and space.edit_tree.is_editable)) @@ -877,7 +877,7 @@ class NODE_OT_collapse_hide_unused_toggle(Operator): hide = (not node.hide) node.hide = hide - # Note: connected sockets are ignored internally + # NOTE: connected sockets are ignored internally. for socket in node.inputs: socket.hide = hide for socket in node.outputs: @@ -901,7 +901,7 @@ class NODE_OT_tree_path_parent(Operator): @classmethod def poll(cls, context): space = context.space_data - # needs active node editor and a tree + # Needs active node editor and a tree. return (space and (space.type == 'NODE_EDITOR') and len(space.path) > 1) def execute(self, context): @@ -964,19 +964,17 @@ class NODE_OT_interface_item_new(NodeInterfaceOperator, Operator): def find_valid_socket_type(tree): socket_type = 'NodeSocketFloat' # Socket type validation function is only available for custom - # node trees. Assume that 'NodeSocketFloat' is valid for - # built-in node tree types. + # node trees. Assume that 'NodeSocketFloat' is valid for built-in node tree types. if not hasattr(tree, "valid_socket_type") or tree.valid_socket_type(socket_type): return socket_type - # Custom nodes may not support float sockets, search all - # registered socket subclasses. + # Custom nodes may not support float sockets, search all registered socket sub-classes. types_to_check = [bpy.types.NodeSocket] while types_to_check: t = types_to_check.pop() idname = getattr(t, "bl_idname", "") if tree.valid_socket_type(idname): return idname - # Test all subclasses + # Test all sub-classes types_to_check.extend(t.__subclasses__()) def execute(self, context): @@ -1224,7 +1222,7 @@ class NODE_OT_viewer_shortcut_set(Operator): fav_node = selected_nodes[0] # Only viewer nodes can be set to favorites. However, the user can - # create a new favorite viewer by selecting any node and pressing ctrl+1. + # create a new favorite viewer by selecting any node and pressing Control+1. if fav_node.type == 'VIEWER': viewer_node = fav_node else: diff --git a/scripts/startup/bl_ui/node_add_menu.py b/scripts/startup/bl_ui/node_add_menu.py index 7b864662d0c..53bf279ae49 100644 --- a/scripts/startup/bl_ui/node_add_menu.py +++ b/scripts/startup/bl_ui/node_add_menu.py @@ -23,7 +23,7 @@ from bpy.app.translations import ( ) -# NOTE: This is kept for compatibility's sake, as some scripts import node_add_menu.add_node_type +# NOTE: This is kept for compatibility's sake, as some scripts import node_add_menu.add_node_type. def add_node_type(layout, node_type, *, label=None, poll=None, search_weight=0.0, translate=True): """Add a node type to a menu.""" return AddNodeMenu.node_operator( @@ -104,7 +104,7 @@ def add_closure_zone(layout, label): class NodeMenu(Menu): - """A baseclass defining the shared methods for AddNodeMenu and SwapNodeMenu""" + """A baseclass defining the shared methods for AddNodeMenu and SwapNodeMenu.""" draw_assets: bool use_transform: bool @@ -118,7 +118,7 @@ class NodeMenu(Menu): @classmethod def node_operator(cls, layout, node_type, *, label=None, poll=None, search_weight=0.0, translate=True): """The main operator defined for the node menu. - \n(e.g. 'Add Node' for AddNodeMenu, or 'Swap Node' for SwapNodeMenu)""" + \n(e.g. 'Add Node' for AddNodeMenu, or 'Swap Node' for SwapNodeMenu).""" bl_rna = bpy.types.Node.bl_rna_get_subclass(node_type) if not label: @@ -143,7 +143,7 @@ class NodeMenu(Menu): @classmethod def node_operator_with_searchable_enum(cls, context, layout, node_idname, property_name, search_weight=0.0): - """Similar to `node_operator`, but with extra entries based on a enum property while in search""" + """Similar to `node_operator`, but with extra entries based on a enum property while in search.""" operators = [] operators.append(cls.node_operator(layout, node_idname, search_weight=search_weight)) @@ -183,7 +183,7 @@ class NodeMenu(Menu): enum_names, search_weight=0.0, ): - """Similar to `node_operator`, but with extra entries based on a enum socket while in search""" + """Similar to `node_operator`, but with extra entries based on a enum socket while in search.""" operators = [] operators.append(cls.node_operator(layout, node_idname, search_weight=search_weight)) if getattr(context, "is_menu_search", False): @@ -208,7 +208,7 @@ class NodeMenu(Menu): @classmethod def node_operator_with_outputs(cls, context, layout, node_type, subnames, *, label=None, search_weight=0.0): - """Similar to `node_operator`, but with extra entries based on a enum socket while in search""" + """Similar to `node_operator`, but with extra entries based on a enum socket while in search.""" bl_rna = bpy.types.Node.bl_rna_get_subclass(node_type) if not label: label = bl_rna.name if bl_rna else "Unknown" @@ -231,7 +231,7 @@ class NodeMenu(Menu): @classmethod def color_mix_node(cls, context, layout): - """The 'Mix Color' node, with its different blend modes available while in search""" + """The 'Mix Color' node, with its different blend modes available while in search.""" label = iface_("Mix Color") operators = [] @@ -269,7 +269,7 @@ class NodeMenu(Menu): @classmethod def new_empty_group(cls, layout): - """Group Node with a newly created empty group as its assigned nodetree""" + """Group Node with a newly created empty group as its assigned nodetree.""" props = layout.operator(cls.new_empty_group_operator_id, text="New Group", text_ctxt=i18n_contexts.default) if hasattr(props, "use_transform"): @@ -279,7 +279,7 @@ class NodeMenu(Menu): @classmethod def draw_group_menu(cls, context, layout): - """Show operators used for interacting with node groups""" + """Show operators used for interacting with node groups.""" space_node = context.space_data node_tree = space_node.edit_tree all_node_groups = context.blend_data.node_groups @@ -327,10 +327,12 @@ class NodeMenu(Menu): @classmethod def draw_menu(cls, layout, path): - """Takes the given menu path and draws the corresponding menu. - \n Menu paths are either explicitly defined, or based on bl_label if not.""" + """ + Takes the given menu path and draws the corresponding menu. + Menu paths are either explicitly defined, or based on bl_label if not. + """ if cls.pathing_dict is None: - raise ValueError("`pathing_dict` was not set for {}".format(cls)) + raise ValueError("`pathing_dict` was not set for {!s}".format(cls)) layout.menu(cls.pathing_dict[path]) @@ -406,7 +408,7 @@ class AddNodeMenu(NodeMenu): class SwapNodeMenu(NodeMenu): draw_assets = True - # NOTE: Swap operators don't have a `use_transform` property, so defining it here has no effect + # NOTE: Swap operators don't have a `use_transform` property, so defining it here has no effect. main_operator_id = "node.swap_node" zone_operator_id = "node.swap_zone"