diff -r e9e7eca7efee -r bf71ee032bb4 src/eric7/EricWidgets/EricMessageBox.py --- a/src/eric7/EricWidgets/EricMessageBox.py Wed Jul 13 11:16:20 2022 +0200 +++ b/src/eric7/EricWidgets/EricMessageBox.py Wed Jul 13 14:55:47 2022 +0200 @@ -19,7 +19,7 @@ Critical = QMessageBox.Icon.Critical Information = QMessageBox.Icon.Information Question = QMessageBox.Icon.Question -Warning = QMessageBox.Icon.Warning # __IGNORE_WARNING_M131__ +Warning = QMessageBox.Icon.Warning # __IGNORE_WARNING_M131__ # QMessageBox.StandardButton Abort = QMessageBox.StandardButton.Abort @@ -63,12 +63,19 @@ """ Class implementing a replacement for QMessageBox. """ - def __init__(self, icon, title, text, modal=False, - buttons=QMessageBox.StandardButton.NoButton, - parent=None): + + def __init__( + self, + icon, + title, + text, + modal=False, + buttons=QMessageBox.StandardButton.NoButton, + parent=None, + ): """ Constructor - + @param icon type of icon to be shown (QMessageBox.Icon) @param title caption of the message box (string) @param text text to be shown by the message box (string) @@ -86,26 +93,32 @@ else: self.setWindowModality(Qt.WindowModality.NonModal) if title == "": - self.setWindowTitle("{0}".format( - QApplication.applicationName())) + self.setWindowTitle("{0}".format(QApplication.applicationName())) else: - self.setWindowTitle("{0} - {1}".format( - QApplication.applicationName(), title)) + self.setWindowTitle( + "{0} - {1}".format(QApplication.applicationName(), title) + ) self.setText(text) self.setStandardButtons(buttons) + ############################################################################### ## Replacements for QMessageBox static methods ## ############################################################################### -def __messageBox(parent, title, text, icon, - buttons=QMessageBox.StandardButton.Ok, - defaultButton=QMessageBox.StandardButton.NoButton, - textFormat=Qt.TextFormat.AutoText): +def __messageBox( + parent, + title, + text, + icon, + buttons=QMessageBox.StandardButton.Ok, + defaultButton=QMessageBox.StandardButton.NoButton, + textFormat=Qt.TextFormat.AutoText, +): """ Private module function to show a modal message box. - + @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) @@ -122,11 +135,11 @@ if parent is not None: messageBox.setWindowModality(Qt.WindowModality.WindowModal) if title == "": - messageBox.setWindowTitle("{0}".format( - QApplication.applicationName())) + messageBox.setWindowTitle("{0}".format(QApplication.applicationName())) else: - messageBox.setWindowTitle("{0} - {1}".format( - QApplication.applicationName(), title)) + messageBox.setWindowTitle( + "{0} - {1}".format(QApplication.applicationName(), title) + ) messageBox.setTextFormat(textFormat) messageBox.setText(text) messageBox.setStandardButtons(buttons) @@ -138,17 +151,22 @@ else: return messageBox.standardButton(clickedButton) + # the about functions are here for consistancy about = QMessageBox.about aboutQt = QMessageBox.aboutQt -def critical(parent, title, text, - buttons=QMessageBox.StandardButton.Ok, - defaultButton=QMessageBox.StandardButton.NoButton): +def critical( + parent, + title, + text, + buttons=QMessageBox.StandardButton.Ok, + defaultButton=QMessageBox.StandardButton.NoButton, +): """ Function to show a modal critical message box. - + @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) @@ -158,16 +176,21 @@ (QMessageBox.StandardButton) @return button pressed by the user (QMessageBox.StandardButton) """ - return __messageBox(parent, title, text, QMessageBox.Icon.Critical, - buttons, defaultButton) + return __messageBox( + parent, title, text, QMessageBox.Icon.Critical, buttons, defaultButton + ) -def information(parent, title, text, - buttons=QMessageBox.StandardButton.Ok, - defaultButton=QMessageBox.StandardButton.NoButton): +def information( + parent, + title, + text, + buttons=QMessageBox.StandardButton.Ok, + defaultButton=QMessageBox.StandardButton.NoButton, +): """ Function to show a modal information message box. - + @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) @@ -177,16 +200,21 @@ (QMessageBox.StandardButton) @return button pressed by the user (QMessageBox.StandardButton) """ - return __messageBox(parent, title, text, QMessageBox.Icon.Information, - buttons, defaultButton) + return __messageBox( + parent, title, text, QMessageBox.Icon.Information, buttons, defaultButton + ) -def question(parent, title, text, - buttons=QMessageBox.StandardButton.Ok, - defaultButton=QMessageBox.StandardButton.NoButton): +def question( + parent, + title, + text, + buttons=QMessageBox.StandardButton.Ok, + defaultButton=QMessageBox.StandardButton.NoButton, +): """ Function to show a modal question message box. - + @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) @@ -196,16 +224,21 @@ (QMessageBox.StandardButton) @return button pressed by the user (QMessageBox.StandardButton) """ - return __messageBox(parent, title, text, QMessageBox.Icon.Question, - buttons, defaultButton) + return __messageBox( + parent, title, text, QMessageBox.Icon.Question, buttons, defaultButton + ) -def warning(parent, title, text, - buttons=QMessageBox.StandardButton.Ok, - defaultButton=QMessageBox.StandardButton.NoButton): +def warning( + parent, + title, + text, + buttons=QMessageBox.StandardButton.Ok, + defaultButton=QMessageBox.StandardButton.NoButton, +): """ Function to show a modal warning message box. - + @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) @@ -215,19 +248,27 @@ (QMessageBox.StandardButton) @return button pressed by the user (QMessageBox.StandardButton) """ - return __messageBox(parent, title, text, QMessageBox.Icon.Warning, - buttons, defaultButton) + return __messageBox( + parent, title, text, QMessageBox.Icon.Warning, buttons, defaultButton + ) + ############################################################################### ## Additional convenience functions ## ############################################################################### -def yesNo(parent, title, text, icon=Question, yesDefault=False, - textFormat=Qt.TextFormat.AutoText): +def yesNo( + parent, + title, + text, + icon=Question, + yesDefault=False, + textFormat=Qt.TextFormat.AutoText, +): """ Function to show a model yes/no message box. - + @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) @@ -241,21 +282,23 @@ """ if icon not in [Critical, Information, Question, Warning]: raise ValueError("Bad value for 'icon' parameter.") - + res = __messageBox( - parent, title, text, icon, + parent, + title, + text, + icon, QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No, - yesDefault and QMessageBox.StandardButton.Yes or - QMessageBox.StandardButton.No, - textFormat) + yesDefault and QMessageBox.StandardButton.Yes or QMessageBox.StandardButton.No, + textFormat, + ) return res == QMessageBox.StandardButton.Yes -def retryAbort(parent, title, text, icon=Question, - textFormat=Qt.TextFormat.AutoText): +def retryAbort(parent, title, text, icon=Question, textFormat=Qt.TextFormat.AutoText): """ Function to show a model abort/retry message box. - + @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) @@ -267,20 +310,23 @@ """ if icon not in [Critical, Information, Question, Warning]: raise ValueError("Bad value for 'icon' parameter.") - + res = __messageBox( - parent, title, text, icon, + parent, + title, + text, + icon, QMessageBox.StandardButton.Retry | QMessageBox.StandardButton.Abort, QMessageBox.StandardButton.Retry, - textFormat) + textFormat, + ) return res == QMessageBox.StandardButton.Retry -def okToClearData(parent, title, text, saveFunc, - textFormat=Qt.TextFormat.AutoText): +def okToClearData(parent, title, text, saveFunc, textFormat=Qt.TextFormat.AutoText): """ 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) @@ -290,12 +336,18 @@ @return flag indicating that it is ok to clear the data (boolean) """ res = __messageBox( - parent, title, text, QMessageBox.Icon.Warning, - (QMessageBox.StandardButton.Abort | - QMessageBox.StandardButton.Discard | - QMessageBox.StandardButton.Save), + parent, + title, + text, + QMessageBox.Icon.Warning, + ( + QMessageBox.StandardButton.Abort + | QMessageBox.StandardButton.Discard + | QMessageBox.StandardButton.Save + ), QMessageBox.StandardButton.Save, - textFormat) + textFormat, + ) if res == QMessageBox.StandardButton.Abort: return False if res == QMessageBox.StandardButton.Save: