From 39b0d68f0933da100c394dac309b6d393e20e622 Mon Sep 17 00:00:00 2001 From: "Chris Rapson (AT)" <4982550+chrisrapson@users.noreply.github.com> Date: Mon, 24 Aug 2020 14:13:16 +1200 Subject: [PATCH] Improve MessageBox when clicking Next/Prev without saving image --- labelImg.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/labelImg.py b/labelImg.py index fa9a2e5c..39d3035f 100755 --- a/labelImg.py +++ b/labelImg.py @@ -1392,12 +1392,22 @@ class MainWindow(QMainWindow, WindowMixin): proc.startDetached(os.path.abspath(__file__)) def mayContinue(self): - return not (self.dirty and not self.discardChangesDialog()) + if not self.dirty: + return True + else: + discardChanges = self.discardChangesDialog() + if discardChanges == QMessageBox.No: + return True + elif discardChanges == QMessageBox.Yes: + self.saveFile() + return True + else: + return False def discardChangesDialog(self): - yes, no = QMessageBox.Yes, QMessageBox.No - msg = u'You have unsaved changes, proceed anyway?' - return yes == QMessageBox.warning(self, u'Attention', msg, yes | no) + yes, no, cancel = QMessageBox.Yes, QMessageBox.No, QMessageBox.Cancel + msg = u'You have unsaved changes, would you like to save them and proceed?\nClick "No" to undo all changes.' + return QMessageBox.warning(self, u'Attention', msg, yes | no | cancel) def errorMessage(self, title, message): return QMessageBox.critical(self, title,