##// END OF EJS Templates
inputhook_qt4: handle KeyboardInterrupt in a way compatible with 'readline'....
Christian Boos -
Show More
@@ -208,23 +208,16 b' class InputHookManager(object):'
208 # #481).
208 # #481).
209
209
210 # Note that we can't let KeyboardInterrupt escape from that
210 # Note that we can't let KeyboardInterrupt escape from that
211 # hook, (no exception can't be raised from within a ctypes
211 # hook, as no exception can be raised from within a ctypes
212 # python callback). We need to make a compromise: a trapped
212 # python callback. We need to make a compromise: a trapped
213 # KeyboardInterrupt will prevent the input hook to re-enter
213 # KeyboardInterrupt will temporarily disable the input hook
214 # the exec loop, until we start over with a new prompt line.
214 # until we start over with a new prompt line with a second
215 # This means one needs a double CTRL+C to get back to the
215 # CTRL+C.
216 # prompt.
217
216
218 got_kbdint = [False]
217 got_kbdint = [False]
219
218
220 def preprompthook_qt4(self):
221 got_kbdint[0] = False
222 ipapi.get().set_hook('pre_prompt_hook', preprompthook_qt4)
223
224 def inputhook_qt4():
219 def inputhook_qt4():
225 try:
220 try:
226 if got_kbdint[0]:
227 return 0
228 app.processEvents(QtCore.QEventLoop.AllEvents, 300)
221 app.processEvents(QtCore.QEventLoop.AllEvents, 300)
229 if not stdin_ready():
222 if not stdin_ready():
230 timer = QtCore.QTimer()
223 timer = QtCore.QTimer()
@@ -235,11 +228,17 b' class InputHookManager(object):'
235 timer.stop()
228 timer.stop()
236 except KeyboardInterrupt:
229 except KeyboardInterrupt:
237 got_kbdint[0] = True
230 got_kbdint[0] = True
231 self.clear_inputhook()
238 print("\n(event loop interrupted - "
232 print("\n(event loop interrupted - "
239 "hit CTRL+C again to clear the prompt)")
233 "hit CTRL+C again to clear the prompt)")
240 return 0
234 return 0
241 self.set_inputhook(inputhook_qt4)
235 self.set_inputhook(inputhook_qt4)
242
236
237 def preprompthook_qt4(ishell):
238 if got_kbdint[0]:
239 self.set_inputhook(inputhook_qt4)
240 ipapi.get().set_hook('pre_prompt_hook', preprompthook_qt4)
241
243 self._current_gui = GUI_QT4
242 self._current_gui = GUI_QT4
244 app._in_event_loop = True
243 app._in_event_loop = True
245 self._apps[GUI_QT4] = app
244 self._apps[GUI_QT4] = app
General Comments 0
You need to be logged in to leave comments. Login now