@@ -9,6 +9,7 @@ class NodeEditor(QtCore.QObject):
99 def __init__ (self , parent ):
1010 super (NodeEditor , self ).__init__ (parent )
1111 self .connection = None
12+ self .port = None
1213 self .scene = None
1314 self ._last_selected = None
1415
@@ -37,16 +38,19 @@ def eventFilter(self, watched, event):
3738 if isinstance (item , Port ):
3839 self .connection = Connection (None )
3940 self .scene .addItem (self .connection )
40- self .connection .start_port = item
41+ # self.connection.start_port = item
42+ self .port = item
4143 self .connection .start_pos = item .scenePos ()
4244 self .connection .end_pos = event .scenePos ()
4345 self .connection .update_path ()
4446 return True
4547
4648 elif isinstance (item , Connection ):
4749 self .connection = Connection (None )
50+ self .connection .start_pos = item .start_pos
4851 self .scene .addItem (self .connection )
49- self .connection .start_port = item .start_port
52+ # self.connection.start_port = item.start_port
53+ self .port = item .start_port
5054 self .connection .end_pos = event .scenePos ()
5155 self .connection .update_start_and_end_pos () # to fix the offset
5256 return True
@@ -94,28 +98,35 @@ def eventFilter(self, watched, event):
9498 elif event .type () == QtCore .QEvent .GraphicsSceneMouseRelease :
9599 if self .connection and event .button () == QtCore .Qt .LeftButton :
96100 item = self .item_at (event .scenePos ())
101+
102+ # connecting a port
97103 if isinstance (item , Port ):
98- start_port = self .connection . start_port
99- end_port = item
104+ if self .port . can_connect_to ( item ):
105+ print ( "Making connection" )
100106
101- if (
102- start_port .node () != end_port .node ()
103- and start_port .is_output () != end_port .is_output ()
104- and not start_port .is_connected (end_port )
105- ):
106- self .connection .end_port = end_port
107+ # delete existing connection on the new port
108+ if item .connection :
109+ item .connection .delete ()
107110
108- self .connection .update_start_and_end_pos ()
109- self .connection = None
111+ # delete existing connection to the original port
112+ self .port .clear_connection ()
113+ item .clear_connection ()
114+
115+ self .connection .start_port = self .port
110116
111- # # Flip them aroud if wired the wrong way
112- # if not self.connection.start_port.is_output():
113- # self.connection.flip_connections()
117+ self .connection .end_port = item
114118
115- return True
119+ self .connection .update_start_and_end_pos ()
120+ self .connection = None
121+ else :
122+ print ("Deleting connection" )
123+ self .connection .delete ()
124+ self .connection = None
116125
117- self .connection .delete ()
126+ if self .connection :
127+ self .connection .delete ()
118128 self .connection = None
129+ self .port = None
119130 return True
120131
121132 return super (NodeEditor , self ).eventFilter (watched , event )
0 commit comments