Skip to content

Commit 4b61089

Browse files
committed
add feature : click port can start live pipe && CTRL key can deselect items
1 parent d0e1ae1 commit 4b61089

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-14
lines changed

NodeGraphQt/qgraphics/port.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ def itemChange(self, change, value):
120120
return super(PortItem, self).itemChange(change, value)
121121

122122
def mousePressEvent(self, event):
123-
if event.modifiers() != QtCore.Qt.AltModifier:
124-
self.viewer_start_connection()
123+
# if event.modifiers() != QtCore.Qt.AltModifier:
124+
# self.viewer_start_connection()
125125
super(PortItem, self).mousePressEvent(event)
126126

127127
def mouseReleaseEvent(self, event):

NodeGraphQt/widgets/viewer.py

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ def mousePressEvent(self, event):
218218
if self.SHIFT_state:
219219
for node in nodes:
220220
node.selected = not node.selected
221+
elif self.CTRL_state:
222+
for node in nodes:
223+
node.selected = False
221224

222225
# update the recorded node positions.
223226
self._node_positions.update(
@@ -234,7 +237,8 @@ def mousePressEvent(self, event):
234237
self._rubber_band.show()
235238

236239
# allow new live pipe with the shift modifier.
237-
if not self.SHIFT_state or self.SHIFT_state and pipes:
240+
if (not self.SHIFT_state and not self.CTRL_state) or\
241+
(self.SHIFT_state and pipes):
238242
super(NodeViewer, self).mousePressEvent(event)
239243

240244
def mouseReleaseEvent(self, event):
@@ -309,12 +313,20 @@ def mouseMoveEvent(self, event):
309313
self.scene().setSelectionArea(path, QtCore.Qt.IntersectsItemShape)
310314
self.scene().update(map_rect)
311315

312-
if self.SHIFT_state:
316+
if self.SHIFT_state or self.CTRL_state:
317+
nodes, pipes = self.selected_items()
318+
313319
for pipe in self._prev_selection_pipes:
314320
pipe.setSelected(True)
315321
for node in self._prev_selection_nodes:
316322
node.selected = True
317323

324+
if self.CTRL_state:
325+
for pipe in pipes:
326+
pipe.setSelected(False)
327+
for node in nodes:
328+
node.selected = False
329+
318330
elif self.LMB_state:
319331
self.COLLIDING_state = False
320332
nodes = self.selected_nodes()
@@ -427,6 +439,9 @@ def sceneMousePressEvent(self, event):
427439
# viewer pan mode.
428440
if self.ALT_state:
429441
return
442+
if self._LIVE_PIPE.isVisible():
443+
self.apply_live_connection(event)
444+
return
430445

431446
pos = event.scenePos()
432447
port_items = self._items_near(pos, PortItem, 5, 5)
@@ -476,6 +491,17 @@ def sceneMousePressEvent(self, event):
476491
def sceneMouseReleaseEvent(self, event):
477492
"""
478493
triggered mouse release event for the scene.
494+
Args:
495+
event (QtWidgets.QGraphicsSceneMouseEvent):
496+
The event handler from the QtWidgets.QGraphicsScene
497+
"""
498+
self.apply_live_connection(event)
499+
500+
# --- port connections ---
501+
502+
def apply_live_connection(self, event):
503+
"""
504+
triggered mouse press/release event for the scene.
479505
- verify to make a the connection Pipe.
480506
481507
Args:
@@ -514,6 +540,10 @@ def sceneMouseReleaseEvent(self, event):
514540
self.end_live_connection()
515541
return
516542

543+
else:
544+
if self._start_port is end_port:
545+
return
546+
517547
# restore connection check.
518548
restore_connection = any([
519549
# if same port type.
@@ -559,8 +589,6 @@ def sceneMouseReleaseEvent(self, event):
559589
self._detached_port = None
560590
self.end_live_connection()
561591

562-
# --- port connections ---
563-
564592
def start_live_connection(self, selected_port):
565593
"""
566594
create new pipe for the connection.
@@ -694,17 +722,13 @@ def all_nodes(self):
694722
return nodes
695723

696724
def selected_nodes(self):
697-
nodes = []
698-
for item in self.scene().selectedItems():
699-
if isinstance(item, AbstractNodeItem):
700-
nodes.append(item)
725+
nodes = [item for item in self.scene().selectedItems()\
726+
if isinstance(item,AbstractNodeItem)]
701727
return nodes
702728

703729
def selected_pipes(self):
704-
pipes = []
705-
for item in self.scene().selectedItems():
706-
if isinstance(item, Pipe):
707-
pipes.append(item)
730+
pipes = [item for item in self.scene().selectedItems()\
731+
if isinstance(item,Pipe)]
708732
return pipes
709733

710734
def selected_items(self):

0 commit comments

Comments
 (0)