##// END OF EJS Templates
FIX: re-order qt eventloop hook a bit...
Thomas A Caswell -
Show More
@@ -1,30 +1,35 b''
1 import sys
1 import sys
2 from IPython.external.qt_for_kernel import QtCore, QtGui
2 from IPython.external.qt_for_kernel import QtCore, QtGui
3
3
4 # If we create a QApplication, keep a reference to it so that it doesn't get
4 # If we create a QApplication, keep a reference to it so that it doesn't get
5 # garbage collected.
5 # garbage collected.
6 _appref = None
6 _appref = None
7
7
8
8 def inputhook(context):
9 def inputhook(context):
9 global _appref
10 global _appref
10 app = QtCore.QCoreApplication.instance()
11 app = QtCore.QCoreApplication.instance()
11 if not app:
12 if not app:
12 _appref = app = QtGui.QApplication([" "])
13 _appref = app = QtGui.QApplication([" "])
13 event_loop = QtCore.QEventLoop(app)
14 event_loop = QtCore.QEventLoop(app)
14
15
15 if sys.platform == 'win32':
16 if sys.platform == 'win32':
16 # The QSocketNotifier method doesn't appear to work on Windows.
17 # The QSocketNotifier method doesn't appear to work on Windows.
17 # Use polling instead.
18 # Use polling instead.
18 timer = QtCore.QTimer()
19 timer = QtCore.QTimer()
19 timer.timeout.connect(event_loop.quit)
20 timer.timeout.connect(event_loop.quit)
20 while not context.input_is_ready():
21 while not context.input_is_ready():
21 timer.start(50) # 50 ms
22 timer.start(50) # 50 ms
22 event_loop.exec_()
23 event_loop.exec_()
23 timer.stop()
24 timer.stop()
24 else:
25 else:
25 # On POSIX platforms, we can use a file descriptor to quit the event
26 # On POSIX platforms, we can use a file descriptor to quit the event
26 # loop when there is input ready to read.
27 # loop when there is input ready to read.
27 notifier = QtCore.QSocketNotifier(context.fileno(), QtCore.QSocketNotifier.Read)
28 notifier = QtCore.QSocketNotifier(context.fileno(),
28 notifier.setEnabled(True)
29 QtCore.QSocketNotifier.Read)
30 # connect the callback we care about before we turn it on
29 notifier.activated.connect(event_loop.exit)
31 notifier.activated.connect(event_loop.exit)
30 event_loop.exec_()
32 notifier.setEnabled(True)
33 # only start the event loop we are not already flipped
34 if not context.input_is_ready():
35 event_loop.exec_()
General Comments 0
You need to be logged in to leave comments. Login now