Continued replacing QMessageBox.

Fri, 03 Sep 2010 13:39:08 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 03 Sep 2010 13:39:08 +0200
changeset 549
fe99d46d56c8
parent 548
ac7af05dd54a
child 550
22b951013193

Continued replacing QMessageBox.

E5Gui/E5MessageBox.py file | annotate | diff | comparison | revisions
IconEditor/IconEditorWindow.py file | annotate | diff | comparison | revisions
MultiProject/MultiProject.py file | annotate | diff | comparison | revisions
Project/Project.py file | annotate | diff | comparison | revisions
QScintilla/Editor.py file | annotate | diff | comparison | revisions
QScintilla/MiniEditor.py file | annotate | diff | comparison | revisions
ViewManager/ViewManager.py file | annotate | diff | comparison | revisions
--- a/E5Gui/E5MessageBox.py	Fri Sep 03 10:21:47 2010 +0200
+++ b/E5Gui/E5MessageBox.py	Fri Sep 03 13:39:08 2010 +0200
@@ -150,3 +150,24 @@
                        QMessageBox.StandardButtons(QMessageBox.Yes | QMessageBox.No), 
                        yesDefault and QMessageBox.Yes or QMessageBox.No)
     return res == QMessageBox.Yes
+
+def okToClearData(parent, title, text, saveFunc):
+    """
+    Function to show a model message box to ask for clearing the data.
+    
+    @param parent parent widget of the message box (QWidget)
+    @param title caption of the message box (string)
+    @param text text to be shown by the message box (string)
+    @param saveFunc reference to a function performing the save action. It
+        must be a parameterless function returning a flag indicating success.
+    @return flag indicating that it is ok to clear the data (boolean)
+    """
+    res = __messageBox(parent, title, text, QMessageBox.Warning, 
+        QMessageBox.StandardButtons(
+            QMessageBox.Abort | QMessageBox.Discard | QMessageBox.Save), 
+        QMessageBox.Save)
+    if res == QMessageBox.Abort:
+        return False
+    if res == QMessageBox.Save:
+        return saveFunc()
+    return True
--- a/IconEditor/IconEditorWindow.py	Fri Sep 03 10:21:47 2010 +0200
+++ b/IconEditor/IconEditorWindow.py	Fri Sep 03 13:39:08 2010 +0200
@@ -1116,17 +1116,11 @@
         @return flag indicating, if it is ok to continue (boolean)
         """
         if self.__editor.isDirty():
-            ret = E5MessageBox.warning(self,
+            ret = E5MessageBox.okToClearData(self,
                 self.trUtf8("eric5 Icon Editor"),
-                self.trUtf8("""The icon image has unsaved changes."""),
-                QMessageBox.StandardButtons(\
-                    QMessageBox.Abort | \
-                    QMessageBox.Discard | \
-                    QMessageBox.Save),
-                QMessageBox.Save)
-            if ret == QMessageBox.Save:
-                return self.__saveIcon()
-            elif ret == QMessageBox.Abort:
+                self.trUtf8("""The icon image has unsaved changes."""), 
+                self.__saveIcon)
+            if not ret:
                 return False
         return True
     
--- a/MultiProject/MultiProject.py	Fri Sep 03 10:21:47 2010 +0200
+++ b/MultiProject/MultiProject.py	Fri Sep 03 13:39:08 2010 +0200
@@ -624,21 +624,13 @@
         @return flag indicating whether this operation was successful (boolean)
         """
         if self.isDirty():
-            res = E5MessageBox.warning(self.parent(), 
+            res = E5MessageBox.okToClearData(self.parent(), 
                 self.trUtf8("Close Multiproject"),
                 self.trUtf8("The current multiproject has unsaved changes."),
-                QMessageBox.StandardButtons(\
-                    QMessageBox.Abort | \
-                    QMessageBox.Discard | \
-                    QMessageBox.Save),
-                QMessageBox.Save)
-            if res == QMessageBox.Save:
-                return self.saveMultiProject()
-            elif res == QMessageBox.Discard:
+                self.saveMultiProject)
+            if res:
                 self.setDirty(False)
-                return True
-            elif res == QMessageBox.Abort:
-                return False
+            return res
         
         return True
     
--- a/Project/Project.py	Fri Sep 03 10:21:47 2010 +0200
+++ b/Project/Project.py	Fri Sep 03 13:39:08 2010 +0200
@@ -2911,21 +2911,13 @@
         @return flag indicating whether this operation was successful (boolean)
         """
         if self.isDirty():
-            res = E5MessageBox.warning(self.parent(), 
+            res = E5MessageBox.okToClearData(self.parent(), 
                 self.trUtf8("Close Project"),
                 self.trUtf8("The current project has unsaved changes."),
-                QMessageBox.StandardButtons(\
-                    QMessageBox.Abort | \
-                    QMessageBox.Discard | \
-                    QMessageBox.Save),
-                QMessageBox.Save)
-            if res == QMessageBox.Save:
-                return self.saveProject()
-            elif res == QMessageBox.Discard:
+                self.saveProject)
+            if res:
                 self.setDirty(False)
-                return True
-            elif res == QMessageBox.Abort:
-                return False
+            return res
             
         return True
         
--- a/QScintilla/Editor.py	Fri Sep 03 10:21:47 2010 +0200
+++ b/QScintilla/Editor.py	Fri Sep 03 13:39:08 2010 +0200
@@ -2176,22 +2176,14 @@
             fn = self.fileName
             if fn is None:
                 fn = self.noName
-            res = E5MessageBox.warning(self.vm, 
+            res = E5MessageBox.okToClearData(self, 
                 self.trUtf8("File Modified"),
                 self.trUtf8("<p>The file <b>{0}</b> has unsaved changes.</p>")
                     .format(fn),
-                QMessageBox.StandardButtons(\
-                    QMessageBox.Abort | \
-                    QMessageBox.Discard | \
-                    QMessageBox.Save),
-                QMessageBox.Save)
-            if res == QMessageBox.Save:
-                ok = self.saveFile()
-                if ok:
-                    self.vm.setEditorName(self, self.fileName)
-                return ok
-            elif res == QMessageBox.Abort:
-                return False
+                self.saveFile)
+            if res:
+                self.vm.setEditorName(self, self.fileName)
+            return res
         
         return True
         
--- a/QScintilla/MiniEditor.py	Fri Sep 03 10:21:47 2010 +0200
+++ b/QScintilla/MiniEditor.py	Fri Sep 03 13:39:08 2010 +0200
@@ -1476,18 +1476,11 @@
         @return flag indicating, if it is ok to continue (boolean)
         """
         if self.__textEdit.isModified():
-            ret = E5MessageBox.warning(self, 
+            ret = E5MessageBox.okToClearData(self, 
                     self.trUtf8("eric5 Mini Editor"),
                     self.trUtf8("The document has been unsaved changes."),
-                    QMessageBox.StandardButtons(\
-                        QMessageBox.Abort | \
-                        QMessageBox.Discard | \
-                        QMessageBox.Save),
-                    QMessageBox.Save)
-            if ret == QMessageBox.Save:
-                return self.__save()
-            elif ret == QMessageBox.Abort:
-                return False
+                    self.__save)
+            return ret
         return True
     
     def __loadFile(self, fileName, filetype = None):
--- a/ViewManager/ViewManager.py	Fri Sep 03 10:21:47 2010 +0200
+++ b/ViewManager/ViewManager.py	Fri Sep 03 13:39:08 2010 +0200
@@ -14,7 +14,7 @@
 from PyQt4.Qsci import QsciScintilla
 
 from E5Gui.E5Application import e5App
-from E5Gui import E5FileDialog
+from E5Gui import E5FileDialog, E5MessageBox
 
 from Globals import recentNameFiles
 
@@ -2995,25 +2995,17 @@
                 fn = editor.getNoName()
                 autosave = False
             if autosave:
-                res = QMessageBox.Save
+                res = editor.saveFile()
             else:
-                res = E5MessageBox.warning(self.ui,
+                res = E5MessageBox.okToClearData(self.ui,
                     QApplication.translate('ViewManager', "File Modified"),
                     QApplication.translate('ViewManager', 
                         """<p>The file <b>{0}</b> has unsaved changes.</p>""")
                         .format(fn),
-                    QMessageBox.StandardButtons(\
-                        QMessageBox.Abort | \
-                        QMessageBox.Discard | \
-                        QMessageBox.Save),
-                    QMessageBox.Save)
-            if res == QMessageBox.Save:
-                ok = editor.saveFile()
-                if ok:
-                    self.setEditorName(editor, editor.getFileName())
-                return ok
-            elif res == QMessageBox.Abort:
-                return False
+                    editor.saveFile)
+            if res:
+                self.setEditorName(editor, editor.getFileName())
+            return res
         
         return True
         

eric ide

mercurial