From 8dcde696d1996d892b3c241766984617405e564e Mon Sep 17 00:00:00 2001 From: David Yonge-Mallo Date: Sun, 10 Dec 2023 09:59:23 +0100 Subject: [PATCH] Enable "File|Export to tikz" only if active panel is a proof. --- test/test_mainwindow.py | 18 ++++++++++++++++++ zxlive/mainwindow.py | 6 ++++++ 2 files changed, 24 insertions(+) diff --git a/test/test_mainwindow.py b/test/test_mainwindow.py index f63ece63..793c8cde 100644 --- a/test/test_mainwindow.py +++ b/test/test_mainwindow.py @@ -66,8 +66,26 @@ def test_undo_redo_actions(app: MainWindow) -> None: def test_start_derivation(app: MainWindow, qtbot: QtBot) -> None: + # Demo graph is not a proof, so export to tikz should be disabled. assert app.active_panel is not None assert isinstance(app.active_panel, GraphEditPanel) + assert not app.export_tikz_proof.isEnabled() + + # Start a derivation. Export to tikz is enabled. qtbot.mouseClick(app.active_panel.start_derivation, QtCore.Qt.MouseButton.LeftButton) assert app.tab_widget.count() == 2 assert isinstance(app.active_panel, ProofPanel) + assert app.export_tikz_proof.isEnabled() + + # Switch to the demo graph tab. Export to tikz is disabled. + app.tab_widget.setCurrentIndex(0) + assert not app.export_tikz_proof.isEnabled() + + # Switch back to the proof tab. Export to tikz is enabled. + app.tab_widget.setCurrentIndex(1) + assert app.export_tikz_proof.isEnabled() + + # Close the proof tab. Export to tikz is disabled. + app.close_action.trigger() + assert app.tab_widget.count() == 1 + assert not app.export_tikz_proof.isEnabled() diff --git a/zxlive/mainwindow.py b/zxlive/mainwindow.py index 55111ac4..73097ecc 100644 --- a/zxlive/mainwindow.py +++ b/zxlive/mainwindow.py @@ -181,6 +181,9 @@ def _reset_menus(self, has_active_tab: bool) -> None: self.fit_view_action.setEnabled(has_active_tab) self.show_matrix_action.setEnabled(has_active_tab) + # Export to tikz is enabled only if there is a proof in the active tab. + self.export_tikz_proof.setEnabled(has_active_tab and isinstance(self.active_panel, ProofPanel)) + # Paste is enabled only if there is something in the clipboard. self.paste_action.setEnabled(has_active_tab and self.copied_graph is not None) @@ -253,6 +256,7 @@ def tab_changed(self, i: int) -> None: self._redo_changed() if self.active_panel: self.active_panel.update_colors() + self._reset_menus(True) def _undo_changed(self) -> None: if self.active_panel: @@ -318,6 +322,8 @@ def close_tab(self, i: int) -> bool: self.tab_widget.removeTab(i) if self.tab_widget.count() == 0: self._reset_menus(False) + else: + self._reset_menus(True) return True def handle_save_file_action(self) -> bool: