##// END OF EJS Templates
Backport PR #12842: Reclaim sys.excepthook for interactive shell in %gui qt
Matthias Bussonnier -
Show More
@@ -1,6 +1,7 b''
1 import sys
1 import sys
2 import os
2 import os
3 from IPython.external.qt_for_kernel import QtCore, QtGui
3 from IPython.external.qt_for_kernel import QtCore, QtGui
4 from IPython import get_ipython
4
5
5 # If we create a QApplication, keep a reference to it so that it doesn't get
6 # If we create a QApplication, keep a reference to it so that it doesn't get
6 # garbage collected.
7 # garbage collected.
@@ -8,6 +9,12 b' _appref = None'
8 _already_warned = False
9 _already_warned = False
9
10
10
11
12 def _reclaim_excepthook():
13 shell = get_ipython()
14 if shell is not None:
15 sys.excepthook = shell.excepthook
16
17
11 def inputhook(context):
18 def inputhook(context):
12 global _appref
19 global _appref
13 app = QtCore.QCoreApplication.instance()
20 app = QtCore.QCoreApplication.instance()
@@ -27,6 +34,13 b' def inputhook(context):'
27 return
34 return
28 QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
35 QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
29 _appref = app = QtGui.QApplication([" "])
36 _appref = app = QtGui.QApplication([" "])
37
38 # "reclaim" IPython sys.excepthook after event loop starts
39 # without this, it defaults back to BaseIPythonApplication.excepthook
40 # and exceptions in the Qt event loop are rendered without traceback
41 # formatting and look like "bug in IPython".
42 QtCore.QTimer.singleShot(0, _reclaim_excepthook)
43
30 event_loop = QtCore.QEventLoop(app)
44 event_loop = QtCore.QEventLoop(app)
31
45
32 if sys.platform == 'win32':
46 if sys.platform == 'win32':
General Comments 0
You need to be logged in to leave comments. Login now