From c391e5f2e0afe0fad3bff26491f963559fe49c30 Mon Sep 17 00:00:00 2001 From: John van de Wetering Date: Thu, 30 Nov 2023 13:10:48 +0100 Subject: [PATCH] Now only double-clicking the vertex/edge type selectors changes the type of the selection, mimicking the behaviour of tikzit. --- zxlive/app.py | 2 +- zxlive/editor_base_panel.py | 26 ++++++++++++++++++-------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/zxlive/app.py b/zxlive/app.py index 1ab2f148..6fc133ce 100644 --- a/zxlive/app.py +++ b/zxlive/app.py @@ -20,7 +20,7 @@ from PySide6.QtGui import QIcon import sys -sys.path.insert(0, '../pyzx') # So that it can find a local copy of pyzx +# sys.path.insert(0, '../pyzx') # So that it can find a local copy of pyzx from .mainwindow import MainWindow from .common import get_data, GraphT diff --git a/zxlive/editor_base_panel.py b/zxlive/editor_base_panel.py index 906ba59c..3063b9e6 100644 --- a/zxlive/editor_base_panel.py +++ b/zxlive/editor_base_panel.py @@ -78,16 +78,16 @@ def _toolbar_sections(self) -> Iterator[ToolbarSection]: def create_side_bar(self) -> None: self.sidebar = QSplitter(self) self.sidebar.setOrientation(Qt.Orientation.Vertical) - self.vertex_list = create_list_widget(self, vertices_data(), self._vty_clicked) - self.edge_list = create_list_widget(self, edges_data(), self._ety_clicked) + self.vertex_list = create_list_widget(self, vertices_data(), self._vty_clicked, self._vty_double_clicked) + self.edge_list = create_list_widget(self, edges_data(), self._ety_clicked, self._ety_double_clicked) self.variable_viewer = VariableViewer(self) self.sidebar.addWidget(self.vertex_list) self.sidebar.addWidget(self.edge_list) self.sidebar.addWidget(self.variable_viewer) def update_side_bar(self) -> None: - populate_list_widget(self.vertex_list, vertices_data(), self._vty_clicked) - populate_list_widget(self.edge_list, edges_data(), self._ety_clicked) + populate_list_widget(self.vertex_list, vertices_data(), self._vty_clicked, self._vty_double_clicked) + populate_list_widget(self.edge_list, edges_data(), self._ety_clicked, self._ety_double_clicked) def update_colors(self) -> None: super().update_colors() @@ -98,6 +98,9 @@ def _tool_clicked(self, tool: ToolType) -> None: def _vty_clicked(self, vty: VertexType.Type) -> None: self._curr_vty = vty + + def _vty_double_clicked(self, vty: VertexType.Type) -> None: + self._curr_vty = vty selected = list(self.graph_scene.selected_vertices) if len(selected) > 0: cmd = ChangeNodeType(self.graph_view, selected, vty) @@ -105,6 +108,9 @@ def _vty_clicked(self, vty: VertexType.Type) -> None: def _ety_clicked(self, ety: EdgeType.Type) -> None: self._curr_ety = ety + + def _ety_double_clicked(self, ety: EdgeType.Type) -> None: + self._curr_ety = ety self.graph_scene.curr_ety = ety selected = list(self.graph_scene.selected_edges) if len(selected) > 0: @@ -308,7 +314,9 @@ def toolbar_select_node_edge(parent: EditorBasePanel) -> ToolbarSection: def create_list_widget(parent: EditorBasePanel, data: dict[VertexType.Type, DrawPanelNodeType] | dict[EdgeType.Type, DrawPanelNodeType], - onclick: Callable[[VertexType.Type], None] | Callable[[EdgeType.Type], None]) -> QListWidget: + onclick: Callable[[VertexType.Type], None] | Callable[[EdgeType.Type], None], + ondoubleclick: Callable[[VertexType.Type, None] | Callable[[EdgeType.Type], None]]) \ + -> QListWidget: list_widget = QListWidget(parent) list_widget.setResizeMode(QListView.ResizeMode.Adjust) list_widget.setViewMode(QListView.ViewMode.IconMode) @@ -317,15 +325,16 @@ def create_list_widget(parent: EditorBasePanel, list_widget.setGridSize(QSize(60, 64)) list_widget.setWordWrap(True) list_widget.setIconSize(QSize(24, 24)) - populate_list_widget(list_widget, data, onclick) + populate_list_widget(list_widget, data, onclick, ondoubleclick) list_widget.setCurrentItem(list_widget.item(0)) return list_widget def populate_list_widget(list_widget: QListWidget, data: dict[VertexType.Type, DrawPanelNodeType] | dict[EdgeType.Type, DrawPanelNodeType], - onclick: Callable[[VertexType.Type], None] | Callable[[EdgeType.Type], None]) \ - -> None: + onclick: Callable[[VertexType.Type], None] | Callable[[EdgeType.Type], None], + ondoubleclick: Callable[[VertexType.Type, None] | Callable[[EdgeType.Type], None]]) \ + -> None: row = list_widget.currentRow() list_widget.clear() for typ, value in data.items(): @@ -334,6 +343,7 @@ def populate_list_widget(list_widget: QListWidget, item.setData(Qt.ItemDataRole.UserRole, typ) list_widget.addItem(item) list_widget.itemClicked.connect(lambda x: onclick(x.data(Qt.ItemDataRole.UserRole))) + list_widget.itemDoubleClicked.connect(lambda x: ondoubleclick(x.data(Qt.ItemDataRole.UserRole))) list_widget.setCurrentRow(row)