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