Skip to content

Commit

Permalink
Merge pull request #210 from dlyongemallo/export_tikz_conditional
Browse files Browse the repository at this point in the history
Enable "File|Export to tikz" only if active panel is a proof.
  • Loading branch information
jvdwetering authored Dec 11, 2023
2 parents b882a07 + 8dcde69 commit 836272f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/test_mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
6 changes: 6 additions & 0 deletions zxlive/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,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)

Expand Down Expand Up @@ -254,6 +257,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:
Expand Down Expand Up @@ -319,6 +323,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:
Expand Down

0 comments on commit 836272f

Please sign in to comment.