Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes undo stack and clears stack on project creation #37

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion rascal2/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import multiprocessing
import sys

Expand Down Expand Up @@ -26,9 +27,16 @@ def ui_execute():
return app.exec()


def log_uncaught_exceptions(exc_type, exc_value, exc_traceback):
"""Qt slots swallows exceptions but this ensures exceptions are logged"""
logging.critical("An unhandled exception occurred!", exc_info=(exc_type, exc_value, exc_traceback))
logging.shutdown()
sys.exit(1)


def main():
multiprocessing.freeze_support()

sys.excepthook = log_uncaught_exceptions
exit_code = ui_execute()
sys.exit(exit_code)

Expand Down
2 changes: 1 addition & 1 deletion rascal2/ui/presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def __init__(self, view):
self.view = view
self.model = MainWindowModel()
self.title = self.view.windowTitle()
self.undo_stack = self.view.undo_stack

def create_project(self, name: str, save_path: str):
"""Creates a new RAT project and controls object then initialise UI.
Expand All @@ -39,6 +38,7 @@ def create_project(self, name: str, save_path: str):
# https://github.com/RascalSoftware/RasCAL-2/issues/15
self.view.init_settings_and_log(save_path)
self.view.setup_mdi()
self.view.undo_stack.clear()

def edit_controls(self, setting: str, value: Any):
"""Edit a setting in the Controls object.
Expand Down
21 changes: 13 additions & 8 deletions rascal2/ui/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,20 @@ def create_actions(self):
self.save_project_action.setIcon(QtGui.QIcon(path_for("save-project.png")))
self.save_project_action.setShortcut(QtGui.QKeySequence.StandardKey.Save)

self.undo_action = QtGui.QAction("&Undo", self)
self.undo_action.setStatusTip("Undo")
self.undo_action = self.undo_stack.createUndoAction(self, "&Undo")
self.undo_action.setStatusTip("Undo the last action")
self.undo_action.setIcon(QtGui.QIcon(path_for("undo.png")))
self.undo_action.setShortcut(QtGui.QKeySequence.StandardKey.Undo)

self.redo_action = QtGui.QAction("&Redo", self)
self.redo_action.setStatusTip("Redo")
self.redo_action = self.undo_stack.createRedoAction(self, "&Redo")
self.redo_action.setStatusTip("Redo the last undone action")
self.redo_action.setIcon(QtGui.QIcon(path_for("redo.png")))
self.redo_action.setShortcut(QtGui.QKeySequence.StandardKey.Redo)

self.undo_view_action = QtGui.QAction("Undo &History", self)
self.undo_view_action.setStatusTip("View undo history")
self.undo_view_action.triggered.connect(self.undo_view.show)

self.export_plots_action = QtGui.QAction("Export", self)
self.export_plots_action.setStatusTip("Export Plots")
self.export_plots_action.setIcon(QtGui.QIcon(path_for("export-plots.png")))
Expand Down Expand Up @@ -128,11 +132,12 @@ def create_menus(self):
file_menu.addSeparator()
file_menu.addAction(self.exit_action)

# edit_menu = main_menu.addMenu("&Edit")
edit_menu = main_menu.addMenu("&Edit")
edit_menu.addAction(self.undo_action)
edit_menu.addAction(self.redo_action)
edit_menu.addAction(self.undo_view_action)

tools_menu = main_menu.addMenu("&Tools")
tools_menu.addAction(self.undo_action)
tools_menu.addAction(self.redo_action)
# tools_menu = main_menu.addMenu("&Tools")

windows_menu = main_menu.addMenu("&Windows")
windows_menu.addAction(self.tile_windows_action)
Expand Down
Loading