From 688739591951f21cbd99aa99f89c3febeafb57ac Mon Sep 17 00:00:00 2001 From: Razin Shaikh Date: Sun, 30 Jun 2024 18:05:23 +0100 Subject: [PATCH 1/2] create custom selection change signal --- zxlive/graphscene.py | 4 ++++ zxlive/graphview.py | 1 + zxlive/proof_panel.py | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/zxlive/graphscene.py b/zxlive/graphscene.py index 98dae4a1..e809c65a 100644 --- a/zxlive/graphscene.py +++ b/zxlive/graphscene.py @@ -50,6 +50,8 @@ class GraphScene(QGraphicsScene): # Triggers when an edge is dragged. Actual types: EItem, float (old curve_distance), float (new curve_distance) edge_dragged = Signal(object, object, object) + selection_changed_custom = Signal() + def __init__(self) -> None: super().__init__() self.setSceneRect(0, 0, 2*OFFSET_X, 2*OFFSET_Y) @@ -74,6 +76,7 @@ def select_vertices(self, vs: Iterable[VT]) -> None: if isinstance(it, VItem) and it.v in vs: it.setSelected(True) vs.remove(it.v) + self.selection_changed_custom.emit() def set_graph(self, g: GraphT) -> None: """Set the PyZX graph for the scene. @@ -218,6 +221,7 @@ def select_all(self) -> None: """Selects all vertices and edges in the scene.""" for it in self.items(): it.setSelected(True) + self.selection_changed_custom.emit() class EditGraphScene(GraphScene): diff --git a/zxlive/graphview.py b/zxlive/graphview.py index f94734ff..3ceb7dd6 100644 --- a/zxlive/graphview.py +++ b/zxlive/graphview.py @@ -184,6 +184,7 @@ def mouseReleaseEvent(self, e: QMouseEvent) -> None: items = [it for it in self.graph_scene.items(self.mapToScene(rect).boundingRect()) if isinstance(it, VItem)] for it in items: it.setSelected(not (len(items) == 1 or e.modifiers() & Qt.KeyboardModifier.ShiftModifier) or not it.isSelected()) + self.graph_scene.selection_changed_custom.emit() elif self.tool == GraphTool.MagicWand: if self.wand_trace is not None: if not (e.modifiers() & Qt.KeyboardModifier.ShiftModifier): diff --git a/zxlive/proof_panel.py b/zxlive/proof_panel.py index 56b31103..dc24964e 100644 --- a/zxlive/proof_panel.py +++ b/zxlive/proof_panel.py @@ -420,7 +420,7 @@ def _refresh_rewrites_model(self) -> None: self.rewrites_panel.setModel(model) self.rewrites_panel.clicked.connect(model.do_rewrite) # TODO: Right now this calls for every single vertex selected, even if we select many at the same time - self.graph_scene.selectionChanged.connect(lambda: model.executor.submit(model.update_on_selection)) + self.graph_scene.selection_changed_custom.connect(lambda: model.executor.submit(model.update_on_selection)) class ProofStepItemDelegate(QStyledItemDelegate): From fca5ed2140339aae0f9be84084dc459bd51d613a Mon Sep 17 00:00:00 2001 From: Razin Shaikh Date: Sun, 30 Jun 2024 18:12:53 +0100 Subject: [PATCH 2/2] emit selection changed when edge is selected --- zxlive/eitem.py | 1 + zxlive/proof_panel.py | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/zxlive/eitem.py b/zxlive/eitem.py index 7ed72897..8c083640 100644 --- a/zxlive/eitem.py +++ b/zxlive/eitem.py @@ -144,6 +144,7 @@ def mouseReleaseEvent(self, e: QGraphicsSceneMouseEvent) -> None: self._old_pos = None self.is_dragging = False self.is_mouse_pressed = False + self.graph_scene.selection_changed_custom.emit() diff --git a/zxlive/proof_panel.py b/zxlive/proof_panel.py index dc24964e..70202117 100644 --- a/zxlive/proof_panel.py +++ b/zxlive/proof_panel.py @@ -419,7 +419,6 @@ def _refresh_rewrites_model(self) -> None: model = RewriteActionTreeModel.from_dict(action_groups, self) self.rewrites_panel.setModel(model) self.rewrites_panel.clicked.connect(model.do_rewrite) - # TODO: Right now this calls for every single vertex selected, even if we select many at the same time self.graph_scene.selection_changed_custom.connect(lambda: model.executor.submit(model.update_on_selection))