Skip to content

Commit 4abdb92

Browse files
committed
add : toggle auto cook logic
1 parent 26b09f7 commit 4abdb92

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

NodeGraphQt/widgets/actions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def __init__(self, *args, **kwargs):
1818
# if hasattr(a, 'node_id'):
1919
# a.node_id = None
2020

21-
def get_menu(self, name,node_id=None):
21+
def get_menu(self, name, node_id=None):
2222
for action in self.actions():
2323
menu = action.menu()
2424
if not menu:

example_auto_nodes.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
import sys
1111
import inspect
1212
import importlib
13+
from example_auto_nodes.node_base.auto_node import AutoNode
14+
from example_auto_nodes.node_base.module_node import ModuleNode
15+
1316

1417
def GetNodesFromFolder(FolderPath):
1518
path, FolderName = os.path.split(FolderPath)
@@ -31,6 +34,17 @@ def GetNodesFromFolder(FolderPath):
3134
return nodes
3235

3336

37+
def cook_node(graph,node):
38+
node.cook()
39+
40+
41+
def print_functions(graph,node):
42+
for func in node.module_functions:
43+
print(func)
44+
45+
def toggle_auto_cook(graph,node):
46+
node.autoCook = not node.autoCook
47+
3448
if __name__ == '__main__':
3549
app = QtWidgets.QApplication([])
3650

@@ -68,19 +82,24 @@ def show_nodes_list(node):
6882
for n in reg_nodes:
6983
graph.register_node(n)
7084

71-
mathNodeA = graph.create_node('Math.MathFunctionsNode',
85+
node_menu = graph.context_nodes_menu()
86+
node_menu.add_command('Print Functions', print_functions, node_class=ModuleNode)
87+
node_menu.add_command('Cook Node', cook_node, node_class=AutoNode)
88+
node_menu.add_command('Toggle Auto Cook', toggle_auto_cook, node_class=AutoNode)
89+
90+
mathNodeA = graph.create_node('Module.MathModuleNode',
7291
name='Math Functions A',
7392
color='#0a1e20',
7493
text_color='#feab20',
7594
pos=[-250, 70])
7695

77-
mathNodeB = graph.create_node('Math.MathFunctionsNode',
96+
mathNodeB = graph.create_node('Module.MathModuleNode',
7897
name='Math Functions B',
7998
color='#0a1e20',
8099
text_color='#feab20',
81100
pos=[-250, -70])
82101

83-
mathNodeC = graph.create_node('Math.MathFunctionsNode',
102+
mathNodeC = graph.create_node('Module.MathModuleNode',
84103
name='Math Functions C',
85104
color='#0a1e20',
86105
text_color='#feab20',

example_auto_nodes/node_base/auto_node.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,33 @@ class AutoNode(BaseNode):
1919
def __init__(self,defaultInputType=None,defaultOutputType=None):
2020
super(AutoNode, self).__init__()
2121
self.needCook = True
22+
self._autoCook = True
2223
self._error = False
2324
self.matchTypes = [[float, int]]
2425
self.errorColor = (200, 50, 50)
26+
self.stopCookColor = (200,200,200)
2527

2628
self.defaultColor = self.get_property("color")
2729
self.defaultValue = None
2830
self.defaultInputType = defaultInputType
2931
self.defaultOutputType = defaultOutputType
3032

33+
@property
34+
def autoCook(self):
35+
return self._autoCook
36+
37+
@autoCook.setter
38+
def autoCook(self,mode):
39+
if mode is self._autoCook:
40+
return
41+
42+
self._autoCook = mode
43+
if mode:
44+
self.set_property('color',self.defaultColor)
45+
else:
46+
self.defaultColor = self.get_property("color")
47+
self.set_property('color', self.stopCookColor)
48+
3149
def cookNextNode(self):
3250
for nodeList in self.connected_output_nodes().values():
3351
for n in nodeList:
@@ -52,7 +70,10 @@ def getInputData(self, port):
5270
data = from_port.node().get_property(from_port.name())
5371
return data
5472

55-
def cook(self):
73+
def cook(self, forceCook = False):
74+
if not self._autoCook and forceCook is not True:
75+
return
76+
5677
if self.disabled():
5778
num = len(self.input_ports())
5879
for index, out_port in enumerate(self.output_ports()):

0 commit comments

Comments
 (0)