18 QtMsgType, |
18 QtMsgType, |
19 qInstallMessageHandler, |
19 qInstallMessageHandler, |
20 ) |
20 ) |
21 from PyQt6.QtWidgets import QDialog, QErrorMessage |
21 from PyQt6.QtWidgets import QDialog, QErrorMessage |
22 |
22 |
23 from eric7 import EricUtilities, Globals, Preferences, Utilities |
23 from eric7 import EricUtilities |
|
24 from eric7.EricCore import EricPreferences |
24 from eric7.EricWidgets.EricApplication import ericApp |
25 from eric7.EricWidgets.EricApplication import ericApp |
25 |
26 |
26 _msgHandlerDialog = None |
27 _msgHandlerDialog = None |
|
28 _msgHandlerMinSeverity = None |
27 _origMsgHandler = None |
29 _origMsgHandler = None |
28 |
30 |
29 _filterSettings = QSettings( |
31 _filterSettings = QSettings( |
30 QSettings.Format.IniFormat, |
32 QSettings.Format.IniFormat, |
31 QSettings.Scope.UserScope, |
33 QSettings.Scope.UserScope, |
32 Globals.settingsNameOrganization, |
34 EricPreferences.settingsNameOrganization, |
33 "eric7messagefilters", |
35 "eric7messagefilters", |
34 ) |
36 ) |
35 _defaultFilters = [ |
37 _defaultFilters = [ |
36 "QFont::", |
38 "QFont::", |
37 "QCocoaMenu::removeMenuItem", |
39 "QCocoaMenu::removeMenuItem", |
119 @type QMessageLogContext |
121 @type QMessageLogContext |
120 @param message message to be shown |
122 @param message message to be shown |
121 @type bytes |
123 @type bytes |
122 """ |
124 """ |
123 if _msgHandlerDialog: |
125 if _msgHandlerDialog: |
124 if msgType.value < Preferences.getUI("MinimumMessageTypeSeverity"): |
126 if msgType.value < _msgHandlerMinSeverity: |
125 # severity is lower than configured |
127 # severity is lower than configured |
126 # just ignore the message |
128 # just ignore the message |
127 return |
129 return |
128 |
130 |
129 with contextlib.suppress(RuntimeError): |
131 with contextlib.suppress(RuntimeError): |
136 elif msgType == QtMsgType.QtCriticalMsg: |
138 elif msgType == QtMsgType.QtCriticalMsg: |
137 messageType = "Critical:" |
139 messageType = "Critical:" |
138 elif msgType == QtMsgType.QtFatalMsg: |
140 elif msgType == QtMsgType.QtFatalMsg: |
139 messageType = "Fatal Error:" |
141 messageType = "Fatal Error:" |
140 if isinstance(message, bytes): |
142 if isinstance(message, bytes): |
141 message = Utilities.decodeBytes(message) |
143 message = EricUtilities.decodeBytes(message) |
142 if filterMessage(message): |
144 if filterMessage(message): |
143 return |
145 return |
144 message = ( |
146 message = ( |
145 message.replace("\r\n", "<br/>") |
147 message.replace("\r\n", "<br/>") |
146 .replace("\n", "<br/>") |
148 .replace("\n", "<br/>") |
193 messageType, message, context.file, context.line, context.function |
195 messageType, message, context.file, context.line, context.function |
194 ) |
196 ) |
195 ) |
197 ) |
196 |
198 |
197 |
199 |
198 def qtHandler(): |
200 def qtHandler(minSeverity): |
199 """ |
201 """ |
200 Module function to install an EricErrorMessage dialog as the global |
202 Module function to install an EricErrorMessage dialog as the global |
201 message handler. |
203 message handler. |
202 |
204 |
|
205 @param minSeverity minimum severity of messages to be shown |
|
206 @type int |
203 @return reference to the message handler dialog |
207 @return reference to the message handler dialog |
204 @rtype EricErrorMessage |
208 @rtype EricErrorMessage |
205 """ |
209 """ |
206 global _msgHandlerDialog, _origMsgHandler |
210 global _msgHandlerDialog, _msgHandlerMinSeverity, _origMsgHandler |
207 |
211 |
208 if _msgHandlerDialog is None: |
212 if _msgHandlerDialog is None: |
209 # Install an EricErrorMessage dialog as the global message handler. |
213 # Install an EricErrorMessage dialog as the global message handler. |
210 _msgHandlerDialog = EricErrorMessage() |
214 _msgHandlerDialog = EricErrorMessage() |
211 _origMsgHandler = qInstallMessageHandler(messageHandler) |
215 _origMsgHandler = qInstallMessageHandler(messageHandler) |
212 |
216 |
|
217 _msgHandlerMinSeverity = minSeverity |
|
218 |
213 return _msgHandlerDialog |
219 return _msgHandlerDialog |
214 |
220 |
215 |
221 |
216 def editMessageFilters(): |
222 def editMessageFilters(): |
217 """ |
223 """ |