@@ -554,10 +554,22 @@ def sceneMousePressEvent(self, event):
554554 return
555555
556556 pos = event .scenePos ()
557- port_items = self ._items_near (pos , PortItem , 5 , 5 )
558- if port_items and self .editable :
559- port = port_items [0 ]
557+ items = self ._items_near (pos , None , 5 , 5 )
560558
559+ # filter from the selection stack in the following order
560+ # "node, port, pipe" this is to avoid selecting items under items.
561+ node , port , pipe = None , None , None
562+ for item in items :
563+ if isinstance (item , AbstractNodeItem ):
564+ node = item
565+ elif isinstance (item , PortItem ):
566+ port = item
567+ elif isinstance (item , Pipe ):
568+ pipe = item
569+ if any ([node , port , pipe ]):
570+ break
571+
572+ if port :
561573 if port .locked :
562574 return
563575
@@ -568,9 +580,8 @@ def sceneMousePressEvent(self, event):
568580 [p .delete () for p in port .connected_pipes ]
569581 return
570582
571- node_items = self ._items_near (pos , AbstractNodeItem , 3 , 3 )
572- if node_items :
573- node = node_items [0 ]
583+ if node :
584+ node_items = self ._items_near (pos , AbstractNodeItem , 3 , 3 )
574585
575586 # record the node positions at selection time.
576587 for n in node_items :
@@ -583,11 +594,10 @@ def sceneMousePressEvent(self, event):
583594 if not isinstance (node , BackdropNodeItem ):
584595 return
585596
586- pipe_items = self ._items_near (pos , Pipe , 3 , 3 )
587- if pipe_items and self .editable :
597+ if pipe :
588598 if not self .LMB_state :
589599 return
590- pipe = pipe_items [ 0 ]
600+
591601 from_port = pipe .port_from_pos (pos , True )
592602
593603 if from_port .locked :
0 commit comments