Show More
@@ -51,14 +51,38 b' def _stdin_ready_other():' | |||
|
51 | 51 | """Return True, assuming there's something to read on stdin.""" |
|
52 | 52 | return True # |
|
53 | 53 | |
|
54 | ||
|
55 | def _ignore_CTRL_C_posix(): | |
|
56 | """Ignore CTRL+C (SIGINT).""" | |
|
57 | signal.signal(signal.SIGINT, signal.SIG_IGN) | |
|
58 | ||
|
59 | def _allow_CTRL_C_posix(): | |
|
60 | """Take CTRL+C into account (SIGINT).""" | |
|
61 | signal.signal(signal.SIGINT, signal.default_int_handler) | |
|
62 | ||
|
63 | def _ignore_CTRL_C_other(): | |
|
64 | """Ignore CTRL+C (not implemented).""" | |
|
65 | pass | |
|
66 | ||
|
67 | def _allow_CTRL_C_other(): | |
|
68 | """Take CTRL+C into account (not implemented).""" | |
|
69 | pass | |
|
70 | ||
|
54 | 71 | if os.name == 'posix': |
|
55 | 72 | import select |
|
73 | import signal | |
|
56 | 74 | stdin_ready = _stdin_ready_posix |
|
75 | ignore_CTRL_C = _ignore_CTRL_C_posix | |
|
76 | allow_CTRL_C = _allow_CTRL_C_posix | |
|
57 | 77 | elif os.name == 'nt': |
|
58 | 78 | import msvcrt |
|
59 | 79 | stdin_ready = _stdin_ready_nt |
|
80 | ignore_CTRL_C = _ignore_CTRL_C_other | |
|
81 | allow_CTRL_C = _allow_CTRL_C_other | |
|
60 | 82 | else: |
|
61 | 83 | stdin_ready = _stdin_ready_other |
|
84 | ignore_CTRL_C = _ignore_CTRL_C_other | |
|
85 | allow_CTRL_C = _allow_CTRL_C_other | |
|
62 | 86 | |
|
63 | 87 | |
|
64 | 88 | #----------------------------------------------------------------------------- |
@@ -94,6 +118,11 b' class InputHookManager(object):' | |||
|
94 | 118 | |
|
95 | 119 | def set_inputhook(self, callback): |
|
96 | 120 | """Set PyOS_InputHook to callback and return the previous one.""" |
|
121 | # On platforms with 'readline' support, it's all too likely to | |
|
122 | # have a KeyboardInterrupt signal delivered *even before* an | |
|
123 | # initial ``try:`` clause in the callback can be executed, so | |
|
124 | # we need to disable CTRL+C in this situation. | |
|
125 | ignore_CTRL_C() | |
|
97 | 126 | self._callback = callback |
|
98 | 127 | self._callback_pyfunctype = self.PYFUNC(callback) |
|
99 | 128 | pyos_inputhook_ptr = self.get_pyos_inputhook() |
@@ -117,6 +146,7 b' class InputHookManager(object):' | |||
|
117 | 146 | pyos_inputhook_ptr = self.get_pyos_inputhook() |
|
118 | 147 | original = self.get_pyos_inputhook_as_func() |
|
119 | 148 | pyos_inputhook_ptr.value = ctypes.c_void_p(None).value |
|
149 | allow_CTRL_C() | |
|
120 | 150 | self._reset() |
|
121 | 151 | return original |
|
122 | 152 |
@@ -17,7 +17,7 b' Author: Christian Boos' | |||
|
17 | 17 | #----------------------------------------------------------------------------- |
|
18 | 18 | |
|
19 | 19 | from IPython.external.qt_for_kernel import QtCore, QtGui |
|
20 | from IPython.lib.inputhook import stdin_ready | |
|
20 | from IPython.lib.inputhook import allow_CTRL_C, ignore_CTRL_C, stdin_ready | |
|
21 | 21 | |
|
22 | 22 | #----------------------------------------------------------------------------- |
|
23 | 23 | # Code |
@@ -78,6 +78,7 b' def create_inputhook_qt4(mgr, app=None):' | |||
|
78 | 78 | back to a clean prompt line. |
|
79 | 79 | """ |
|
80 | 80 | try: |
|
81 | allow_CTRL_C() | |
|
81 | 82 | app = QtCore.QCoreApplication.instance() |
|
82 | 83 | app.processEvents(QtCore.QEventLoop.AllEvents, 300) |
|
83 | 84 | if not stdin_ready(): |
@@ -88,13 +89,14 b' def create_inputhook_qt4(mgr, app=None):' | |||
|
88 | 89 | app.exec_() |
|
89 | 90 | timer.stop() |
|
90 | 91 | except KeyboardInterrupt: |
|
92 | ignore_CTRL_C() | |
|
91 | 93 | got_kbdint[0] = True |
|
92 | mgr.clear_inputhook() | |
|
93 | 94 | print("\nKeyboardInterrupt - qt4 event loop interrupted!" |
|
94 | 95 | "\n * hit CTRL+C again to clear the prompt" |
|
95 | 96 | "\n * use '%gui none' to disable the event loop" |
|
96 | 97 | " permanently" |
|
97 | 98 | "\n and '%gui qt4' to re-enable it later") |
|
99 | mgr.clear_inputhook() | |
|
98 | 100 | return 0 |
|
99 | 101 | |
|
100 | 102 | def preprompthook_qt4(ishell): |
General Comments 0
You need to be logged in to leave comments.
Login now