447
447
# different callbacks share local variables?
449
449
# Intercept some specific keys.
450
if event.KeyCode == ord('L') and event.ControlDown() :
450
key_code = event.GetKeyCode()
451
if key_code == ord('L') and event.ControlDown() :
451
452
self.scroll_to_bottom()
452
elif event.KeyCode == ord('K') and event.ControlDown() :
453
elif key_code == ord('K') and event.ControlDown() :
453
454
self.input_buffer = ''
454
elif event.KeyCode == ord('A') and event.ControlDown() :
455
elif key_code == ord('A') and event.ControlDown() :
455
456
self.GotoPos(self.GetLength())
456
457
self.SetSelectionStart(self.current_prompt_pos)
457
458
self.SetSelectionEnd(self.GetCurrentPos())
459
elif event.KeyCode == ord('E') and event.ControlDown() :
460
elif key_code == ord('E') and event.ControlDown() :
460
461
self.GotoPos(self.GetLength())
462
elif event.KeyCode == wx.WXK_PAGEUP:
463
elif key_code == wx.WXK_PAGEUP:
463
464
self.ScrollPages(-1)
464
elif event.KeyCode == wx.WXK_PAGEDOWN:
465
elif key_code == wx.WXK_PAGEDOWN:
465
466
self.ScrollPages(1)
466
elif event.KeyCode == wx.WXK_HOME:
467
self.GotoPos(self.GetLength())
468
elif event.KeyCode == wx.WXK_END:
469
self.GotoPos(self.GetLength())
470
elif event.KeyCode == wx.WXK_UP and event.ShiftDown():
467
elif key_code == wx.WXK_HOME:
468
self.GotoPos(self.GetLength())
469
elif key_code == wx.WXK_END:
470
self.GotoPos(self.GetLength())
471
elif key_code == wx.WXK_UP and event.ShiftDown():
471
472
self.ScrollLines(-1)
472
elif event.KeyCode == wx.WXK_DOWN and event.ShiftDown():
473
elif key_code == wx.WXK_DOWN and event.ShiftDown():
473
474
self.ScrollLines(1)
477
478
if self.AutoCompActive():
480
if event.KeyCode in (13, wx.WXK_NUMPAD_ENTER) and \
481
event.Modifiers in (wx.MOD_NONE, wx.MOD_WIN,
481
if key_code in (13, wx.WXK_NUMPAD_ENTER):
482
# XXX: not catching modifiers, to be wx2.6-compatible
484
484
if not self.enter_catched:
485
485
self.CallTipCancel()
486
if event.Modifiers == wx.MOD_SHIFT:
486
if event.ShiftDown():
487
487
# Try to force execution
488
488
self.GotoPos(self.GetLength())
489
489
self.write('\n' + self.continuation_prompt(),
494
494
self.enter_catched = True
496
elif event.KeyCode == wx.WXK_HOME:
497
if event.Modifiers in (wx.MOD_NONE, wx.MOD_WIN):
496
elif key_code == wx.WXK_HOME:
497
if not event.ShiftDown():
498
498
self.GotoPos(self.current_prompt_pos)
501
elif event.Modifiers == wx.MOD_SHIFT:
502
501
# FIXME: This behavior is not ideal: if the selection
503
502
# is already started, it will jump.
504
503
self.SetSelectionStart(self.current_prompt_pos)
505
504
self.SetSelectionEnd(self.GetCurrentPos())
508
elif event.KeyCode == wx.WXK_UP:
507
elif key_code == wx.WXK_UP:
509
508
if self.GetCurrentLine() > self.current_prompt_line:
510
509
if self.GetCurrentLine() == self.current_prompt_line + 1 \
511
510
and self.GetColumn(self.GetCurrentPos()) < \
518
elif event.KeyCode in (wx.WXK_LEFT, wx.WXK_BACK):
517
elif key_code in (wx.WXK_LEFT, wx.WXK_BACK):
519
518
if not self._keep_cursor_in_buffer(self.GetCurrentPos() - 1):
523
elif event.KeyCode == wx.WXK_RIGHT:
522
elif key_code == wx.WXK_RIGHT:
524
523
if not self._keep_cursor_in_buffer(self.GetCurrentPos() + 1):
529
elif event.KeyCode == wx.WXK_DELETE:
528
elif key_code == wx.WXK_DELETE:
530
529
if not self._keep_cursor_in_buffer(self.GetCurrentPos() - 1):
535
534
# Put the cursor back in the edit region
536
535
if not self._keep_cursor_in_buffer():
537
536
if not (self.GetCurrentPos() == self.GetLength()
538
and event.KeyCode == wx.WXK_DELETE):
537
and key_code == wx.WXK_DELETE):