[Bf-blender-cvs] [87884310862] functions: allow changing type of Pack List node

Jacques Lucke noreply at git.blender.org
Wed Mar 20 18:51:16 CET 2019


Commit: 87884310862a83a0c906736e8571bd621c1ae196
Author: Jacques Lucke
Date:   Wed Mar 20 18:51:02 2019 +0100
Branches: functions
https://developer.blender.org/rB87884310862a83a0c906736e8571bd621c1ae196

allow changing type of Pack List node

===================================================================

M	release/scripts/startup/function_nodes/base.py
M	release/scripts/startup/function_nodes/node_operators.py
M	release/scripts/startup/function_nodes/nodes/pack_list.py
M	release/scripts/startup/function_nodes/socket_decl.py
M	release/scripts/startup/function_nodes/sockets.py

===================================================================

diff --git a/release/scripts/startup/function_nodes/base.py b/release/scripts/startup/function_nodes/base.py
index 397446c36ce..b40c76e84e4 100644
--- a/release/scripts/startup/function_nodes/base.py
+++ b/release/scripts/startup/function_nodes/base.py
@@ -69,9 +69,9 @@ class BaseNode:
         self.outputs.clear()
 
         inputs, outputs = self.get_sockets()
-        for decl in self.storage.inputs_decl:
+        for decl in inputs:
             decl.build(self, self.inputs)
-        for decl in self.storage.outputs_decl:
+        for decl in outputs:
             decl.build(self, self.outputs)
         self.storage.set_current_declaration(inputs, outputs)
 
@@ -116,6 +116,17 @@ class BaseNode:
             *, icon="NONE", settings=tuple()):
         assert isinstance(settings, tuple)
         props = layout.operator("fn.node_operator", text=text, icon=icon)
+        self._set_common_invoke_props(props, function_name, settings)
+
+    def invoke_type_selection(self,
+            layout, function_name, text,
+            *, mode="ALL", icon="NONE", settings=tuple()):
+        assert isinstance(settings, tuple)
+        props = layout.operator("fn.node_data_type_selector", text=text, icon=icon)
+        self._set_common_invoke_props(props, function_name, settings)
+        props.mode = mode
+
+    def _set_common_invoke_props(self, props, function_name, settings):
         props.tree_name = self.id_data.name
         props.node_name = self.name
         props.function_name = function_name
diff --git a/release/scripts/startup/function_nodes/node_operators.py b/release/scripts/startup/function_nodes/node_operators.py
index 5c6aa24991e..95610cc392f 100644
--- a/release/scripts/startup/function_nodes/node_operators.py
+++ b/release/scripts/startup/function_nodes/node_operators.py
@@ -1,27 +1,61 @@
 import bpy
 from bpy.props import *
+from . sockets import type_infos
 
-class NodeOperator(bpy.types.Operator):
-    bl_idname = "fn.node_operator"
-    bl_label = "Generic Node Operator"
-    bl_options = {"INTERNAL"}
-
+class NodeOperatorBase:
     tree_name: StringProperty()
     node_name: StringProperty()
     function_name: StringProperty()
     settings_repr: StringProperty()
 
-    def execute(self, context):
+    def call(self, *args):
         tree = bpy.data.node_groups.get(self.tree_name)
         if tree is None:
-            return {"CANCELLED"}
+            return {'CANCELLED'}
 
         node = tree.nodes.get(self.node_name)
         if node is None:
-            return {"CANCELLED"}
+            return {'CANCELLED'}
 
         function = getattr(node, self.function_name)
         settings = eval(self.settings_repr)
-        function(*settings)
+        function(*args, *settings)
+        return {'FINISHED'}
+
+class NodeOperator(bpy.types.Operator, NodeOperatorBase):
+    bl_idname = "fn.node_operator"
+    bl_label = "Generic Node Operator"
+    bl_options = {'INTERNAL'}
+
+    def execute(self, context):
+        return self.call()
+
+class NodeDataTypeSelector(bpy.types.Operator, NodeOperatorBase):
+    bl_idname = "fn.node_data_type_selector"
+    bl_label = "Generic Node Data Type Selector"
+    bl_options = {'INTERNAL'}
+    bl_property = "item"
+
+    mode: EnumProperty(
+        items=[
+            ("ALL", "All", ""),
+            ("BASE", "Base", ""),
+        ])
+
+    def get_items(self, context):
+        if self.mode == "ALL":
+            return type_infos.get_data_type_items()
+        elif self.mode == "BASE":
+            return type_infos.get_base_type_items()
+        else:
+            assert False
+
+    item: EnumProperty(items=get_items)
+
+    def invoke(self, context, event):
+        context.window_manager.invoke_search_popup(self)
+        return {'CANCELLED'}
+
+    def execute(self, context):
+        return self.call(self.item)
 
-        return {"FINISHED"}
\ No newline at end of file
diff --git a/release/scripts/startup/function_nodes/nodes/pack_list.py b/release/scripts/startup/function_nodes/nodes/pack_list.py
index 3c657d10a07..bed85288b7b 100644
--- a/release/scripts/startup/function_nodes/nodes/pack_list.py
+++ b/release/scripts/startup/function_nodes/nodes/pack_list.py
@@ -16,4 +16,11 @@ class PackListNode(bpy.types.Node, FunctionNode):
             PackListDecl("inputs", "variadic", self.active_type),
         ], [
             FixedSocketDecl("output", "List", type_infos.to_list(self.active_type)),
-        ]
\ No newline at end of file
+        ]
+
+    def draw(self, layout):
+        self.invoke_type_selection(layout, "set_type", "Change Type", mode="BASE")
+
+    def set_type(self, data_type):
+        self.active_type = data_type
+        self.rebuild_and_try_keep_state()
\ No newline at end of file
diff --git a/release/scripts/startup/function_nodes/socket_decl.py b/release/scripts/startup/function_nodes/socket_decl.py
index 1c4229f12eb..a99d81d1114 100644
--- a/release/scripts/startup/function_nodes/socket_decl.py
+++ b/release/scripts/startup/function_nodes/socket_decl.py
@@ -247,10 +247,7 @@ class AppendAnyVariadicOperator(bpy.types.Operator):
     node_name: StringProperty()
     prop_name: StringProperty()
 
-    def get_data_type_items(self, context):
-        return type_infos.get_data_type_items()
-
-    item: EnumProperty(items=get_data_type_items)
+    item: EnumProperty(items=type_infos.get_data_type_items_cb())
 
     def invoke(self, context, event):
         context.window_manager.invoke_search_popup(self)
diff --git a/release/scripts/startup/function_nodes/sockets.py b/release/scripts/startup/function_nodes/sockets.py
index b647667e4fe..cac39a92887 100644
--- a/release/scripts/startup/function_nodes/sockets.py
+++ b/release/scripts/startup/function_nodes/sockets.py
@@ -150,6 +150,17 @@ class DataTypesInfo:
             items.append((data_type, data_type, ""))
         return items
 
+    def get_base_type_items(self):
+        items = []
+        for data_type in self.list_by_base.keys():
+            items.append((data_type, data_type, ""))
+        return items
+
+    def get_data_type_items_cb(self):
+        def callback(_1, _2):
+            return self.get_data_type_items()
+        return callback
+
 
 type_infos = DataTypesInfo()



More information about the Bf-blender-cvs mailing list