Show More
@@ -1,3 +1,4 b'' | |||||
|
1 | import sys | |||
1 | from IPython.external.qt_for_kernel import QtCore, QtGui |
|
2 | from IPython.external.qt_for_kernel import QtCore, QtGui | |
2 |
|
3 | |||
3 | def inputhook(context): |
|
4 | def inputhook(context): | |
@@ -5,7 +6,20 b' def inputhook(context):' | |||||
5 | if not app: |
|
6 | if not app: | |
6 | return |
|
7 | return | |
7 | event_loop = QtCore.QEventLoop(app) |
|
8 | event_loop = QtCore.QEventLoop(app) | |
8 | notifier = QtCore.QSocketNotifier(context.fileno(), QtCore.QSocketNotifier.Read) |
|
9 | ||
9 | notifier.setEnabled(True) |
|
10 | if sys.platform == 'win32': | |
10 | notifier.activated.connect(event_loop.exit) |
|
11 | # The QSocketNotifier method doesn't appear to work on Windows. | |
11 | event_loop.exec_() |
|
12 | # Use polling instead. | |
|
13 | timer = QtCore.QTimer() | |||
|
14 | timer.timeout.connect(event_loop.quit) | |||
|
15 | while not context.input_is_ready(): | |||
|
16 | timer.start(50) # 50 ms | |||
|
17 | event_loop.exec_() | |||
|
18 | timer.stop() | |||
|
19 | else: | |||
|
20 | # On POSIX platforms, we can use a file descriptor to quit the event | |||
|
21 | # loop when there is input ready to read. | |||
|
22 | notifier = QtCore.QSocketNotifier(context.fileno(), QtCore.QSocketNotifier.Read) | |||
|
23 | notifier.setEnabled(True) | |||
|
24 | notifier.activated.connect(event_loop.exit) | |||
|
25 | event_loop.exec_() |
General Comments 0
You need to be logged in to leave comments.
Login now