-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_node.py
More file actions
55 lines (40 loc) · 1.78 KB
/
node_node.py
File metadata and controls
55 lines (40 loc) · 1.78 KB
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
from node_graphics_node import customgraphics_node
from node_content_widget import customgraphics_nodeContentWdiget
from node_socket import Socket, LEFT_TOP, LEFT_BOTTOM, RIGHT_TOP, RIGHT_BOTTOM
class Node():
def __init__(self, scene, title="Undefined Node", inputs=[], outputs=[]):
self.scene = scene
self.title = title
self.content = customgraphics_nodeContentWdiget()
self.graphicNode = customgraphics_node(self)
self.scene.addNode(self)
self.scene.graphicScene.addItem(self.graphicNode)
# self.graphicNode.title = "Edited"
self.socket_spacing = 22
# Create sockets for inputs and outputs
self.inputs = []
self.outputs = []
counter = 0
for item in inputs:
socket = Socket(node=self, index=counter, position=LEFT_BOTTOM)
counter += 1
self.inputs.append(socket)
counter = 0
for item in outputs:
socket = Socket(node=self, index=counter, position=RIGHT_TOP)
counter += 1
self.outputs.append(socket)
@property
def pos(self):
return self.graphicNode.pos() # QPintF
def setPos(self, x, y):
self.graphicNode.setPos(x, y)
def getSocketPosition(self, index, position):
x = 0 if position in (LEFT_TOP, LEFT_BOTTOM) else self.graphicNode.width
if position in (LEFT_BOTTOM, RIGHT_BOTTOM):
# Start from bottom
y = self.graphicNode.height - self.graphicNode.edge_size - self.graphicNode._padding - index * self.socket_spacing
else:
# Start from top
y = self.graphicNode.title_height + self.graphicNode._padding + self.graphicNode.edge_size + index*self.socket_spacing
return x,y