Fix #35633, Cannot Add Group Node In Blender 2.67a. The menu entry for the "make...
authorLukas Toenne <lukas.toenne@googlemail.com>
Wed, 5 Jun 2013 09:21:17 +0000 (09:21 +0000)
committerLukas Toenne <lukas.toenne@googlemail.com>
Wed, 5 Jun 2013 09:21:17 +0000 (09:21 +0000)
allow custom draw functions such as this operator. Used in the group items callback to generate the basic group_make operator call.

release/scripts/modules/nodeitems_utils.py
release/scripts/startup/nodeitems_builtins.py

index cb574b7285375d57858816540ec8359e0f58a282..2114a64e416ccc400d88acc899c62c83514a60bc 100644 (file)
@@ -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 = []
index 6e5fbeca170e668727b6eb7f576085b902c41711..a4e9d4d51a57e81b8ffc2493c314bae8e098714c 100644 (file)
@@ -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