##// END OF EJS Templates
formatting
Talley Lambert -
Show More
@@ -1,69 +1,70 b''
1 1 import sys
2 2 import os
3 3 from IPython.external.qt_for_kernel import QtCore, QtGui
4 4 from IPython import get_ipython
5 5
6 6 # If we create a QApplication, keep a reference to it so that it doesn't get
7 7 # garbage collected.
8 8 _appref = None
9 9 _already_warned = False
10 10
11 11
12 12 def _reclaim_excepthook():
13 13 shell = get_ipython()
14 14 if shell is not None:
15 15 sys.excepthook = shell.excepthook
16 16
17 17
18 18 def inputhook(context):
19 19 global _appref
20 20 app = QtCore.QCoreApplication.instance()
21 21 if not app:
22 if sys.platform == "linux":
23 if not os.environ.get("DISPLAY") and not os.environ.get("WAYLAND_DISPLAY"):
22 if sys.platform == 'linux':
23 if not os.environ.get('DISPLAY') \
24 and not os.environ.get('WAYLAND_DISPLAY'):
24 25 import warnings
25
26 26 global _already_warned
27 27 if not _already_warned:
28 28 _already_warned = True
29 29 warnings.warn(
30 "The DISPLAY or WAYLAND_DISPLAY environment variable is "
31 "not set or empty and Qt5 requires this environment "
32 "variable. Deactivate Qt5 code."
30 'The DISPLAY or WAYLAND_DISPLAY environment variable is '
31 'not set or empty and Qt5 requires this environment '
32 'variable. Deactivate Qt5 code.'
33 33 )
34 34 return
35 35 QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
36 36 _appref = app = QtGui.QApplication([" "])
37 37
38 38 # "reclaim" IPython sys.excepthook after event loop starts
39 39 # without this, it defaults back to BaseIPythonApplication.excepthook
40 40 # and exceptions in the Qt event loop are rendered without traceback
41 41 # formatting and look like "bug in IPython".
42 42 QtCore.QTimer.singleShot(0, _reclaim_excepthook)
43 43
44 44 event_loop = QtCore.QEventLoop(app)
45 45
46 if sys.platform == "win32":
46 if sys.platform == 'win32':
47 47 # The QSocketNotifier method doesn't appear to work on Windows.
48 48 # Use polling instead.
49 49 timer = QtCore.QTimer()
50 50 timer.timeout.connect(event_loop.quit)
51 51 while not context.input_is_ready():
52 52 timer.start(50) # 50 ms
53 53 event_loop.exec_()
54 54 timer.stop()
55 55 else:
56 56 # On POSIX platforms, we can use a file descriptor to quit the event
57 57 # loop when there is input ready to read.
58 notifier = QtCore.QSocketNotifier(context.fileno(), QtCore.QSocketNotifier.Read)
58 notifier = QtCore.QSocketNotifier(context.fileno(),
59 QtCore.QSocketNotifier.Read)
59 60 try:
60 61 # connect the callback we care about before we turn it on
61 62 # lambda is necessary as PyQT inspect the function signature to know
62 63 # what arguments to pass to. See https://github.com/ipython/ipython/pull/12355
63 64 notifier.activated.connect(lambda: event_loop.exit())
64 65 notifier.setEnabled(True)
65 66 # only start the event loop we are not already flipped
66 67 if not context.input_is_ready():
67 68 event_loop.exec_()
68 69 finally:
69 70 notifier.setEnabled(False)
General Comments 0
You need to be logged in to leave comments. Login now