eric6/E5Gui/E5ErrorMessage.py

Wed, 30 Dec 2020 11:00:44 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 30 Dec 2020 11:00:44 +0100
branch
maintenance
changeset 7924
8a96736d465e
parent 7780
41420f82c0ac
child 8143
2c730d5fd177
permissions
-rw-r--r--

Updated copyright for 2021.

2683
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7924
8a96736d465e Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7780
diff changeset
3 # Copyright (c) 2013 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
2683
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a specialized error message dialog.
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
7252
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
10 from PyQt5.QtCore import (
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
11 qInstallMessageHandler, QtDebugMsg, QtWarningMsg, QtCriticalMsg,
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
12 QtFatalMsg, QThread, QMetaObject, Qt, Q_ARG, QSettings
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
13 )
7761
ed2c67d20328 Eliminated use of qApp in order to prepare for PyQt6 migration.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
14 from PyQt5.QtWidgets import QErrorMessage, QDialog
ed2c67d20328 Eliminated use of qApp in order to prepare for PyQt6 migration.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
15
ed2c67d20328 Eliminated use of qApp in order to prepare for PyQt6 migration.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
16 from E5Gui.E5Application import e5App
2683
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
2697
1cd7fa670b05 Added a dialog to edit the list of unwanted error messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2696
diff changeset
18 import Globals
2683
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 import Utilities
7317
cada9fd4ad3a Error Message Dialog:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7252
diff changeset
20 import Preferences
2683
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22
6391
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
23 _msgHandlerDialog = None
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
24 _origMsgHandler = None
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
25
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
26 _filterSettings = QSettings(
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
27 QSettings.IniFormat,
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
28 QSettings.UserScope,
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
29 Globals.settingsNameOrganization,
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
30 "eric6messagefilters")
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
31 _defaultFilters = [
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
32 "QFont::",
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
33 "QCocoaMenu::removeMenuItem",
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
34 "QCocoaMenu::insertNative",
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
35 ",type id:",
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
36 "Remote debugging server started successfully",
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
37 "Uncaught SecurityError:",
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
38 "Content Security Policy",
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
39 "QXcbClipboard:",
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
40 "QXcbConnection: XCB error",
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
41 "libpng warning: iCCP:",
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
42 ]
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
43
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
44
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
45 def filterMessage(message):
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
46 """
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
47 Module function to filter messages.
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
48
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
49 @param message message to be checked
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
50 @type str
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
51 @return flag indicating that the message should be filtered out
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
52 @rtype bool
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
53 """
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
54 for filterStr in Globals.toList(_filterSettings.value(
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
55 "MessageFilters", _defaultFilters)):
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
56 if filterStr in message:
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
57 return True
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
58
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
59 return False
2683
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 class E5ErrorMessage(QErrorMessage):
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 """
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 Class implementing a specialized error message dialog.
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 """
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 def __init__(self, parent=None):
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 """
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 Constructor
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69
6391
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
70 @param parent reference to the parent widget
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
71 @type QWidget
2683
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 """
2791
a9577f248f04 Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2770
diff changeset
73 super(E5ErrorMessage, self).__init__(parent)
2683
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 def showMessage(self, message, msgType=""):
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 """
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 Public method to show a message.
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78
6391
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
79 @param message error message to be shown
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
80 @type str
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
81 @param msgType type of the error message
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
82 @type str
2683
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 """
6391
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
84 if not filterMessage(message):
2683
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 if msgType:
2791
a9577f248f04 Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2770
diff changeset
86 super(E5ErrorMessage, self).showMessage(message, msgType)
2683
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 else:
2791
a9577f248f04 Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2770
diff changeset
88 super(E5ErrorMessage, self).showMessage(message)
2697
1cd7fa670b05 Added a dialog to edit the list of unwanted error messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2696
diff changeset
89
1cd7fa670b05 Added a dialog to edit the list of unwanted error messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2696
diff changeset
90 def editMessageFilters(self):
1cd7fa670b05 Added a dialog to edit the list of unwanted error messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2696
diff changeset
91 """
1cd7fa670b05 Added a dialog to edit the list of unwanted error messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2696
diff changeset
92 Public method to edit the list of message filters.
1cd7fa670b05 Added a dialog to edit the list of unwanted error messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2696
diff changeset
93 """
1cd7fa670b05 Added a dialog to edit the list of unwanted error messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2696
diff changeset
94 from .E5ErrorMessageFilterDialog import E5ErrorMessageFilterDialog
1cd7fa670b05 Added a dialog to edit the list of unwanted error messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2696
diff changeset
95 dlg = E5ErrorMessageFilterDialog(
6391
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
96 Globals.toList(_filterSettings.value(
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
97 "MessageFilters", _defaultFilters)),
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
98 _defaultFilters)
7759
51aa6c6b66f7 Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
99 if dlg.exec() == QDialog.Accepted:
2697
1cd7fa670b05 Added a dialog to edit the list of unwanted error messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2696
diff changeset
100 filters = dlg.getFilters()
6391
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
101 _filterSettings.setValue("MessageFilters", filters)
2683
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103
7198
684261ef2165 Removed the Qt4 runtime stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
104 def messageHandler(msgType, context, message):
2683
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 """
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 Module function handling messages.
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107
6391
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
108 @param msgType type of the message
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
109 @type int, QtMsgType
7198
684261ef2165 Removed the Qt4 runtime stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
110 @param context context information
684261ef2165 Removed the Qt4 runtime stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
111 @type QMessageLogContext
684261ef2165 Removed the Qt4 runtime stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
112 @param message message to be shown
684261ef2165 Removed the Qt4 runtime stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
113 @type bytes
2683
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 """
6391
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
115 if _msgHandlerDialog:
7319
49ea50a9a61e EditorFilePage: added a button to install the PyMdown extensions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7317
diff changeset
116 if msgType < Preferences.getUI("MinimumMessageTypeSeverity"):
49ea50a9a61e EditorFilePage: added a button to install the PyMdown extensions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7317
diff changeset
117 # severity is lower than configured
49ea50a9a61e EditorFilePage: added a button to install the PyMdown extensions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7317
diff changeset
118 # just ignore the message
49ea50a9a61e EditorFilePage: added a button to install the PyMdown extensions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7317
diff changeset
119 return
49ea50a9a61e EditorFilePage: added a button to install the PyMdown extensions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7317
diff changeset
120
2695
13c6301cbed3 Fixed an issue in the new error message window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2683
diff changeset
121 try:
13c6301cbed3 Fixed an issue in the new error message window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2683
diff changeset
122 if msgType == QtDebugMsg:
5840
36f8973c5a8d Removed the translations from E5ErrorMessage as this causes issues on openSUSE Leap 42.3 (maybe earlier versions as well).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
123 messageType = "Debug Message:"
2695
13c6301cbed3 Fixed an issue in the new error message window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2683
diff changeset
124 elif msgType == QtWarningMsg:
5840
36f8973c5a8d Removed the translations from E5ErrorMessage as this causes issues on openSUSE Leap 42.3 (maybe earlier versions as well).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
125 messageType = "Warning:"
2695
13c6301cbed3 Fixed an issue in the new error message window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2683
diff changeset
126 elif msgType == QtCriticalMsg:
5840
36f8973c5a8d Removed the translations from E5ErrorMessage as this causes issues on openSUSE Leap 42.3 (maybe earlier versions as well).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
127 messageType = "Critical:"
2695
13c6301cbed3 Fixed an issue in the new error message window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2683
diff changeset
128 elif msgType == QtFatalMsg:
5840
36f8973c5a8d Removed the translations from E5ErrorMessage as this causes issues on openSUSE Leap 42.3 (maybe earlier versions as well).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
129 messageType = "Fatal Error:"
2696
c25359355787 Fixed another issue in the new error message dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2695
diff changeset
130 if isinstance(message, bytes):
3663
83e22cb3b312 Fixed a little issue in the error message handler.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3656
diff changeset
131 message = Utilities.decodeBytes(message)
6391
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
132 if filterMessage(message):
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
133 return
7252
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
134 message = (
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
135 message.replace("\r\n", "<br/>")
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
136 .replace("\n", "<br/>")
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
137 .replace("\r", "<br/>")
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
138 )
7198
684261ef2165 Removed the Qt4 runtime stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
139 if context.file is not None:
7252
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
140 msg = (
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
141 "<p><b>{0}</b></p><p>{1}</p><p>File: {2}</p>"
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
142 "<p>Line: {3}</p><p>Function: {4}</p>"
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
143 ).format(messageType, Utilities.html_uencode(message),
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
144 context.file, context.line, context.function)
3776
ccb6eacb50e5 Started adding code to make eric6 usable with PyQt5 and PyQt4.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3687
diff changeset
145 else:
ccb6eacb50e5 Started adding code to make eric6 usable with PyQt5 and PyQt4.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3687
diff changeset
146 msg = "<p><b>{0}</b></p><p>{1}</p>".format(
ccb6eacb50e5 Started adding code to make eric6 usable with PyQt5 and PyQt4.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3687
diff changeset
147 messageType, Utilities.html_uencode(message))
7761
ed2c67d20328 Eliminated use of qApp in order to prepare for PyQt6 migration.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
148 if QThread.currentThread() == e5App().thread():
6391
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
149 _msgHandlerDialog.showMessage(msg)
2695
13c6301cbed3 Fixed an issue in the new error message window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2683
diff changeset
150 else:
13c6301cbed3 Fixed an issue in the new error message window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2683
diff changeset
151 QMetaObject.invokeMethod(
6391
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
152 _msgHandlerDialog,
2695
13c6301cbed3 Fixed an issue in the new error message window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2683
diff changeset
153 "showMessage",
13c6301cbed3 Fixed an issue in the new error message window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2683
diff changeset
154 Qt.QueuedConnection,
13c6301cbed3 Fixed an issue in the new error message window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2683
diff changeset
155 Q_ARG(str, msg))
13c6301cbed3 Fixed an issue in the new error message window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2683
diff changeset
156 return
13c6301cbed3 Fixed an issue in the new error message window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2683
diff changeset
157 except RuntimeError:
13c6301cbed3 Fixed an issue in the new error message window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2683
diff changeset
158 pass
6391
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
159 elif _origMsgHandler:
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
160 _origMsgHandler(msgType, message)
2695
13c6301cbed3 Fixed an issue in the new error message window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2683
diff changeset
161 return
13c6301cbed3 Fixed an issue in the new error message window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2683
diff changeset
162
13c6301cbed3 Fixed an issue in the new error message window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2683
diff changeset
163 if msgType == QtDebugMsg:
5840
36f8973c5a8d Removed the translations from E5ErrorMessage as this causes issues on openSUSE Leap 42.3 (maybe earlier versions as well).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
164 messageType = "Debug Message"
2695
13c6301cbed3 Fixed an issue in the new error message window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2683
diff changeset
165 elif msgType == QtWarningMsg:
5840
36f8973c5a8d Removed the translations from E5ErrorMessage as this causes issues on openSUSE Leap 42.3 (maybe earlier versions as well).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
166 messageType = "Warning"
2695
13c6301cbed3 Fixed an issue in the new error message window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2683
diff changeset
167 elif msgType == QtCriticalMsg:
5840
36f8973c5a8d Removed the translations from E5ErrorMessage as this causes issues on openSUSE Leap 42.3 (maybe earlier versions as well).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
168 messageType = "Critical"
2695
13c6301cbed3 Fixed an issue in the new error message window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2683
diff changeset
169 elif msgType == QtFatalMsg:
5840
36f8973c5a8d Removed the translations from E5ErrorMessage as this causes issues on openSUSE Leap 42.3 (maybe earlier versions as well).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
170 messageType = "Fatal Error"
2696
c25359355787 Fixed another issue in the new error message dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2695
diff changeset
171 if isinstance(message, bytes):
c25359355787 Fixed another issue in the new error message dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2695
diff changeset
172 message = message.decode()
7198
684261ef2165 Removed the Qt4 runtime stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
173 print("{0}: {1} in {2} at line {3} ({4})".format(
684261ef2165 Removed the Qt4 runtime stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
174 messageType, message, context.file, context.line,
684261ef2165 Removed the Qt4 runtime stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
175 context.function))
2683
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 def qtHandler():
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 """
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 Module function to install an E5ErrorMessage dialog as the global
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 message handler.
2953
703452a2876f Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2770
diff changeset
182
6391
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
183 @return reference to the message handler dialog
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
184 @rtype E5ErrorMessage
2683
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 """
6391
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
186 global _msgHandlerDialog, _origMsgHandler
2683
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187
6391
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
188 if _msgHandlerDialog is None:
2683
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 # Install an E5ErrorMessage dialog as the global message handler.
6391
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
190 _msgHandlerDialog = E5ErrorMessage()
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
191 _origMsgHandler = qInstallMessageHandler(messageHandler)
2683
ef93fc7332a2 Added a specialized error message handler allowing to filter messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192
6391
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
193 return _msgHandlerDialog
2697
1cd7fa670b05 Added a dialog to edit the list of unwanted error messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2696
diff changeset
194
1cd7fa670b05 Added a dialog to edit the list of unwanted error messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2696
diff changeset
195
1cd7fa670b05 Added a dialog to edit the list of unwanted error messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2696
diff changeset
196 def editMessageFilters():
1cd7fa670b05 Added a dialog to edit the list of unwanted error messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2696
diff changeset
197 """
1cd7fa670b05 Added a dialog to edit the list of unwanted error messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2696
diff changeset
198 Module function to edit the list of message filters.
1cd7fa670b05 Added a dialog to edit the list of unwanted error messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2696
diff changeset
199 """
6391
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
200 if _msgHandlerDialog:
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
201 _msgHandlerDialog.editMessageFilters()
2697
1cd7fa670b05 Added a dialog to edit the list of unwanted error messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2696
diff changeset
202 else:
5840
36f8973c5a8d Removed the translations from E5ErrorMessage as this causes issues on openSUSE Leap 42.3 (maybe earlier versions as well).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
203 print("No message handler installed.")
2697
1cd7fa670b05 Added a dialog to edit the list of unwanted error messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2696
diff changeset
204
1cd7fa670b05 Added a dialog to edit the list of unwanted error messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2696
diff changeset
205
1cd7fa670b05 Added a dialog to edit the list of unwanted error messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2696
diff changeset
206 def messageHandlerInstalled():
1cd7fa670b05 Added a dialog to edit the list of unwanted error messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2696
diff changeset
207 """
1cd7fa670b05 Added a dialog to edit the list of unwanted error messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2696
diff changeset
208 Module function to check, if a message handler was installed.
1cd7fa670b05 Added a dialog to edit the list of unwanted error messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2696
diff changeset
209
6391
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
210 @return flag indicating an installed message handler
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
211 @rtype bool
2697
1cd7fa670b05 Added a dialog to edit the list of unwanted error messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2696
diff changeset
212 """
6391
0b91857640ed E5ErrorMessage: improved the functionality to be able to cope with error message from threads.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
213 return _msgHandlerDialog is not None
4566
a2e8f3c420ec Dealt with the M801 code style checker messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4241
diff changeset
214
a2e8f3c420ec Dealt with the M801 code style checker messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4241
diff changeset
215 #
a2e8f3c420ec Dealt with the M801 code style checker messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4241
diff changeset
216 # eflag: noqa = M801

eric ide

mercurial