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