diff options
Diffstat (limited to 'release/scripts')
-rw-r--r-- | release/scripts/modules/nodeitems_utils.py | 30 | ||||
-rw-r--r-- | release/scripts/startup/nodeitems_builtins.py | 9 |
2 files changed, 30 insertions, 9 deletions
diff --git a/release/scripts/modules/nodeitems_utils.py b/release/scripts/modules/nodeitems_utils.py index cb574b72853..2114a64e416 100644 --- a/release/scripts/modules/nodeitems_utils.py +++ b/release/scripts/modules/nodeitems_utils.py @@ -57,6 +57,27 @@ class NodeItem(): # if no custom label is defined, fall back to the node type UI name return getattr(bpy.types, self.nodetype).bl_rna.name + # NB: is a staticmethod because called with an explicit self argument + # NodeItemCustom sets this as a variable attribute in __init__ + @staticmethod + def draw(self, layout, context): + default_context = bpy.app.translations.contexts.default + + props = layout.operator("node.add_node", text=self.label, text_ctxt=default_context) + props.type = self.nodetype + props.use_transform = True + + for setting in self.settings.items(): + ops = props.settings.add() + ops.name = setting[0] + ops.value = setting[1] + + +class NodeItemCustom(): + def __init__(self, poll=None, draw=None): + self.poll = poll + self.draw = draw + _node_categories = {} @@ -71,14 +92,7 @@ def register_node_categories(identifier, cat_list): col = layout.column() default_context = bpy.app.translations.contexts.default for item in self.category.items(context): - props = col.operator("node.add_node", text=item.label, text_ctxt=default_context) - props.type = item.nodetype - props.use_transform = True - - for setting in item.settings.items(): - ops = props.settings.add() - ops.name = setting[0] - ops.value = setting[1] + item.draw(item, col, context) menu_types = [] panel_types = [] diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py index 6e5fbeca170..a4e9d4d51a5 100644 --- a/release/scripts/startup/nodeitems_builtins.py +++ b/release/scripts/startup/nodeitems_builtins.py @@ -19,7 +19,7 @@ # <pep8 compliant> import bpy import nodeitems_utils -from nodeitems_utils import NodeCategory, NodeItem +from nodeitems_utils import NodeCategory, NodeItem, NodeItemCustom # Subclasses for standard node types @@ -47,6 +47,11 @@ class TextureNodeCategory(NodeCategory): return context.space_data.tree_type == 'TextureNodeTree' +# menu entry for making a new group from selected nodes +def group_make_draw(self, layout, context): + layout.operator("node.group_make") + layout.separator() + # maps node tree type to group node type node_tree_group_type = { 'CompositorNodeTree' : 'CompositorNodeGroup', @@ -62,6 +67,8 @@ def node_group_items(context): if not ntree: return + yield NodeItemCustom(draw=group_make_draw) + def contains_group(nodetree, group): if nodetree == group: return True |