-
Notifications
You must be signed in to change notification settings - Fork 1
/
node_socket.py
76 lines (52 loc) · 2.21 KB
/
node_socket.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
from node_graphics_socket import Qgraphics_socket
from collections import OrderedDict
from node_serializable import Serializable
LEFT_TOP = 1
LEFT_CENTER =2
LEFT_BOTTOM = 3
RIGHT_TOP = 4
RIGHT_CENTER = 5
RIGHT_BOTTOM = 6
class Socket(Serializable):
def __init__(self, node, index = 0, position = LEFT_TOP, socket_type = 1, multi_edges = True, count_on_this_node_side=1, is_input=False) -> None:
super().__init__()
self.node = node
self.index = index
self.position = position
self.socket_type = socket_type
self.is_multi_edges = multi_edges
self.count_on_this_node_side = count_on_this_node_side
self.is_input = is_input
self.is_output = not self.is_input
self.graphics_socket = Qgraphics_socket(self, self.socket_type)
self.setSocketPosition()
self.edges = []
def get_socket_position(self):
res = self.node.get_socket_position(self.index, self.position, self.count_on_this_node_side)
return res
def setSocketPosition(self):
self.graphics_socket.setPos(*self.node.get_socket_position(self.index, self.position, self.count_on_this_node_side))
def add_edge(self, edge):
self.edges.append(edge)
def remove_edge(self, edge):
if edge in self.edges: self.edges.remove(edge)
else: print("!W:", "Socket::removeEdge", "wanna remove edge", edge, "from self.edges but it's not in the list!")
def removeAllEdges(self):
while self.edges:
edge = self.edges.pop(0)
edge.remove()
def __str__(self) -> str:
return "<Socket %s %s..%s>" % ("ME" if self.is_multi_edges else "SE", hex(id(self))[2:5], hex(id(self))[-3:])
def serialize(self):
return OrderedDict([
('id', self.id),
('index', self.index),
('multi_edges', self.is_multi_edges),
('position', self.position),
('socket_type', self.socket_type),
])
def deserialize(self, data, hashmap={}, restore_id = True):
if restore_id:self.id = data['id']
self.is_multi_edges = data['multi_edges']
hashmap[data['id']] = self
return True