forked from LeGoffLoic/Nodz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nodz_demo.py
175 lines (116 loc) · 5.09 KB
/
nodz_demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
from Qt import QtCore
import nodz_main
nodz = nodz_main.Nodz(None)
# nodz.loadConfig(filePath='')
nodz.initialize()
nodz.show()
######################################################################
# Test signals
######################################################################
# Nodes
@QtCore.Slot(str)
def on_nodeCreated(nodeName):
print 'node created : ', nodeName
@QtCore.Slot(str)
def on_nodeDeleted(nodeName):
print 'node deleted : ', nodeName
@QtCore.Slot(str, str)
def on_nodeEdited(nodeName, newName):
print 'node edited : {0}, new name : {1}'.format(nodeName, newName)
@QtCore.Slot(str)
def on_nodeSelected(nodesName):
print 'node selected : ', nodesName
# Attrs
@QtCore.Slot(str, int)
def on_attrCreated(nodeName, attrId):
print 'attr created : {0} at index : {1}'.format(nodeName, attrId)
@QtCore.Slot(str, int)
def on_attrDeleted(nodeName, attrId):
print 'attr Deleted : {0} at old index : {1}'.format(nodeName, attrId)
@QtCore.Slot(str, int, int)
def on_attrEdited(nodeName, oldId, newId):
print 'attr Edited : {0} at old index : {1}, new index : {2}'.format(nodeName, oldId, newId)
# Graph
@QtCore.Slot()
def on_graphSaved():
print 'graph saved !'
@QtCore.Slot()
def on_graphLoaded():
print 'graph loaded !'
@QtCore.Slot()
def on_graphCleared():
print 'graph cleared !'
@QtCore.Slot()
def on_graphEvaluated():
print 'graph evaluated !'
# Other
@QtCore.Slot(object)
def on_keyPressed(key):
print 'key pressed : ', key
nodz.signal_NodeCreated.connect(on_nodeCreated)
nodz.signal_NodeDeleted.connect(on_nodeDeleted)
nodz.signal_NodeEdited.connect(on_nodeEdited)
nodz.signal_NodeSelected.connect(on_nodeSelected)
nodz.signal_AttrCreated.connect(on_attrCreated)
nodz.signal_AttrDeleted.connect(on_attrDeleted)
nodz.signal_AttrEdited.connect(on_attrEdited)
nodz.signal_GraphSaved.connect(on_graphSaved)
nodz.signal_GraphLoaded.connect(on_graphLoaded)
nodz.signal_GraphCleared.connect(on_graphCleared)
nodz.signal_GraphEvaluated.connect(on_graphEvaluated)
nodz.signal_KeyPressed.connect(on_keyPressed)
######################################################################
# Test API
######################################################################
# Node A
nodeA = nodz.createNode(name='nodeA', preset='node_preset_1', position=None)
nodz.createAttribute(node=nodeA, name='Aattr1', index=-1, preset='attr_preset_1',
plug=True, socket=False, dataType=str)
nodz.createAttribute(node=nodeA, name='Aattr2', index=-1, preset='attr_preset_1',
plug=True, socket=False, dataType=int)
nodz.createAttribute(node=nodeA, name='Aattr3', index=-1, preset='attr_preset_2',
plug=True, socket=False, dataType=int)
nodz.createAttribute(node=nodeA, name='Aattr4', index=-1, preset='attr_preset_2',
plug=True, socket=False, dataType=str)
# Node B
nodeB = nodz.createNode(name='nodeB', preset='node_preset_1')
nodz.createAttribute(node=nodeB, name='Battr1', index=-1, preset='attr_preset_1',
plug=True, socket=False, dataType=str)
nodz.createAttribute(node=nodeB, name='Battr2', index=-1, preset='attr_preset_1',
plug=True, socket=False, dataType=int)
# Node C
nodeC = nodz.createNode(name='nodeC', preset='node_preset_1')
nodz.createAttribute(node=nodeC, name='Cattr1', index=-1, preset='attr_preset_1',
plug=False, socket=True, dataType=str)
nodz.createAttribute(node=nodeC, name='Cattr2', index=-1, preset='attr_preset_1',
plug=True, socket=False, dataType=int)
nodz.createAttribute(node=nodeC, name='Cattr3', index=-1, preset='attr_preset_1',
plug=True, socket=False, dataType=str)
nodz.createAttribute(node=nodeC, name='Cattr4', index=-1, preset='attr_preset_2',
plug=False, socket=True, dataType=str)
nodz.createAttribute(node=nodeC, name='Cattr5', index=-1, preset='attr_preset_2',
plug=False, socket=True, dataType=int)
nodz.createAttribute(node=nodeC, name='Cattr6', index=-1, preset='attr_preset_3',
plug=True, socket=False, dataType=str)
nodz.createAttribute(node=nodeC, name='Cattr7', index=-1, preset='attr_preset_3',
plug=True, socket=False, dataType=str)
nodz.createAttribute(node=nodeC, name='Cattr8', index=-1, preset='attr_preset_3',
plug=True, socket=False, dataType=int)
# Please note that this is a local test so once the graph is cleared
# and reloaded, all the local variables are not valid anymore, which
# means the following code to alter nodes won't work but saving/loading/
# clearing/evaluating will.
# Attributes Edition
nodz.editAttribute(node=nodeC, index=0, newName=None, newIndex=-1)
nodz.editAttribute(node=nodeC, index=-1, newName='NewAttrName', newIndex=None)
# Attributes Deletion
nodz.deleteAttribute(node=nodeC, index=-1)
# Nodes Edition
nodz.editNode(node=nodeC, newName='newNodeName')
# Nodes Deletion
nodz.deleteNode(node=nodeC)
# Graph
print nodz.evaluateGraph()
nodz.saveGraph(filePath='Enter your path')
nodz.clearGraph()
nodz.loadGraph(filePath='Enter your path')