E5ErrorMessage: improved the functionality to be able to cope with error message from threads.

Sat, 30 Jun 2018 17:40:08 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 30 Jun 2018 17:40:08 +0200
changeset 6391
0b91857640ed
parent 6390
355b89e9bfad
child 6392
872c6f9de9b6

E5ErrorMessage: improved the functionality to be able to cope with error message from threads.

APIs/Python3/eric6.api file | annotate | diff | comparison | revisions
Documentation/Help/source.qch file | annotate | diff | comparison | revisions
Documentation/Help/source.qhp file | annotate | diff | comparison | revisions
Documentation/Source/eric6.E5Gui.E5ErrorMessage.html file | annotate | diff | comparison | revisions
E5Gui/E5ErrorMessage.py file | annotate | diff | comparison | revisions
--- a/APIs/Python3/eric6.api	Sat Jun 30 17:02:52 2018 +0200
+++ b/APIs/Python3/eric6.api	Sat Jun 30 17:40:08 2018 +0200
@@ -885,7 +885,12 @@
 eric6.E5Gui.E5ErrorMessage.E5ErrorMessage.editMessageFilters?4()
 eric6.E5Gui.E5ErrorMessage.E5ErrorMessage.showMessage?4(message, msgType="")
 eric6.E5Gui.E5ErrorMessage.E5ErrorMessage?1(parent=None)
+eric6.E5Gui.E5ErrorMessage._defaultFilters?8
+eric6.E5Gui.E5ErrorMessage._filterSettings?8
+eric6.E5Gui.E5ErrorMessage._msgHandlerDialog?8
+eric6.E5Gui.E5ErrorMessage._origMsgHandler?8
 eric6.E5Gui.E5ErrorMessage.editMessageFilters?4()
+eric6.E5Gui.E5ErrorMessage.filterMessage?4(message)
 eric6.E5Gui.E5ErrorMessage.messageHandler?4(msgType, *args)
 eric6.E5Gui.E5ErrorMessage.messageHandlerInstalled?4()
 eric6.E5Gui.E5ErrorMessage.qtHandler?4()
Binary file Documentation/Help/source.qch has changed
--- a/Documentation/Help/source.qhp	Sat Jun 30 17:02:52 2018 +0200
+++ b/Documentation/Help/source.qhp	Sat Jun 30 17:40:08 2018 +0200
@@ -4410,7 +4410,6 @@
       <keyword name="E5ErrorMessage" id="E5ErrorMessage" ref="eric6.E5Gui.E5ErrorMessage.html#E5ErrorMessage" />
       <keyword name="E5ErrorMessage (Constructor)" id="E5ErrorMessage (Constructor)" ref="eric6.E5Gui.E5ErrorMessage.html#E5ErrorMessage.__init__" />
       <keyword name="E5ErrorMessage (Module)" id="E5ErrorMessage (Module)" ref="eric6.E5Gui.E5ErrorMessage.html" />
-      <keyword name="E5ErrorMessage.__filterMessage" id="E5ErrorMessage.__filterMessage" ref="eric6.E5Gui.E5ErrorMessage.html#E5ErrorMessage.__filterMessage" />
       <keyword name="E5ErrorMessage.editMessageFilters" id="E5ErrorMessage.editMessageFilters" ref="eric6.E5Gui.E5ErrorMessage.html#E5ErrorMessage.editMessageFilters" />
       <keyword name="E5ErrorMessage.showMessage" id="E5ErrorMessage.showMessage" ref="eric6.E5Gui.E5ErrorMessage.html#E5ErrorMessage.showMessage" />
       <keyword name="E5ErrorMessageFilterDialog" id="E5ErrorMessageFilterDialog" ref="eric6.E5Gui.E5ErrorMessageFilterDialog.html#E5ErrorMessageFilterDialog" />
@@ -18703,6 +18702,7 @@
       <keyword name="filterAnsiSequences" id="filterAnsiSequences" ref="eric6.Utilities.__init__.html#filterAnsiSequences" />
       <keyword name="filterCharsFromFilename" id="filterCharsFromFilename" ref="eric6.Helpviewer.HelpUtilities.html#filterCharsFromFilename" />
       <keyword name="filterCharsFromFilename" id="filterCharsFromFilename" ref="eric6.WebBrowser.Tools.WebBrowserTools.html#filterCharsFromFilename" />
+      <keyword name="filterMessage" id="filterMessage" ref="eric6.E5Gui.E5ErrorMessage.html#filterMessage" />
       <keyword name="find_module" id="find_module" ref="eric6.Utilities.ClassBrowsers.__init__.html#find_module" />
       <keyword name="find_module" id="find_module" ref="eric6.Utilities.ModuleParser.html#find_module" />
       <keyword name="find_moduleAsStr" id="find_moduleAsStr" ref="eric6.Globals.compatibility_fixes.html#find_moduleAsStr" />
--- a/Documentation/Source/eric6.E5Gui.E5ErrorMessage.html	Sat Jun 30 17:02:52 2018 +0200
+++ b/Documentation/Source/eric6.E5Gui.E5ErrorMessage.html	Sat Jun 30 17:40:08 2018 +0200
@@ -25,7 +25,7 @@
 </p>
 <h3>Global Attributes</h3>
 <table>
-<tr><td>__msgHandlerDialog</td></tr><tr><td>__origMsgHandler</td></tr>
+<tr><td>_defaultFilters</td></tr><tr><td>_filterSettings</td></tr><tr><td>_msgHandlerDialog</td></tr><tr><td>_origMsgHandler</td></tr>
 </table>
 <h3>Classes</h3>
 <table>
@@ -40,6 +40,9 @@
 <td><a href="#editMessageFilters">editMessageFilters</a></td>
 <td>Module function to edit the list of message filters.</td>
 </tr><tr>
+<td><a href="#filterMessage">filterMessage</a></td>
+<td>Module function to filter messages.</td>
+</tr><tr>
 <td><a href="#messageHandler">messageHandler</a></td>
 <td>Module function handling messages.</td>
 </tr><tr>
@@ -72,9 +75,6 @@
 <td><a href="#E5ErrorMessage.__init__">E5ErrorMessage</a></td>
 <td>Constructor</td>
 </tr><tr>
-<td><a href="#E5ErrorMessage.__filterMessage">__filterMessage</a></td>
-<td>Private method to filter messages.</td>
-</tr><tr>
 <td><a href="#E5ErrorMessage.editMessageFilters">editMessageFilters</a></td>
 <td>Public method to edit the list of message filters.</td>
 </tr><tr>
@@ -92,25 +92,9 @@
 <p>
         Constructor
 </p><dl>
-<dt><i>parent</i></dt>
+<dt><i>parent</i> (QWidget)</dt>
 <dd>
-reference to the parent widget (QWidget)
-</dd>
-</dl><a NAME="E5ErrorMessage.__filterMessage" ID="E5ErrorMessage.__filterMessage"></a>
-<h4>E5ErrorMessage.__filterMessage</h4>
-<b>__filterMessage</b>(<i>message</i>)
-<p>
-        Private method to filter messages.
-</p><dl>
-<dt><i>message</i></dt>
-<dd>
-message to be checked (string)
-</dd>
-</dl><dl>
-<dt>Returns:</dt>
-<dd>
-flag indicating that the message should be filtered out
-            (boolean)
+reference to the parent widget
 </dd>
 </dl><a NAME="E5ErrorMessage.editMessageFilters" ID="E5ErrorMessage.editMessageFilters"></a>
 <h4>E5ErrorMessage.editMessageFilters</h4>
@@ -123,12 +107,12 @@
 <p>
         Public method to show a message.
 </p><dl>
-<dt><i>message</i></dt>
+<dt><i>message</i> (str)</dt>
 <dd>
-error message to be shown (string)
-</dd><dt><i>msgType</i></dt>
+error message to be shown
+</dd><dt><i>msgType</i> (str)</dt>
 <dd>
-type of the error message (string)
+type of the error message
 </dd>
 </dl>
 <div align="right"><a href="#top">Up</a></div>
@@ -141,20 +125,42 @@
 </p>
 <div align="right"><a href="#top">Up</a></div>
 <hr /><hr />
+<a NAME="filterMessage" ID="filterMessage"></a>
+<h2>filterMessage</h2>
+<b>filterMessage</b>(<i>message</i>)
+<p>
+    Module function to filter messages.
+</p><dl>
+<dt><i>message</i> (str)</dt>
+<dd>
+message to be checked
+</dd>
+</dl><dl>
+<dt>Returns:</dt>
+<dd>
+flag indicating that the message should be filtered out
+</dd>
+</dl><dl>
+<dt>Return Type:</dt>
+<dd>
+bool
+</dd>
+</dl>
+<div align="right"><a href="#top">Up</a></div>
+<hr /><hr />
 <a NAME="messageHandler" ID="messageHandler"></a>
 <h2>messageHandler</h2>
 <b>messageHandler</b>(<i>msgType, *args</i>)
 <p>
     Module function handling messages.
 </p><dl>
-<dt><i>msgType</i></dt>
+<dt><i>msgType</i> (int, QtMsgType)</dt>
 <dd>
-type of the message (integer, QtMsgType)
-</dd><dt><i>args</i></dt>
+type of the message
+</dd><dt><i>args</i> (PyQt4: bytes; PyQt5: tuple of (QMessageLogContext, bytes))</dt>
 <dd>
-message handler arguments, for PyQt4 message to be shown
-        (bytes), for PyQt5 context information (QMessageLogContext) and
-        message to be shown (bytes)
+message handler arguments, for PyQt4 message to be shown, for
+        PyQt5 context information and message to be shown
 </dd>
 </dl>
 <div align="right"><a href="#top">Up</a></div>
@@ -167,7 +173,12 @@
 </p><dl>
 <dt>Returns:</dt>
 <dd>
-flag indicating an installed message handler (boolean)
+flag indicating an installed message handler
+</dd>
+</dl><dl>
+<dt>Return Type:</dt>
+<dd>
+bool
 </dd>
 </dl>
 <div align="right"><a href="#top">Up</a></div>
@@ -181,7 +192,12 @@
 </p><dl>
 <dt>Returns:</dt>
 <dd>
-reference to the message handler dialog (E5ErrorMessage)
+reference to the message handler dialog
+</dd>
+</dl><dl>
+<dt>Return Type:</dt>
+<dd>
+E5ErrorMessage
 </dd>
 </dl>
 <div align="right"><a href="#top">Up</a></div>
--- a/E5Gui/E5ErrorMessage.py	Sat Jun 30 17:02:52 2018 +0200
+++ b/E5Gui/E5ErrorMessage.py	Sat Jun 30 17:40:08 2018 +0200
@@ -17,8 +17,43 @@
 import Utilities
 
 
-__msgHandlerDialog = None
-__origMsgHandler = None
+_msgHandlerDialog = None
+_origMsgHandler = None
+
+_filterSettings = QSettings(
+    QSettings.IniFormat,
+    QSettings.UserScope,
+    Globals.settingsNameOrganization,
+    "eric6messagefilters")
+_defaultFilters = [
+    "QFont::",
+    "QCocoaMenu::removeMenuItem",
+    "QCocoaMenu::insertNative",
+    ",type id:",
+    "Remote debugging server started successfully",
+    "Uncaught SecurityError:",
+    "Content Security Policy",
+    "QXcbClipboard:",
+    "QXcbConnection: XCB error",
+    "libpng warning: iCCP:",
+]
+
+
+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
+    @rtype bool
+    """
+    for filterStr in Globals.toList(_filterSettings.value(
+            "MessageFilters", _defaultFilters)):
+        if filterStr in message:
+            return True
+    
+    return False
 
 
 class E5ErrorMessage(QErrorMessage):
@@ -29,52 +64,21 @@
         """
         Constructor
         
-        @param parent reference to the parent widget (QWidget)
+        @param parent reference to the parent widget
+        @type QWidget
         """
         super(E5ErrorMessage, self).__init__(parent)
-        
-        self.settings = QSettings(
-            QSettings.IniFormat,
-            QSettings.UserScope,
-            Globals.settingsNameOrganization,
-            "eric6messagefilters")
-        
-        self.__defaultFilters = [
-            "QFont::",
-            "QCocoaMenu::removeMenuItem",
-            "QCocoaMenu::insertNative",
-            ",type id:",
-            "Remote debugging server started successfully",
-            "Uncaught SecurityError:",
-            "Content Security Policy",
-            "QXcbClipboard:",
-            "QXcbConnection: XCB error",
-            "libpng warning: iCCP:",
-        ]
-    
-    def __filterMessage(self, message):
-        """
-        Private method to filter messages.
-        
-        @param message message to be checked (string)
-        @return flag indicating that the message should be filtered out
-            (boolean)
-        """
-        for filterStr in Globals.toList(self.settings.value(
-                "MessageFilters", self.__defaultFilters)):
-            if filterStr in message:
-                return True
-        
-        return False
     
     def showMessage(self, message, msgType=""):
         """
         Public method to show a message.
         
-        @param message error message to be shown (string)
-        @param msgType type of the error message (string)
+        @param message error message to be shown
+        @type str
+        @param msgType type of the error message
+        @type str
         """
-        if not self.__filterMessage(message):
+        if not filterMessage(message):
             if msgType:
                 super(E5ErrorMessage, self).showMessage(message, msgType)
             else:
@@ -86,29 +90,30 @@
         """
         from .E5ErrorMessageFilterDialog import E5ErrorMessageFilterDialog
         dlg = E5ErrorMessageFilterDialog(
-            Globals.toList(self.settings.value(
-                "MessageFilters", self.__defaultFilters)),
-            self.__defaultFilters)
+            Globals.toList(_filterSettings.value(
+                "MessageFilters", _defaultFilters)),
+            _defaultFilters)
         if dlg.exec_() == QDialog.Accepted:
             filters = dlg.getFilters()
-            self.settings.setValue("MessageFilters", filters)
+            _filterSettings.setValue("MessageFilters", filters)
 
 
 def messageHandler(msgType, *args):
     """
     Module function handling messages.
     
-    @param msgType type of the message (integer, QtMsgType)
-    @param args message handler arguments, for PyQt4 message to be shown
-        (bytes), for PyQt5 context information (QMessageLogContext) and
-        message to be shown (bytes)
+    @param msgType type of the message
+    @type  int, QtMsgType
+    @param args message handler arguments, for PyQt4 message to be shown, for
+        PyQt5 context information and message to be shown
+    @type PyQt4: bytes; PyQt5: tuple of (QMessageLogContext, bytes)
     """
     if len(args) == 2:
         context = args[0]
         message = args[1]
     else:
         message = args[0]
-    if __msgHandlerDialog:
+    if _msgHandlerDialog:
         try:
             if msgType == QtDebugMsg:
                 messageType = "Debug Message:"
@@ -120,6 +125,8 @@
                 messageType = "Fatal Error:"
             if isinstance(message, bytes):
                 message = Utilities.decodeBytes(message)
+            if filterMessage(message):
+                return
             message = message.replace("\r\n", "<br/>")\
                              .replace("\n", "<br/>")\
                              .replace("\r", "<br/>")
@@ -132,18 +139,18 @@
                 msg = "<p><b>{0}</b></p><p>{1}</p>".format(
                     messageType, Utilities.html_uencode(message))
             if QThread.currentThread() == qApp.thread():
-                __msgHandlerDialog.showMessage(msg)
+                _msgHandlerDialog.showMessage(msg)
             else:
                 QMetaObject.invokeMethod(
-                    __msgHandlerDialog,
+                    _msgHandlerDialog,
                     "showMessage",
                     Qt.QueuedConnection,
                     Q_ARG(str, msg))
             return
         except RuntimeError:
             pass
-    elif __origMsgHandler:
-        __origMsgHandler(msgType, message)
+    elif _origMsgHandler:
+        _origMsgHandler(msgType, message)
         return
     
     if msgType == QtDebugMsg:
@@ -169,24 +176,25 @@
     Module function to install an E5ErrorMessage dialog as the global
     message handler.
     
-    @return reference to the message handler dialog (E5ErrorMessage)
+    @return reference to the message handler dialog
+    @rtype E5ErrorMessage
     """
-    global __msgHandlerDialog, __origMsgHandler
+    global _msgHandlerDialog, _origMsgHandler
     
-    if __msgHandlerDialog is None:
+    if _msgHandlerDialog is None:
         # Install an E5ErrorMessage dialog as the global message handler.
-        __msgHandlerDialog = E5ErrorMessage()
-        __origMsgHandler = qInstallMessageHandler(messageHandler)
+        _msgHandlerDialog = E5ErrorMessage()
+        _origMsgHandler = qInstallMessageHandler(messageHandler)
     
-    return __msgHandlerDialog
+    return _msgHandlerDialog
 
 
 def editMessageFilters():
     """
     Module function to edit the list of message filters.
     """
-    if __msgHandlerDialog:
-        __msgHandlerDialog.editMessageFilters()
+    if _msgHandlerDialog:
+        _msgHandlerDialog.editMessageFilters()
     else:
         print("No message handler installed.")
 
@@ -195,9 +203,10 @@
     """
     Module function to check, if a message handler was installed.
     
-    @return flag indicating an installed message handler (boolean)
+    @return flag indicating an installed message handler
+    @rtype bool
     """
-    return __msgHandlerDialog is not None
+    return _msgHandlerDialog is not None
 
 #
 # eflag: noqa = M801

eric ide

mercurial