-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwarn.py
More file actions
29 lines (22 loc) · 988 Bytes
/
warn.py
File metadata and controls
29 lines (22 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""A way of making warnings friendlier with Qt."""
import warnings
from PyQt4.QtGui import QMessageBox
from utils import _
def warn_qt(message, category, filename, lineno, file_=None, line=None):
"Warning handler to show a Qt QMessageBox."
if type(message) == tuple:
window, message = message
else:
window = None
msg = _('%(message)s\n\n(From %(file)s, line %(line)s)') % {
'message': message, 'file': filename, 'line': lineno}
# Potential danger point: if the QApplication hasn't been initialised yet
# this will abort and there's no way I can stop it as far as I can tell -
# try..except doesn't help.
QMessageBox.warning(window, _('PortableApps.com Development Toolkit'), msg,
QMessageBox.Ok)
def set_warnings_qt():
"Set warnings to trigger warn_qt."
#old_showwarning = warnings.showwarning
warnings.showwarning = warn_qt
warnings.simplefilter('always') # Always warn, not just first time