From c29be67845ccb17093565bec961202b3a44e37db Mon Sep 17 00:00:00 2001 From: tassaron Date: Thu, 21 Apr 2022 15:49:18 -0400 Subject: fix RuntimeError caused by QUndoStack signal handler --- src/gui/mainwindow.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/gui') diff --git a/src/gui/mainwindow.py b/src/gui/mainwindow.py index 53a6bd1..75534c2 100644 --- a/src/gui/mainwindow.py +++ b/src/gui/mainwindow.py @@ -108,6 +108,15 @@ class MainWindow(QtWidgets.QMainWindow): # Begin decorating the window and connecting events componentList = self.window.listWidget_componentList + # Undo Feature + def toggleUndoButtonEnabled(*_): + """ Enable/disable undo button depending on whether UndoStack contains Actions """ + try: + undoButton.setEnabled(self.undoStack.count()) + except RuntimeError: + # program is probably in midst of exiting + pass + style = window.pushButton_undo.style() undoButton = window.pushButton_undo undoButton.setIcon( @@ -115,9 +124,7 @@ class MainWindow(QtWidgets.QMainWindow): ) undoButton.clicked.connect(self.undoStack.undo) undoButton.setEnabled(False) - self.undoStack.cleanChanged.connect( - lambda change: undoButton.setEnabled(self.undoStack.count()) - ) + self.undoStack.cleanChanged.connect(toggleUndoButtonEnabled) self.undoMenu = QMenu() self.undoMenu.addAction( self.undoStack.createUndoAction(self) @@ -130,6 +137,7 @@ class MainWindow(QtWidgets.QMainWindow): lambda _: self.showUndoStack() ) undoButton.setMenu(self.undoMenu) + # end of Undo Feature style = window.pushButton_listMoveUp.style() window.pushButton_listMoveUp.setIcon( -- cgit v1.2.3