eric6/E5Gui/E5MessageBox.py

branch
maintenance
changeset 8176
31965986ecd1
parent 8043
0acf98cd089a
parent 8143
2c730d5fd177
child 8273
698ae46f40a4
diff -r e01ae92db699 -r 31965986ecd1 eric6/E5Gui/E5MessageBox.py
--- a/eric6/E5Gui/E5MessageBox.py	Sat Mar 06 10:00:52 2021 +0100
+++ b/eric6/E5Gui/E5MessageBox.py	Sun Mar 28 15:00:11 2021 +0200
@@ -15,46 +15,46 @@
 ###############################################################################
 
 # QMessageBox.Icon
-NoIcon = QMessageBox.NoIcon
-Critical = QMessageBox.Critical
-Information = QMessageBox.Information
-Question = QMessageBox.Question
-Warning = QMessageBox.Warning       # __IGNORE_WARNING_M131__
+NoIcon = QMessageBox.Icon.NoIcon
+Critical = QMessageBox.Icon.Critical
+Information = QMessageBox.Icon.Information
+Question = QMessageBox.Icon.Question
+Warning = QMessageBox.Icon.Warning       # __IGNORE_WARNING_M131__
 
 StandardButtons = QMessageBox.StandardButtons
 
 # QMessageBox.StandardButton
-Abort = QMessageBox.Abort
-Apply = QMessageBox.Apply
-Cancel = QMessageBox.Cancel
-Close = QMessageBox.Close
-Discard = QMessageBox.Discard
-Help = QMessageBox.Help
-Ignore = QMessageBox.Ignore
-No = QMessageBox.No
-NoToAll = QMessageBox.NoToAll
-Ok = QMessageBox.Ok
-Open = QMessageBox.Open
-Reset = QMessageBox.Reset
-RestoreDefaults = QMessageBox.RestoreDefaults
-Retry = QMessageBox.Retry
-Save = QMessageBox.Save
-SaveAll = QMessageBox.SaveAll
-Yes = QMessageBox.Yes
-YesToAll = QMessageBox.YesToAll
-NoButton = QMessageBox.NoButton
+Abort = QMessageBox.StandardButton.Abort
+Apply = QMessageBox.StandardButton.Apply
+Cancel = QMessageBox.StandardButton.Cancel
+Close = QMessageBox.StandardButton.Close
+Discard = QMessageBox.StandardButton.Discard
+Help = QMessageBox.StandardButton.Help
+Ignore = QMessageBox.StandardButton.Ignore
+No = QMessageBox.StandardButton.No
+NoToAll = QMessageBox.StandardButton.NoToAll
+Ok = QMessageBox.StandardButton.Ok
+Open = QMessageBox.StandardButton.Open
+Reset = QMessageBox.StandardButton.Reset
+RestoreDefaults = QMessageBox.StandardButton.RestoreDefaults
+Retry = QMessageBox.StandardButton.Retry
+Save = QMessageBox.StandardButton.Save
+SaveAll = QMessageBox.StandardButton.SaveAll
+Yes = QMessageBox.StandardButton.Yes
+YesToAll = QMessageBox.StandardButton.YesToAll
+NoButton = QMessageBox.StandardButton.NoButton
 
 # QMessageBox.ButtonRole
-AcceptRole = QMessageBox.AcceptRole
-ActionRole = QMessageBox.ActionRole
-ApplyRole = QMessageBox.ApplyRole
-DestructiveRole = QMessageBox.DestructiveRole
-InvalidRole = QMessageBox.InvalidRole
-HelpRole = QMessageBox.HelpRole
-NoRole = QMessageBox.NoRole
-RejectRole = QMessageBox.RejectRole
-ResetRole = QMessageBox.ResetRole
-YesRole = QMessageBox.YesRole
+AcceptRole = QMessageBox.ButtonRole.AcceptRole
+ActionRole = QMessageBox.ButtonRole.ActionRole
+ApplyRole = QMessageBox.ButtonRole.ApplyRole
+DestructiveRole = QMessageBox.ButtonRole.DestructiveRole
+InvalidRole = QMessageBox.ButtonRole.InvalidRole
+HelpRole = QMessageBox.ButtonRole.HelpRole
+NoRole = QMessageBox.ButtonRole.NoRole
+RejectRole = QMessageBox.ButtonRole.RejectRole
+ResetRole = QMessageBox.ButtonRole.ResetRole
+YesRole = QMessageBox.ButtonRole.YesRole
 
 ###############################################################################
 ##  Replacement for the QMessageBox class                                    ##
@@ -66,7 +66,7 @@
     Class implementing a replacement for QMessageBox.
     """
     def __init__(self, icon, title, text, modal=False,
-                 buttons=QMessageBox.NoButton,
+                 buttons=QMessageBox.StandardButton.NoButton,
                  parent=None):
         """
         Constructor
@@ -82,11 +82,11 @@
         self.setIcon(icon)
         if modal:
             if parent is not None:
-                self.setWindowModality(Qt.WindowModal)
+                self.setWindowModality(Qt.WindowModality.WindowModal)
             else:
-                self.setWindowModality(Qt.ApplicationModal)
+                self.setWindowModality(Qt.WindowModality.ApplicationModal)
         else:
-            self.setWindowModality(Qt.NonModal)
+            self.setWindowModality(Qt.WindowModality.NonModal)
         if title == "":
             self.setWindowTitle("{0}".format(
                 QApplication.applicationName()))
@@ -102,8 +102,9 @@
 
 
 def __messageBox(parent, title, text, icon,
-                 buttons=QMessageBox.Ok, defaultButton=QMessageBox.NoButton,
-                 textFormat=Qt.AutoText):
+                 buttons=QMessageBox.StandardButton.Ok,
+                 defaultButton=QMessageBox.StandardButton.NoButton,
+                 textFormat=Qt.TextFormat.AutoText):
     """
     Private module function to show a modal message box.
     
@@ -121,7 +122,7 @@
     messageBox = QMessageBox(parent)
     messageBox.setIcon(icon)
     if parent is not None:
-        messageBox.setWindowModality(Qt.WindowModal)
+        messageBox.setWindowModality(Qt.WindowModality.WindowModal)
     if title == "":
         messageBox.setWindowTitle("{0}".format(
             QApplication.applicationName()))
@@ -135,7 +136,7 @@
     messageBox.exec()
     clickedButton = messageBox.clickedButton()
     if clickedButton is None:
-        return QMessageBox.NoButton
+        return QMessageBox.StandardButton.NoButton
     else:
         return messageBox.standardButton(clickedButton)
 
@@ -145,7 +146,8 @@
 
 
 def critical(parent, title, text,
-             buttons=QMessageBox.Ok, defaultButton=QMessageBox.NoButton):
+             buttons=QMessageBox.StandardButton.Ok,
+             defaultButton=QMessageBox.StandardButton.NoButton):
     """
     Function to show a modal critical message box.
     
@@ -158,12 +160,13 @@
         (QMessageBox.StandardButton)
     @return button pressed by the user (QMessageBox.StandardButton)
     """
-    return __messageBox(parent, title, text, QMessageBox.Critical,
+    return __messageBox(parent, title, text, QMessageBox.Icon.Critical,
                         buttons, defaultButton)
 
 
 def information(parent, title, text,
-                buttons=QMessageBox.Ok, defaultButton=QMessageBox.NoButton):
+                buttons=QMessageBox.StandardButton.Ok,
+                defaultButton=QMessageBox.StandardButton.NoButton):
     """
     Function to show a modal information message box.
     
@@ -176,12 +179,13 @@
         (QMessageBox.StandardButton)
     @return button pressed by the user (QMessageBox.StandardButton)
     """
-    return __messageBox(parent, title, text, QMessageBox.Information,
+    return __messageBox(parent, title, text, QMessageBox.Icon.Information,
                         buttons, defaultButton)
 
 
 def question(parent, title, text,
-             buttons=QMessageBox.Ok, defaultButton=QMessageBox.NoButton):
+             buttons=QMessageBox.StandardButton.Ok,
+             defaultButton=QMessageBox.StandardButton.NoButton):
     """
     Function to show a modal question message box.
     
@@ -194,12 +198,13 @@
         (QMessageBox.StandardButton)
     @return button pressed by the user (QMessageBox.StandardButton)
     """
-    return __messageBox(parent, title, text, QMessageBox.Question,
+    return __messageBox(parent, title, text, QMessageBox.Icon.Question,
                         buttons, defaultButton)
 
 
 def warning(parent, title, text,
-            buttons=QMessageBox.Ok, defaultButton=QMessageBox.NoButton):
+            buttons=QMessageBox.StandardButton.Ok,
+            defaultButton=QMessageBox.StandardButton.NoButton):
     """
     Function to show a modal warning message box.
     
@@ -212,7 +217,7 @@
         (QMessageBox.StandardButton)
     @return button pressed by the user (QMessageBox.StandardButton)
     """
-    return __messageBox(parent, title, text, QMessageBox.Warning,
+    return __messageBox(parent, title, text, QMessageBox.Icon.Warning,
                         buttons, defaultButton)
 
 ###############################################################################
@@ -221,7 +226,7 @@
 
 
 def yesNo(parent, title, text, icon=Question, yesDefault=False,
-          textFormat=Qt.AutoText):
+          textFormat=Qt.TextFormat.AutoText):
     """
     Function to show a model yes/no message box.
     
@@ -241,13 +246,16 @@
     
     res = __messageBox(
         parent, title, text, icon,
-        QMessageBox.StandardButtons(QMessageBox.Yes | QMessageBox.No),
-        yesDefault and QMessageBox.Yes or QMessageBox.No,
+        QMessageBox.StandardButtons(QMessageBox.StandardButton.Yes |
+                                    QMessageBox.StandardButton.No),
+        yesDefault and QMessageBox.StandardButton.Yes or
+        QMessageBox.StandardButton.No,
         textFormat)
-    return res == QMessageBox.Yes
+    return res == QMessageBox.StandardButton.Yes
 
 
-def retryAbort(parent, title, text, icon=Question, textFormat=Qt.AutoText):
+def retryAbort(parent, title, text, icon=Question,
+               textFormat=Qt.TextFormat.AutoText):
     """
     Function to show a model abort/retry message box.
     
@@ -265,13 +273,15 @@
     
     res = __messageBox(
         parent, title, text, icon,
-        QMessageBox.StandardButtons(QMessageBox.Retry | QMessageBox.Abort),
-        QMessageBox.Retry,
+        QMessageBox.StandardButtons(QMessageBox.StandardButton.Retry |
+                                    QMessageBox.StandardButton.Abort),
+        QMessageBox.StandardButton.Retry,
         textFormat)
-    return res == QMessageBox.Retry
+    return res == QMessageBox.StandardButton.Retry
 
 
-def okToClearData(parent, title, text, saveFunc, textFormat=Qt.AutoText):
+def okToClearData(parent, title, text, saveFunc,
+                  textFormat=Qt.TextFormat.AutoText):
     """
     Function to show a model message box to ask for clearing the data.
     
@@ -284,13 +294,15 @@
     @return flag indicating that it is ok to clear the data (boolean)
     """
     res = __messageBox(
-        parent, title, text, QMessageBox.Warning,
+        parent, title, text, QMessageBox.Icon.Warning,
         QMessageBox.StandardButtons(
-            QMessageBox.Abort | QMessageBox.Discard | QMessageBox.Save),
-        QMessageBox.Save,
+            QMessageBox.StandardButton.Abort |
+            QMessageBox.StandardButton.Discard |
+            QMessageBox.StandardButton.Save),
+        QMessageBox.StandardButton.Save,
         textFormat)
-    if res == QMessageBox.Abort:
+    if res == QMessageBox.StandardButton.Abort:
         return False
-    if res == QMessageBox.Save:
+    if res == QMessageBox.StandardButton.Save:
         return saveFunc()
     return True

eric ide

mercurial