Skip to content

Commit 75dc9f1

Browse files
committed
upgrade and add new example nodes
1 parent b9f0fea commit 75dc9f1

File tree

6 files changed

+477
-18
lines changed

6 files changed

+477
-18
lines changed

example_auto_nodes/data_node.py

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
from .node_base.auto_node import AutoNode
4+
5+
6+
class VectorValue(AutoNode):
7+
"""
8+
Create a basic vector data
9+
"""
10+
11+
__identifier__ = 'Data'
12+
NODE_NAME = 'Vector'
13+
14+
def __init__(self):
15+
super(VectorValue, self).__init__()
16+
value = [0.0, 0.0, 0.0]
17+
18+
self.add_output('out',list)
19+
self.create_property("out", value)
20+
21+
self.add_float_input('0', 'X', value=value[0], tab='widgets')
22+
self.view.widgets['0'].value_changed.connect(lambda: self.updateValue(0))
23+
24+
self.add_float_input('1', 'Y', value=value[1], tab='widgets')
25+
self.view.widgets['1'].value_changed.connect(lambda: self.updateValue(1))
26+
27+
self.add_float_input('2', 'Z', value=value[2], tab='widgets')
28+
self.view.widgets['2'].value_changed.connect(lambda: self.updateValue(2))
29+
30+
self.defaultValue = value
31+
32+
def updateValue(self, index):
33+
self.get_property("out")[index] = self.get_property(str(index))
34+
self.cook()
35+
36+
37+
class VectorSplit(AutoNode):
38+
"""
39+
Splict a vector to x,y,z
40+
"""
41+
42+
__identifier__ = 'Data'
43+
NODE_NAME = 'Vector Split'
44+
45+
def __init__(self):
46+
super(VectorSplit, self).__init__()
47+
self.defaultValue = [0.0, 0.0, 0.0]
48+
49+
self.add_output('x')
50+
self.create_property("x", self.defaultValue[0])
51+
self.add_output('y')
52+
self.create_property("y", self.defaultValue[1])
53+
self.add_output('z')
54+
self.create_property("z", self.defaultValue[2])
55+
56+
self.add_input("in vector",list)
57+
58+
def run(self):
59+
value = self.getInputData(0)
60+
self.set_property("x", value[0])
61+
self.set_property("y", value[1])
62+
self.set_property("z", value[2])
63+
64+
65+
class VectorMaker(AutoNode):
66+
"""
67+
Create a vector by three float value
68+
"""
69+
70+
__identifier__ = 'Data'
71+
NODE_NAME = 'Vector Maker'
72+
73+
def __init__(self):
74+
super(VectorMaker, self).__init__()
75+
76+
self.add_output('out')
77+
self.create_property("out", [0, 0, 0])
78+
79+
self.add_input("x",float)
80+
self.add_input("y",float)
81+
self.add_input("z",float)
82+
83+
self.defaultValue = 0.0
84+
85+
def run(self):
86+
self.set_property("out", [self.getInputData(0), self.getInputData(1), self.getInputData(2)])
87+
88+
89+
class DataConvect(AutoNode):
90+
"""
91+
Create a vector by three float value
92+
"""
93+
94+
__identifier__ = 'Data'
95+
NODE_NAME = 'Data Convect'
96+
97+
def __init__(self):
98+
super(DataConvect, self).__init__()
99+
100+
self.add_output('out')
101+
self.create_property("out",None)
102+
self.add_input("in data")
103+
104+
items = ["all to int"]
105+
items.append("all to float")
106+
items.append("all to string")
107+
items.append("eval string")
108+
self.add_combo_menu('method', 'Method', items=items, tab='widgets')
109+
self.view.widgets['method'].value_changed.connect(self.cook)
110+
111+
def run(self):
112+
method = self.get_property("method")
113+
try:
114+
if method == "all to int":
115+
data = int(self.getInputData(0))
116+
elif method == "all to float":
117+
data = float(self.getInputData(0))
118+
elif method == "all to string":
119+
data = str(self.getInputData(0))
120+
elif method == "eval string":
121+
data = eval(self.getInputData(0))
122+
self.set_property("out", data)
123+
except Exception as error:
124+
self.error(error)

example_auto_nodes/input_nodes.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,6 @@
22
from.node_base.auto_node import AutoNode
33
import os
44

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-
205
class FloatInputNode(AutoNode):
216
"""
227
Input float data.
@@ -97,7 +82,7 @@ class TextInputNode(AutoNode):
9782
__identifier__ = 'Inputs'
9883

9984
# initial default node name.
100-
NODE_NAME = 'text'
85+
NODE_NAME = 'Text'
10186

10287
def __init__(self):
10388
super(TextInputNode, self).__init__()

example_auto_nodes/module_nodes.py

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
from example_auto_nodes.node_base.module_node import (ModuleNode,
2+
get_functions_from_module,
3+
get_functions_from_type)
4+
5+
import math
6+
import os
7+
import sys
8+
import random
9+
import numpy
10+
import numpydoc.docscrape
11+
import inspect
12+
13+
# add basic math functions to math library
14+
math.add = lambda x, y: x + y
15+
math.sub = lambda x, y: x - y
16+
math.mul = lambda x, y: x * y
17+
math.div = lambda x, y: x / y
18+
19+
20+
class MathModuleNode(ModuleNode):
21+
"""
22+
Math functions node.
23+
"""
24+
25+
# set a unique node identifier.
26+
__identifier__ = 'Module'
27+
28+
# set the initial default node name.
29+
NODE_NAME = 'math module'
30+
31+
module_functions = get_functions_from_type(math)
32+
33+
def __init__(self):
34+
super(MathModuleNode, self).__init__()
35+
self.defaultValue = 0.0
36+
37+
38+
class osModuleNode(ModuleNode):
39+
"""
40+
os module node.
41+
"""
42+
43+
# set a unique node identifier.
44+
__identifier__ = 'Module'
45+
46+
# set the initial default node name.
47+
NODE_NAME = 'os module'
48+
49+
module_functions = get_functions_from_module(os, max_depth=2)
50+
module_functions.pop("os.abort")
51+
52+
def __init__(self):
53+
super(osModuleNode, self).__init__()
54+
55+
class sysModuleNode(ModuleNode):
56+
"""
57+
sys module node.
58+
"""
59+
60+
# set a unique node identifier.
61+
__identifier__ = 'Module'
62+
63+
# set the initial default node name.
64+
NODE_NAME = 'sys module'
65+
66+
module_functions = get_functions_from_module(sys, max_depth=2)
67+
module_functions.pop("sys.exit")
68+
module_functions.pop("sys.breakpointhook")
69+
70+
def __init__(self):
71+
super(sysModuleNode, self).__init__()
72+
73+
74+
class randomModuleNode(ModuleNode):
75+
"""
76+
random module node.
77+
"""
78+
79+
# set a unique node identifier.
80+
__identifier__ = 'Module'
81+
82+
# set the initial default node name.
83+
NODE_NAME = 'random module'
84+
85+
module_functions = get_functions_from_module(random,max_depth=2)
86+
87+
88+
def __init__(self):
89+
super(randomModuleNode, self).__init__()
90+
91+
92+
class numpyModuleNode(ModuleNode):
93+
"""
94+
numpy module node.
95+
"""
96+
97+
# set a unique node identifier.
98+
__identifier__ = 'Module'
99+
100+
# set the initial default node name.
101+
NODE_NAME = 'numpy module'
102+
103+
module_functions = get_functions_from_module(numpy,max_depth=2)
104+
105+
106+
def __init__(self):
107+
super(numpyModuleNode, self).__init__()
108+
109+
def is_function(self,obj):
110+
result = super(numpyModuleNode,self).is_function(obj)
111+
if result:
112+
return True
113+
elif type(obj).__name__ == "ufunc":
114+
return True
115+
return False
116+
117+
def get_numpy_args(self,func):
118+
args = []
119+
info = numpydoc.docscrape.FunctionDoc(func)
120+
for i in info["Parameters"]:
121+
param = str(i)
122+
if "name" in param:
123+
args.append(param.split("'")[1])
124+
return args
125+
126+
def addFunction(self, prop, func):
127+
"""
128+
Create inputs based on functions arguments.
129+
"""
130+
131+
self.func = self.module_functions[func]
132+
133+
args = []
134+
if self.is_function(self.func):
135+
try:
136+
args = inspect.getfullargspec(self.func).args
137+
except Exception as error:
138+
try:
139+
args = self.get_numpy_args(self.func)
140+
except Exception as error:
141+
if type(self.func).__name__ == "ufunc":
142+
args = ["input"+str(i+1) for i in range(self.func.nin)]
143+
144+
self.process_args(args)
145+
146+
147+
class StringFunctionsNode(ModuleNode):
148+
"""
149+
String functions node.
150+
"""
151+
152+
# set a unique node identifier.
153+
__identifier__ = 'Data'
154+
155+
# set the initial default node name.
156+
NODE_NAME = 'String Functions'
157+
158+
module_functions = get_functions_from_type(str)
159+
160+
def __init__(self):
161+
super(StringFunctionsNode, self).__init__()
162+
163+
164+
class ListFunctionsNode(ModuleNode):
165+
"""
166+
List functions node.
167+
"""
168+
169+
# set a unique node identifier.
170+
__identifier__ = 'Data'
171+
172+
# set the initial default node name.
173+
NODE_NAME = 'List Functions'
174+
175+
module_functions = get_functions_from_type(list)
176+
177+
def __init__(self):
178+
super(ListFunctionsNode, self).__init__()
179+
180+
181+
class DictFunctionsNode(ModuleNode):
182+
"""
183+
DIct functions node.
184+
"""
185+
186+
# set a unique node identifier.
187+
__identifier__ = 'Data'
188+
189+
# set the initial default node name.
190+
NODE_NAME = 'Dict Functions'
191+
192+
module_functions = get_functions_from_type(list)
193+
194+
def __init__(self):
195+
super(DictFunctionsNode, self).__init__()
196+
197+
198+
class TupleFunctionsNode(ModuleNode):
199+
"""
200+
Tuple functions node.
201+
"""
202+
203+
# set a unique node identifier.
204+
__identifier__ = 'Data'
205+
206+
# set the initial default node name.
207+
NODE_NAME = 'Tuple Functions'
208+
209+
module_functions = get_functions_from_type(tuple)
210+
211+
def __init__(self):
212+
super(TupleFunctionsNode, self).__init__()
213+
214+
215+
if __name__ == "__main__":
216+
s = "[2,2]"
217+
print(numpy.zeros(eval(s)))
218+
pass

0 commit comments

Comments
 (0)