##// END OF EJS Templates
apply comments
Christoph -
Show More
@@ -1,51 +1,49 b''
1 1 import sys
2 2 import os
3 3 from IPython.external.qt_for_kernel import QtCore, QtGui
4 4
5 5 # If we create a QApplication, keep a reference to it so that it doesn't get
6 6 # garbage collected.
7 7 _appref = None
8 8 _already_warned = False
9 9
10 10 def inputhook(context):
11 11 global _appref
12 12 app = QtCore.QCoreApplication.instance()
13 13 if not app:
14 14 if sys.platform == 'linux':
15 try:
16 # DISPLAY or WAYLAND_DISPLAY is set and not empty
17 assert os.environ.get('DISPLAY') or os.environ.get('WAYLAND_DISPLAY')
18 except Exception:
15 if not os.environ.get('DISPLAY') \
16 and not os.environ.get('WAYLAND_DISPLAY'):
19 17 import warnings
20 18 global _already_warned
21 19 if not _already_warned:
22 20 _already_warned = True
23 21 warnings.warn(
24 'The DISPLAY enviroment variable is not set or empty '
25 'and Qt5 requires this enviroment variable. '
26 'Deactivate Qt5 code.'
22 'The DISPLAY or WAYLAND_DISPLAY enviroment variable is '
23 'not set or empty and Qt5 requires this enviroment '
24 'variable. Deactivate Qt5 code.'
27 25 )
28 26 return
29 27 _appref = app = QtGui.QApplication([" "])
30 28 event_loop = QtCore.QEventLoop(app)
31 29
32 30 if sys.platform == 'win32':
33 31 # The QSocketNotifier method doesn't appear to work on Windows.
34 32 # Use polling instead.
35 33 timer = QtCore.QTimer()
36 34 timer.timeout.connect(event_loop.quit)
37 35 while not context.input_is_ready():
38 36 timer.start(50) # 50 ms
39 37 event_loop.exec_()
40 38 timer.stop()
41 39 else:
42 40 # On POSIX platforms, we can use a file descriptor to quit the event
43 41 # loop when there is input ready to read.
44 42 notifier = QtCore.QSocketNotifier(context.fileno(),
45 43 QtCore.QSocketNotifier.Read)
46 44 # connect the callback we care about before we turn it on
47 45 notifier.activated.connect(event_loop.exit)
48 46 notifier.setEnabled(True)
49 47 # only start the event loop we are not already flipped
50 48 if not context.input_is_ready():
51 49 event_loop.exec_()
General Comments 0
You need to be logged in to leave comments. Login now