From 8a6e8bf91525d137157da3e31b0846a5f0903d55 Mon Sep 17 00:00:00 2001 From: Martijn Buijs Date: Thu, 29 Mar 2018 09:58:20 +0200 Subject: [PATCH] Change discard changes dialog to save changes dialog Based on other applications: in case of unsaved changes, ask to 'discard', 'save' or 'cancel' the action. --- labelme/app.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/labelme/app.py b/labelme/app.py index d172ab1..b231e42 100644 --- a/labelme/app.py +++ b/labelme/app.py @@ -965,12 +965,22 @@ class MainWindow(QMainWindow, WindowMixin): return True def mayContinue(self): - return not (self.dirty and not self.discardChangesDialog()) - - def discardChangesDialog(self): - yes, no = QMessageBox.Yes, QMessageBox.No - msg = 'You have unsaved changes, proceed anyway?' - return yes == QMessageBox.warning(self, 'Attention', msg, yes|no) + if not self.dirty: + return True + mb = QMessageBox + msg = 'Save annotations to "{}" before closing?'.format(self.filename) + answer = mb.question(self, + 'Save annotations?', + msg, + mb.Save | mb.Discard | mb.Cancel, + mb.Save) + if answer == mb.Discard: + return True + elif answer == mb.Save: + self.saveFile() + return True + else: # answer == mb.Cancel + return False def errorMessage(self, title, message): return QMessageBox.critical(self, title, -- GitLab