Skip to content

Commit d46ad6a

Browse files
committed
add AutoNode class evaluate the node pipline
1 parent 7476beb commit d46ad6a

File tree

10 files changed

+668
-0
lines changed

10 files changed

+668
-0
lines changed

example_auto_nodes.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
import example_auto_nodes
4+
5+
from NodeGraphQt import (NodeGraph,
6+
BaseNode,
7+
setup_context_menu)
8+
from NodeGraphQt import QtWidgets, QtCore, PropertiesBinWidget, NodeTreeWidget
9+
import os
10+
import sys
11+
import inspect
12+
import importlib
13+
14+
def GetNodesFromFolder(FolderPath):
15+
path, FolderName = os.path.split(FolderPath)
16+
if path not in sys.path:
17+
sys.path.append(path)
18+
19+
nodes = []
20+
for i in os.listdir(FolderPath):
21+
if not i.endswith(".py") or i.startswith("_"):
22+
continue
23+
24+
filename = i[:-3]
25+
module_name = FolderName + "." + filename
26+
27+
for name, obj in inspect.getmembers(importlib.import_module(module_name)):
28+
if inspect.isclass(obj) and filename in str(obj):
29+
if len(inspect.getmembers(obj)) > 0:
30+
nodes.append(obj)
31+
return nodes
32+
33+
34+
if __name__ == '__main__':
35+
app = QtWidgets.QApplication([])
36+
37+
# create node graph.
38+
graph = NodeGraph()
39+
40+
# set up default menu and commands.
41+
setup_context_menu(graph)
42+
43+
# widget used for the node graph.
44+
graph_widget = graph.widget
45+
graph_widget.resize(1100, 800)
46+
graph_widget.show()
47+
48+
# show the properties bin when a node is "double clicked" in the graph.
49+
properties_bin = PropertiesBinWidget(node_graph=graph)
50+
properties_bin.setWindowFlags(QtCore.Qt.Tool)
51+
52+
def show_prop_bin(node):
53+
if not properties_bin.isVisible():
54+
properties_bin.show()
55+
graph.node_double_clicked.connect(show_prop_bin)
56+
57+
# show the nodes list when a node is "double clicked" in the graph.
58+
node_tree = NodeTreeWidget(node_graph=graph)
59+
60+
def show_nodes_list(node):
61+
if not node_tree.isVisible():
62+
node_tree.update()
63+
node_tree.show()
64+
graph.node_double_clicked.connect(show_nodes_list)
65+
66+
reg_nodes = GetNodesFromFolder(os.getcwd() + "/example_auto_nodes")
67+
68+
for n in reg_nodes:
69+
graph.register_node(n)
70+
71+
mathNodeA = graph.create_node('Math.MathFunctionsNode',
72+
name='Math Functions A',
73+
color='#0a1e20',
74+
text_color='#feab20',
75+
pos=[-250, 70])
76+
77+
mathNodeB = graph.create_node('Math.MathFunctionsNode',
78+
name='Math Functions B',
79+
color='#0a1e20',
80+
text_color='#feab20',
81+
pos=[-250, -70])
82+
83+
mathNodeC = graph.create_node('Math.MathFunctionsNode',
84+
name='Math Functions C',
85+
color='#0a1e20',
86+
text_color='#feab20',
87+
pos=[0, 0])
88+
89+
inputANode = graph.create_node('Inputs.FloatInputNode',
90+
name='Input A',
91+
pos=[-500, -50])
92+
93+
inputBNode = graph.create_node('Inputs.FloatInputNode',
94+
name='Input B',
95+
pos=[-500, 50])
96+
97+
outputNode = graph.create_node('Viewers.DataViewerNode',
98+
name='Output',
99+
pos=[250, 0])
100+
101+
app.exec_()

example_auto_nodes/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

example_auto_nodes/basic_nodes.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from .node_base.auto_node import AutoNode
2+
3+
class FooNode(AutoNode):
4+
"""
5+
A node class with 2 inputs and 2 outputs.
6+
"""
7+
8+
# unique node identifier.
9+
__identifier__ = 'com.chantasticvfx'
10+
11+
# initial default node name.
12+
NODE_NAME = 'foo node'
13+
14+
def __init__(self):
15+
super(FooNode, self).__init__()
16+
17+
# create node inputs.
18+
self.add_input('in A')
19+
self.add_input('in B')
20+
21+
# create node outputs.
22+
self.add_output('out A')
23+
self.add_output('out B')
24+
25+
26+
class BarNode(AutoNode):
27+
"""
28+
A node class with 3 inputs and 3 outputs.
29+
The last input and last output can take in multiple pipes.
30+
"""
31+
32+
# unique node identifier.
33+
__identifier__ = 'com.chantasticvfx'
34+
35+
# initial default node name.
36+
NODE_NAME = 'bar'
37+
38+
def __init__(self):
39+
super(BarNode, self).__init__()
40+
41+
# create node inputs
42+
self.add_input('single in 1')
43+
self.add_input('single in 2')
44+
self.add_input('multi in', multi_input=True)
45+
46+
# create node outputs
47+
self.add_output('single out 1', multi_output=False)
48+
self.add_output('single out 2', multi_output=False)
49+
self.add_output('multi out')

example_auto_nodes/input_nodes.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
from NodeGraphQt import QtCore
2+
from.node_base.auto_node import AutoNode
3+
import os
4+
5+
class DataInputNode(AutoNode):
6+
"""
7+
Input node data.
8+
"""
9+
10+
__identifier__ = 'Inputs'
11+
NODE_NAME = 'Basic Input'
12+
13+
def __init__(self):
14+
super(DataInputNode, self).__init__()
15+
self.add_output('out')
16+
self.add_text_input('out', 'Data Output', text='0.4', tab='widgets')
17+
self.view.widgets['out'].value_changed.connect(self.cook)
18+
19+
20+
class FloatInputNode(AutoNode):
21+
"""
22+
Input float data.
23+
"""
24+
25+
__identifier__ = 'Inputs'
26+
NODE_NAME = 'Float'
27+
28+
def __init__(self):
29+
super(FloatInputNode, self).__init__()
30+
self.defaultValue = 0.0
31+
32+
self.output = self.add_output('out',float)
33+
self.add_float_input('out', 'Float Value', value=self.defaultValue, tab='widgets')
34+
self.view.widgets['out'].value_changed.connect(self.cook)
35+
36+
37+
class TickTimeNode(AutoNode):
38+
"""
39+
Every second that passes adds a tick.
40+
"""
41+
42+
__identifier__ = 'Inputs'
43+
NODE_NAME = 'Tick Time'
44+
45+
def __init__(self):
46+
super(TickTimeNode, self).__init__()
47+
self.add_output('out',float)
48+
self.add_float_input('out', 'Data Input', value=0.0, tab='widgets')
49+
self.view.widgets['out'].value_changed.connect(self.cook)
50+
51+
self.timer = QtCore.QTimer()
52+
self.timer.timeout.connect(self.tick)
53+
self.timer.start(1000)
54+
55+
def tick(self):
56+
if not self.disabled():
57+
current = self.get_property('out')
58+
current += 1
59+
self.set_property("out",current)
60+
61+
62+
class TextFileInputNode(AutoNode):
63+
"""
64+
Text File Input node data.
65+
"""
66+
67+
__identifier__ = 'Inputs'
68+
NODE_NAME = 'Text File'
69+
70+
def __init__(self):
71+
super(TextFileInputNode, self).__init__()
72+
self.add_output('out',str)
73+
self.create_property('out', "")
74+
self.add_text_input('path', 'Text File Path', text='', tab='widgets')
75+
self.view.widgets['path'].value_changed.connect(self.cook)
76+
77+
def run(self):
78+
path = self.get_property('path')
79+
if os.path.exists(path):
80+
with open(path, 'r') as fread:
81+
data = fread.read()
82+
self.set_property('output', data)
83+
else:
84+
print('No existe %s' % path)
85+
self.set_property('output', '')

0 commit comments

Comments
 (0)