Skip to content

Commit c3f4f7a

Browse files
committed
merge logic nodes to auto node example && change default node type
1 parent 3dad40f commit c3f4f7a

File tree

11 files changed

+161
-215
lines changed

11 files changed

+161
-215
lines changed

NodeGraphQt/constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
# === ITEM CACHE MODE ===
110110

111111
# QGraphicsItem.NoCache
112-
# QGraphicsItem.ItemCoordinateCache
113112
# QGraphicsItem.DeviceCoordinateCache
113+
# QGraphicsItem.ItemCoordinateCache
114114

115-
ITEM_CACHE_MODE = QtWidgets.QGraphicsItem.ItemCoordinateCache
115+
ITEM_CACHE_MODE = QtWidgets.QGraphicsItem.DeviceCoordinateCache

NodeGraphQt/widgets/viewer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def _set_viewer_zoom(self, value, sensitivity=None, pos=None):
130130
self.scale(scale, scale, pos)
131131

132132
def _set_viewer_pan(self, pos_x, pos_y):
133-
speed = self._scene_range.width() * 0.001
133+
speed = self._scene_range.width() * 0.002
134134
x = -pos_x * speed
135135
y = -pos_y * speed
136136
self._scene_range.adjust(x, y, x, y)

example_auto_nodes.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,19 @@ def GetNodesFromFolder(FolderPath):
3434
return nodes
3535

3636

37-
def cook_node(graph,node):
37+
def cook_node(graph, node):
3838
node.cook()
3939

4040

41-
def print_functions(graph,node):
41+
def print_functions(graph, node):
4242
for func in node.module_functions:
4343
print(func)
4444

45-
def toggle_auto_cook(graph,node):
45+
46+
def toggle_auto_cook(graph, node):
4647
node.autoCook = not node.autoCook
4748

49+
4850
if __name__ == '__main__':
4951
app = QtWidgets.QApplication([])
5052

example_auto_nodes/basic_nodes.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
from .node_base.auto_node import AutoNode
22

3+
34
class FooNode(AutoNode):
45
"""
56
A node class with 2 inputs and 2 outputs.
67
"""
78

89
# unique node identifier.
9-
__identifier__ = 'com.chantasticvfx'
10+
__identifier__ = 'examples'
1011

1112
# initial default node name.
1213
NODE_NAME = 'foo node'
@@ -23,14 +24,15 @@ def __init__(self):
2324
self.add_output('out B')
2425
self.set_icon("example_auto_nodes/pear.png")
2526

27+
2628
class BarNode(AutoNode):
2729
"""
2830
A node class with 3 inputs and 3 outputs.
2931
The last input and last output can take in multiple pipes.
3032
"""
3133

3234
# unique node identifier.
33-
__identifier__ = 'com.chantasticvfx'
35+
__identifier__ = 'examples'
3436

3537
# initial default node name.
3638
NODE_NAME = 'bar'

example_auto_nodes/data_node.py

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,27 @@ class VectorSplit(AutoNode):
1313

1414
def __init__(self):
1515
super(VectorSplit, self).__init__()
16-
self.defaultValue = [0.0, 0.0, 0.0]
1716

1817
self.add_output('x')
19-
self.create_property("x", self.defaultValue[0])
18+
self.create_property("x", 0.0)
2019
self.add_output('y')
21-
self.create_property("y", self.defaultValue[1])
20+
self.create_property("y", 0.0)
2221
self.add_output('z')
23-
self.create_property("z", self.defaultValue[2])
22+
self.create_property("z", 0.0)
23+
self.add_output('w')
24+
self.create_property("w", 0.0)
2425

25-
self.add_input("in vector",list)
26+
self.add_input("in vector", list)
27+
self.map = {0: "x", 1: "y", 2: "z", 3: "w"}
2628

2729
def run(self):
2830
value = self.getInputData(0)
29-
self.set_property("x", value[0])
30-
self.set_property("y", value[1])
31-
self.set_property("z", value[2])
31+
if type(value) is not list:
32+
self.error("Input data not list")
33+
for index, data in enumerate(value):
34+
if index > 3:
35+
return
36+
self.set_property(self.map[index], data)
3237

3338

3439
class VectorMaker(AutoNode):
@@ -42,17 +47,22 @@ class VectorMaker(AutoNode):
4247
def __init__(self):
4348
super(VectorMaker, self).__init__()
4449

45-
self.add_output('out')
46-
self.create_property("out", [0, 0, 0])
47-
48-
self.add_input("x",float)
49-
self.add_input("y",float)
50-
self.add_input("z",float)
50+
self.add_output('out', list)
51+
self.create_property("out",None)
5152

52-
self.defaultValue = 0.0
53+
self.add_input("x", float)
54+
self.add_input("y", float)
55+
self.add_input("z", float)
56+
self.add_input("w", float)
5357

5458
def run(self):
55-
self.set_property("out", [self.getInputData(0), self.getInputData(1), self.getInputData(2)])
59+
result = []
60+
for i in range(4):
61+
data = self.getInputData(i)
62+
if data is not None:
63+
result.append(data)
64+
65+
self.set_property("out", result)
5666

5767

5868
class DataConvect(AutoNode):
@@ -67,7 +77,7 @@ def __init__(self):
6777
super(DataConvect, self).__init__()
6878

6979
self.add_output('out')
70-
self.create_property("out",None)
80+
self.create_property("out", None)
7181
self.add_input("in data")
7282

7383
items = ["all to int"]

example_auto_nodes/input_nodes.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from NodeGraphQt import QtCore
22
from NodeGraphQt.constants import (NODE_PROP_VECTOR2,
33
NODE_PROP_VECTOR3,
4-
NODE_PROP_VECTOR4,
5-
NODE_PROP_SLIDER)
4+
NODE_PROP_VECTOR4)
65

76
from .node_base.auto_node import AutoNode
87
import os
@@ -19,7 +18,7 @@ class FloatInputNode(AutoNode):
1918
def __init__(self):
2019
super(FloatInputNode, self).__init__()
2120
self.output = self.add_output('out', float)
22-
self.add_float_input('out', 'Float Value', value=0.0,range=(-10,10))
21+
self.add_float_input('out', 'Float Value', value=0.0, range=(-10, 10))
2322

2423

2524
class IntInputNode(AutoNode):
@@ -44,7 +43,7 @@ def __init__(self):
4443
super(Vector2InputNode, self).__init__()
4544
self.output = self.add_output('out', list)
4645
self.create_property(
47-
"out", [0, 0], widget_type=NODE_PROP_VECTOR2)
46+
"out", [0.0, 0.0], widget_type=NODE_PROP_VECTOR2)
4847

4948

5049
class Vector3InputNode(AutoNode):
@@ -55,7 +54,7 @@ def __init__(self):
5554
super(Vector3InputNode, self).__init__()
5655
self.output = self.add_output('out', list)
5756
self.create_property(
58-
"out", [0, 0, 0], widget_type=NODE_PROP_VECTOR3)
57+
"out", [0.0, 0.0, 0.0], widget_type=NODE_PROP_VECTOR3)
5958

6059

6160
class Vector4InputNode(AutoNode):
@@ -66,7 +65,7 @@ def __init__(self):
6665
super(Vector4InputNode, self).__init__()
6766
self.output = self.add_output('out', list)
6867
self.create_property(
69-
"out", [0, 0, 0, 0], widget_type=NODE_PROP_VECTOR4)
68+
"out", [0.0, 0.0, 0.0, 0.0], widget_type=NODE_PROP_VECTOR4)
7069

7170

7271
class TickTimeNode(AutoNode):
@@ -106,7 +105,6 @@ def __init__(self):
106105
self.add_output('file content', str)
107106
self.create_property('file content', "")
108107
self.add_output('file path', str)
109-
110108
self.add_file_input('file path', 'File Path')
111109

112110
def run(self):
@@ -119,7 +117,7 @@ def run(self):
119117
except Exception as e:
120118
self.error(e)
121119
else:
122-
self.error('No existe %s' % path)
120+
self.error('No exist %s' % path)
123121
self.set_property('file content', '')
124122

125123

@@ -142,3 +140,21 @@ def __init__(self):
142140

143141
# create QLineEdit text input widget.
144142
self.add_text_input('out', 'Text Input')
143+
144+
145+
class BoolInputNode(AutoNode):
146+
"""
147+
Input Bool data.
148+
"""
149+
150+
__identifier__ = 'Inputs'
151+
NODE_NAME = 'Bool'
152+
153+
def __init__(self):
154+
super(BoolInputNode, self).__init__()
155+
self.add_output('out', bool)
156+
self.create_property('out', True)
157+
self.add_combo_menu('combo', 'Bool value', items=['True', 'False'])
158+
159+
def run(self):
160+
self.set_property('out', eval(self.get_property('combo')))

example_auto_nodes/logic_nodes.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
from .basic_nodes import AutoNode
2+
3+
4+
class IfNode(AutoNode):
5+
"""
6+
if node.
7+
"""
8+
9+
__identifier__ = 'Logics'
10+
NODE_NAME = 'If'
11+
12+
def __init__(self):
13+
super(IfNode, self).__init__()
14+
self.condition = self.add_input('condition')
15+
self._then = self.add_input('then')
16+
self._else = self.add_input('else')
17+
self.add_output('out')
18+
self.create_property('out', None)
19+
20+
def run(self):
21+
if self.getInputData(self.condition):
22+
result = self.getInputData(self._then)
23+
else:
24+
result = self.getInputData(self._else)
25+
26+
self.set_property('out', result)
27+
28+
29+
class BooleanNode(AutoNode):
30+
"""
31+
Boolean Logic funtions node.
32+
"""
33+
34+
__identifier__ = 'Logics'
35+
36+
NODE_NAME = 'Boolean'
37+
38+
logics = {'and': 'a and b',
39+
'or': 'a or b',
40+
'xor': '(not a and b) or (a and not b)',
41+
'not': 'not a'}
42+
43+
def __init__(self):
44+
super(BooleanNode, self).__init__()
45+
self.a = self.add_input('a',bool)
46+
self.b = self.add_input('b',bool)
47+
self.add_output('out',bool)
48+
self.create_property('out', None)
49+
self.add_combo_menu('funcs',
50+
'Functions',
51+
items=list(self.logics.keys()),
52+
tab='widgets')
53+
54+
self.func = self.logics['and']
55+
# switch math function type
56+
self.view.widgets['funcs'].value_changed.connect(self.addFunction)
57+
58+
def addFunction(self, prop, func):
59+
"""
60+
Create inputs based on math functions arguments.
61+
"""
62+
self.func = self.logics[func]
63+
if self.b.visible() and not 'b' in self.func:
64+
self.b.set_visible(False)
65+
elif not self.b.visible():
66+
self.b.set_visible(True)
67+
self.cook()
68+
69+
def run(self):
70+
a = self.getInputData(self.a)
71+
b = self.getInputData(self.b)
72+
73+
if a is None or (b is None and 'b' in self.func):
74+
self.error("No inputs!")
75+
return
76+
77+
self.set_property('out', eval(self.func))
78+

0 commit comments

Comments
 (0)