Show More
@@ -51,14 +51,38 b' def _stdin_ready_other():' | |||||
51 | """Return True, assuming there's something to read on stdin.""" |
|
51 | """Return True, assuming there's something to read on stdin.""" | |
52 | return True # |
|
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 | if os.name == 'posix': |
|
71 | if os.name == 'posix': | |
55 | import select |
|
72 | import select | |
|
73 | import signal | |||
56 | stdin_ready = _stdin_ready_posix |
|
74 | stdin_ready = _stdin_ready_posix | |
|
75 | ignore_CTRL_C = _ignore_CTRL_C_posix | |||
|
76 | allow_CTRL_C = _allow_CTRL_C_posix | |||
57 | elif os.name == 'nt': |
|
77 | elif os.name == 'nt': | |
58 | import msvcrt |
|
78 | import msvcrt | |
59 | stdin_ready = _stdin_ready_nt |
|
79 | stdin_ready = _stdin_ready_nt | |
|
80 | ignore_CTRL_C = _ignore_CTRL_C_other | |||
|
81 | allow_CTRL_C = _allow_CTRL_C_other | |||
60 | else: |
|
82 | else: | |
61 | stdin_ready = _stdin_ready_other |
|
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 | def set_inputhook(self, callback): |
|
119 | def set_inputhook(self, callback): | |
96 | """Set PyOS_InputHook to callback and return the previous one.""" |
|
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 | self._callback = callback |
|
126 | self._callback = callback | |
98 | self._callback_pyfunctype = self.PYFUNC(callback) |
|
127 | self._callback_pyfunctype = self.PYFUNC(callback) | |
99 | pyos_inputhook_ptr = self.get_pyos_inputhook() |
|
128 | pyos_inputhook_ptr = self.get_pyos_inputhook() | |
@@ -117,6 +146,7 b' class InputHookManager(object):' | |||||
117 | pyos_inputhook_ptr = self.get_pyos_inputhook() |
|
146 | pyos_inputhook_ptr = self.get_pyos_inputhook() | |
118 | original = self.get_pyos_inputhook_as_func() |
|
147 | original = self.get_pyos_inputhook_as_func() | |
119 | pyos_inputhook_ptr.value = ctypes.c_void_p(None).value |
|
148 | pyos_inputhook_ptr.value = ctypes.c_void_p(None).value | |
|
149 | allow_CTRL_C() | |||
120 | self._reset() |
|
150 | self._reset() | |
121 | return original |
|
151 | return original | |
122 |
|
152 |
@@ -17,7 +17,7 b' Author: Christian Boos' | |||||
17 | #----------------------------------------------------------------------------- |
|
17 | #----------------------------------------------------------------------------- | |
18 |
|
18 | |||
19 | from IPython.external.qt_for_kernel import QtCore, QtGui |
|
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 | # Code |
|
23 | # Code | |
@@ -78,6 +78,7 b' def create_inputhook_qt4(mgr, app=None):' | |||||
78 | back to a clean prompt line. |
|
78 | back to a clean prompt line. | |
79 | """ |
|
79 | """ | |
80 | try: |
|
80 | try: | |
|
81 | allow_CTRL_C() | |||
81 | app = QtCore.QCoreApplication.instance() |
|
82 | app = QtCore.QCoreApplication.instance() | |
82 | app.processEvents(QtCore.QEventLoop.AllEvents, 300) |
|
83 | app.processEvents(QtCore.QEventLoop.AllEvents, 300) | |
83 | if not stdin_ready(): |
|
84 | if not stdin_ready(): | |
@@ -88,13 +89,14 b' def create_inputhook_qt4(mgr, app=None):' | |||||
88 | app.exec_() |
|
89 | app.exec_() | |
89 | timer.stop() |
|
90 | timer.stop() | |
90 | except KeyboardInterrupt: |
|
91 | except KeyboardInterrupt: | |
|
92 | ignore_CTRL_C() | |||
91 | got_kbdint[0] = True |
|
93 | got_kbdint[0] = True | |
92 | mgr.clear_inputhook() |
|
|||
93 | print("\nKeyboardInterrupt - qt4 event loop interrupted!" |
|
94 | print("\nKeyboardInterrupt - qt4 event loop interrupted!" | |
94 | "\n * hit CTRL+C again to clear the prompt" |
|
95 | "\n * hit CTRL+C again to clear the prompt" | |
95 | "\n * use '%gui none' to disable the event loop" |
|
96 | "\n * use '%gui none' to disable the event loop" | |
96 | " permanently" |
|
97 | " permanently" | |
97 | "\n and '%gui qt4' to re-enable it later") |
|
98 | "\n and '%gui qt4' to re-enable it later") | |
|
99 | mgr.clear_inputhook() | |||
98 | return 0 |
|
100 | return 0 | |
99 |
|
101 | |||
100 | def preprompthook_qt4(ishell): |
|
102 | def preprompthook_qt4(ishell): |
General Comments 0
You need to be logged in to leave comments.
Login now