src/eric7/EricWidgets/EricErrorMessage.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
--- a/src/eric7/EricWidgets/EricErrorMessage.py	Wed Jul 13 11:16:20 2022 +0200
+++ b/src/eric7/EricWidgets/EricErrorMessage.py	Wed Jul 13 14:55:47 2022 +0200
@@ -10,8 +10,13 @@
 import contextlib
 
 from PyQt6.QtCore import (
-    qInstallMessageHandler, Qt, Q_ARG, QSettings, QtMsgType, QThread,
-    QMetaObject
+    qInstallMessageHandler,
+    Qt,
+    Q_ARG,
+    QSettings,
+    QtMsgType,
+    QThread,
+    QMetaObject,
 )
 from PyQt6.QtWidgets import QErrorMessage, QDialog
 
@@ -29,7 +34,8 @@
     QSettings.Format.IniFormat,
     QSettings.Scope.UserScope,
     Globals.settingsNameOrganization,
-    "eric7messagefilters")
+    "eric7messagefilters",
+)
 _defaultFilters = [
     "QFont::",
     "QCocoaMenu::removeMenuItem",
@@ -48,7 +54,7 @@
 def filterMessage(message):
     """
     Module function to filter messages.
-    
+
     @param message message to be checked
     @type str
     @return flag indicating that the message should be filtered out
@@ -56,8 +62,8 @@
     """
     return any(
         filterStr in message
-        for filterStr in Globals.toList(_filterSettings.value(
-            "MessageFilters", [])) + _defaultFilters
+        for filterStr in Globals.toList(_filterSettings.value("MessageFilters", []))
+        + _defaultFilters
     )
 
 
@@ -65,19 +71,20 @@
     """
     Class implementing a specialized error message dialog.
     """
+
     def __init__(self, parent=None):
         """
         Constructor
-        
+
         @param parent reference to the parent widget
         @type QWidget
         """
         super().__init__(parent)
-    
+
     def showMessage(self, message, msgType=""):
         """
         Public method to show a message.
-        
+
         @param message error message to be shown
         @type str
         @param msgType type of the error message
@@ -88,15 +95,16 @@
                 super().showMessage(message, msgType)
             else:
                 super().showMessage(message)
-    
+
     def editMessageFilters(self):
         """
         Public method to edit the list of message filters.
         """
         from .EricErrorMessageFilterDialog import EricErrorMessageFilterDialog
+
         dlg = EricErrorMessageFilterDialog(
-            Globals.toList(_filterSettings.value(
-                "MessageFilters", [])))
+            Globals.toList(_filterSettings.value("MessageFilters", []))
+        )
         if dlg.exec() == QDialog.DialogCode.Accepted:
             filters = dlg.getFilters()
             _filterSettings.setValue("MessageFilters", filters)
@@ -105,7 +113,7 @@
 def messageHandler(msgType, context, message):
     """
     Module function handling messages.
-    
+
     @param msgType type of the message
     @type  int, QtMsgType
     @param context context information
@@ -118,7 +126,7 @@
             # severity is lower than configured
             # just ignore the message
             return
-        
+
         with contextlib.suppress(RuntimeError):
             if msgType == QtMsgType.QtDebugMsg:
                 messageType = "Debug Message:"
@@ -143,11 +151,17 @@
                 (
                     "<p><b>{0}</b></p><p>{1}</p><p>File: {2}</p>"
                     "<p>Line: {3}</p><p>Function: {4}</p>"
-                ).format(messageType, Utilities.html_uencode(message),
-                         context.file, context.line, context.function)
-                if context.file is not None else
-                "<p><b>{0}</b></p><p>{1}</p>".format(
-                    messageType, Utilities.html_uencode(message))
+                ).format(
+                    messageType,
+                    Utilities.html_uencode(message),
+                    context.file,
+                    context.line,
+                    context.function,
+                )
+                if context.file is not None
+                else "<p><b>{0}</b></p><p>{1}</p>".format(
+                    messageType, Utilities.html_uencode(message)
+                )
             )
             if QThread.currentThread() == ericApp().thread():
                 _msgHandlerDialog.showMessage(msg)
@@ -156,12 +170,13 @@
                     _msgHandlerDialog,
                     "showMessage",
                     Qt.ConnectionType.QueuedConnection,
-                    Q_ARG(str, msg))
+                    Q_ARG(str, msg),
+                )
             return
     elif _origMsgHandler:
         _origMsgHandler(msgType, message)
         return
-    
+
     if msgType == QtMsgType.QtDebugMsg:
         messageType = "Debug Message"
     elif msgType == QtMsgType.QtInfoMsg:
@@ -174,26 +189,28 @@
         messageType = "Fatal Error"
     if isinstance(message, bytes):
         message = message.decode()
-    print("{0}: {1} in {2} at line {3} ({4})".format(
-        messageType, message, context.file, context.line,
-        context.function))
+    print(
+        "{0}: {1} in {2} at line {3} ({4})".format(
+            messageType, message, context.file, context.line, context.function
+        )
+    )
 
 
 def qtHandler():
     """
     Module function to install an EricErrorMessage dialog as the global
     message handler.
-    
+
     @return reference to the message handler dialog
     @rtype EricErrorMessage
     """
     global _msgHandlerDialog, _origMsgHandler
-    
+
     if _msgHandlerDialog is None:
         # Install an EricErrorMessage dialog as the global message handler.
         _msgHandlerDialog = EricErrorMessage()
         _origMsgHandler = qInstallMessageHandler(messageHandler)
-    
+
     return _msgHandlerDialog
 
 
@@ -210,11 +227,12 @@
 def messageHandlerInstalled():
     """
     Module function to check, if a message handler was installed.
-    
+
     @return flag indicating an installed message handler
     @rtype bool
     """
     return _msgHandlerDialog is not None
 
+
 #
 # eflag: noqa = M801

eric ide

mercurial