Show More
@@ -196,18 +196,35 b' class InputHookManager(object):' | |||
|
196 | 196 | app = QtGui.QApplication(sys.argv) |
|
197 | 197 | """ |
|
198 | 198 | from IPython.external.qt_for_kernel import QtCore, QtGui |
|
199 | from IPython.core import ipapi | |
|
199 | 200 | |
|
200 | 201 | if app is None: |
|
201 | 202 | app = QtCore.QCoreApplication.instance() |
|
202 | 203 | if app is None: |
|
203 | 204 | app = QtGui.QApplication([" "]) |
|
204 | 205 | |
|
205 |
# Always use |
|
|
206 |
# |
|
|
207 |
# |
|
|
206 | # Always use a custom input hook instead of PyQt4's default | |
|
207 | # one, as it interacts better with readline packages (issue | |
|
208 | # #481). | |
|
209 | ||
|
210 | # Note that we can't let KeyboardInterrupt escape from that | |
|
211 | # hook, (no exception can't be raised from within a ctypes | |
|
212 | # python callback). We need to make a compromise: a trapped | |
|
213 | # KeyboardInterrupt will prevent the input hook to re-enter | |
|
214 | # the exec loop, until we start over with a new prompt line. | |
|
215 | # This means one needs a double CTRL+C to get back to the | |
|
216 | # prompt. | |
|
217 | ||
|
218 | got_kbdint = [False] | |
|
219 | ||
|
220 | def preprompthook_qt4(self): | |
|
221 | got_kbdint[0] = False | |
|
222 | ipapi.get().set_hook('pre_prompt_hook', preprompthook_qt4) | |
|
208 | 223 | |
|
209 | 224 | def inputhook_qt4(): |
|
210 | 225 | try: |
|
226 | if got_kbdint[0]: | |
|
227 | return 0 | |
|
211 | 228 | app.processEvents(QtCore.QEventLoop.AllEvents, 300) |
|
212 | 229 | if not stdin_ready(): |
|
213 | 230 | timer = QtCore.QTimer() |
@@ -217,7 +234,9 b' class InputHookManager(object):' | |||
|
217 | 234 | app.exec_() |
|
218 | 235 | timer.stop() |
|
219 | 236 | except KeyboardInterrupt: |
|
220 | pass | |
|
237 | got_kbdint[0] = True | |
|
238 | print("\n(event loop interrupted - " | |
|
239 | "hit CTRL+C again to clear the prompt)") | |
|
221 | 240 | return 0 |
|
222 | 241 | self.set_inputhook(inputhook_qt4) |
|
223 | 242 |
General Comments 0
You need to be logged in to leave comments.
Login now