##// END OF EJS Templates
BUG: Make the frontend compatible with wxPython 2.6
Gael Varoquaux -
Show More
@@ -447,29 +447,30 b' class ConsoleWidget(editwindow.EditWindow):'
447 # different callbacks share local variables?
447 # different callbacks share local variables?
448
448
449 # Intercept some specific keys.
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 self.scroll_to_bottom()
452 self.scroll_to_bottom()
452 elif event.KeyCode == ord('K') and event.ControlDown() :
453 elif key_code == ord('K') and event.ControlDown() :
453 self.input_buffer = ''
454 self.input_buffer = ''
454 elif event.KeyCode == ord('A') and event.ControlDown() :
455 elif key_code == ord('A') and event.ControlDown() :
455 self.GotoPos(self.GetLength())
456 self.GotoPos(self.GetLength())
456 self.SetSelectionStart(self.current_prompt_pos)
457 self.SetSelectionStart(self.current_prompt_pos)
457 self.SetSelectionEnd(self.GetCurrentPos())
458 self.SetSelectionEnd(self.GetCurrentPos())
458 catched = True
459 catched = True
459 elif event.KeyCode == ord('E') and event.ControlDown() :
460 elif key_code == ord('E') and event.ControlDown() :
460 self.GotoPos(self.GetLength())
461 self.GotoPos(self.GetLength())
461 catched = True
462 catched = True
462 elif event.KeyCode == wx.WXK_PAGEUP:
463 elif key_code == wx.WXK_PAGEUP:
463 self.ScrollPages(-1)
464 self.ScrollPages(-1)
464 elif event.KeyCode == wx.WXK_PAGEDOWN:
465 elif key_code == wx.WXK_PAGEDOWN:
465 self.ScrollPages(1)
466 self.ScrollPages(1)
466 elif event.KeyCode == wx.WXK_HOME:
467 elif key_code == wx.WXK_HOME:
467 self.GotoPos(self.GetLength())
468 self.GotoPos(self.GetLength())
468 elif event.KeyCode == wx.WXK_END:
469 elif key_code == wx.WXK_END:
469 self.GotoPos(self.GetLength())
470 self.GotoPos(self.GetLength())
470 elif event.KeyCode == wx.WXK_UP and event.ShiftDown():
471 elif key_code == wx.WXK_UP and event.ShiftDown():
471 self.ScrollLines(-1)
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 self.ScrollLines(1)
474 self.ScrollLines(1)
474 else:
475 else:
475 catched = False
476 catched = False
@@ -477,13 +478,12 b' class ConsoleWidget(editwindow.EditWindow):'
477 if self.AutoCompActive():
478 if self.AutoCompActive():
478 event.Skip()
479 event.Skip()
479 else:
480 else:
480 if event.KeyCode in (13, wx.WXK_NUMPAD_ENTER) and \
481 if key_code in (13, wx.WXK_NUMPAD_ENTER):
481 event.Modifiers in (wx.MOD_NONE, wx.MOD_WIN,
482 # XXX: not catching modifiers, to be wx2.6-compatible
482 wx.MOD_SHIFT):
483 catched = True
483 catched = True
484 if not self.enter_catched:
484 if not self.enter_catched:
485 self.CallTipCancel()
485 self.CallTipCancel()
486 if event.Modifiers == wx.MOD_SHIFT:
486 if event.ShiftDown():
487 # Try to force execution
487 # Try to force execution
488 self.GotoPos(self.GetLength())
488 self.GotoPos(self.GetLength())
489 self.write('\n' + self.continuation_prompt(),
489 self.write('\n' + self.continuation_prompt(),
@@ -493,19 +493,18 b' class ConsoleWidget(editwindow.EditWindow):'
493 self._on_enter()
493 self._on_enter()
494 self.enter_catched = True
494 self.enter_catched = True
495
495
496 elif event.KeyCode == wx.WXK_HOME:
496 elif key_code == wx.WXK_HOME:
497 if event.Modifiers in (wx.MOD_NONE, wx.MOD_WIN):
497 if not event.ShiftDown():
498 self.GotoPos(self.current_prompt_pos)
498 self.GotoPos(self.current_prompt_pos)
499 catched = True
499 catched = True
500
500 else:
501 elif event.Modifiers == wx.MOD_SHIFT:
502 # FIXME: This behavior is not ideal: if the selection
501 # FIXME: This behavior is not ideal: if the selection
503 # is already started, it will jump.
502 # is already started, it will jump.
504 self.SetSelectionStart(self.current_prompt_pos)
503 self.SetSelectionStart(self.current_prompt_pos)
505 self.SetSelectionEnd(self.GetCurrentPos())
504 self.SetSelectionEnd(self.GetCurrentPos())
506 catched = True
505 catched = True
507
506
508 elif event.KeyCode == wx.WXK_UP:
507 elif key_code == wx.WXK_UP:
509 if self.GetCurrentLine() > self.current_prompt_line:
508 if self.GetCurrentLine() > self.current_prompt_line:
510 if self.GetCurrentLine() == self.current_prompt_line + 1 \
509 if self.GetCurrentLine() == self.current_prompt_line + 1 \
511 and self.GetColumn(self.GetCurrentPos()) < \
510 and self.GetColumn(self.GetCurrentPos()) < \
@@ -515,18 +514,18 b' class ConsoleWidget(editwindow.EditWindow):'
515 event.Skip()
514 event.Skip()
516 catched = True
515 catched = True
517
516
518 elif event.KeyCode in (wx.WXK_LEFT, wx.WXK_BACK):
517 elif key_code in (wx.WXK_LEFT, wx.WXK_BACK):
519 if not self._keep_cursor_in_buffer(self.GetCurrentPos() - 1):
518 if not self._keep_cursor_in_buffer(self.GetCurrentPos() - 1):
520 event.Skip()
519 event.Skip()
521 catched = True
520 catched = True
522
521
523 elif event.KeyCode == wx.WXK_RIGHT:
522 elif key_code == wx.WXK_RIGHT:
524 if not self._keep_cursor_in_buffer(self.GetCurrentPos() + 1):
523 if not self._keep_cursor_in_buffer(self.GetCurrentPos() + 1):
525 event.Skip()
524 event.Skip()
526 catched = True
525 catched = True
527
526
528
527
529 elif event.KeyCode == wx.WXK_DELETE:
528 elif key_code == wx.WXK_DELETE:
530 if not self._keep_cursor_in_buffer(self.GetCurrentPos() - 1):
529 if not self._keep_cursor_in_buffer(self.GetCurrentPos() - 1):
531 event.Skip()
530 event.Skip()
532 catched = True
531 catched = True
@@ -535,7 +534,7 b' class ConsoleWidget(editwindow.EditWindow):'
535 # Put the cursor back in the edit region
534 # Put the cursor back in the edit region
536 if not self._keep_cursor_in_buffer():
535 if not self._keep_cursor_in_buffer():
537 if not (self.GetCurrentPos() == self.GetLength()
536 if not (self.GetCurrentPos() == self.GetLength()
538 and event.KeyCode == wx.WXK_DELETE):
537 and key_code == wx.WXK_DELETE):
539 event.Skip()
538 event.Skip()
540 catched = True
539 catched = True
541
540
@@ -389,7 +389,8 b' class WxController(ConsoleWidget, PrefilterFrontEnd):'
389 """
389 """
390 # FIXME: This method needs to be broken down in smaller ones.
390 # FIXME: This method needs to be broken down in smaller ones.
391 current_line_num = self.GetCurrentLine()
391 current_line_num = self.GetCurrentLine()
392 if event.KeyCode in (ord('c'), ord('C')) and event.ControlDown():
392 key_code = event.GetKeyCode()
393 if key_code in (ord('c'), ord('C')) and event.ControlDown():
393 # Capture Control-C
394 # Capture Control-C
394 if self._input_state == 'subprocess':
395 if self._input_state == 'subprocess':
395 if self.debug:
396 if self.debug:
@@ -403,40 +404,39 b' class WxController(ConsoleWidget, PrefilterFrontEnd):'
403 # XXX: We need to make really sure we
404 # XXX: We need to make really sure we
404 # get back to a prompt.
405 # get back to a prompt.
405 elif self._input_state == 'subprocess' and (
406 elif self._input_state == 'subprocess' and (
406 ( event.KeyCode<256 and
407 ( key_code <256 and not event.ControlDown() )
407 not event.ControlDown() )
408 or
408 or
409 ( event.KeyCode in (ord('d'), ord('D')) and
409 ( key_code in (ord('d'), ord('D')) and
410 event.ControlDown())):
410 event.ControlDown())):
411 # We are running a process, we redirect keys.
411 # We are running a process, we redirect keys.
412 ConsoleWidget._on_key_down(self, event, skip=skip)
412 ConsoleWidget._on_key_down(self, event, skip=skip)
413 char = chr(event.KeyCode)
413 char = chr(key_code)
414 # Deal with some inconsistency in wx keycodes:
414 # Deal with some inconsistency in wx keycodes:
415 if char == '\r':
415 if char == '\r':
416 char = '\n'
416 char = '\n'
417 elif not event.ShiftDown():
417 elif not event.ShiftDown():
418 char = char.lower()
418 char = char.lower()
419 if event.ControlDown() and event.KeyCode in (ord('d'), ord('D')):
419 if event.ControlDown() and key_code in (ord('d'), ord('D')):
420 char = '\04'
420 char = '\04'
421 self._running_process.process.stdin.write(char)
421 self._running_process.process.stdin.write(char)
422 self._running_process.process.stdin.flush()
422 self._running_process.process.stdin.flush()
423 elif event.KeyCode in (ord('('), 57, 53):
423 elif key_code in (ord('('), 57, 53):
424 # Calltips
424 # Calltips
425 event.Skip()
425 event.Skip()
426 self.do_calltip()
426 self.do_calltip()
427 elif self.AutoCompActive() and not event.KeyCode == ord('\t'):
427 elif self.AutoCompActive() and not key_code == ord('\t'):
428 event.Skip()
428 event.Skip()
429 if event.KeyCode in (wx.WXK_BACK, wx.WXK_DELETE):
429 if key_code in (wx.WXK_BACK, wx.WXK_DELETE):
430 wx.CallAfter(self._popup_completion, create=True)
430 wx.CallAfter(self._popup_completion, create=True)
431 elif not event.KeyCode in (wx.WXK_UP, wx.WXK_DOWN, wx.WXK_LEFT,
431 elif not key_code in (wx.WXK_UP, wx.WXK_DOWN, wx.WXK_LEFT,
432 wx.WXK_RIGHT, wx.WXK_ESCAPE):
432 wx.WXK_RIGHT, wx.WXK_ESCAPE):
433 wx.CallAfter(self._popup_completion)
433 wx.CallAfter(self._popup_completion)
434 else:
434 else:
435 # Up history
435 # Up history
436 if event.KeyCode == wx.WXK_UP and (
436 if key_code == wx.WXK_UP and (
437 ( current_line_num == self.current_prompt_line and
437 event.ControlDown() or
438 event.Modifiers in (wx.MOD_NONE, wx.MOD_WIN) )
438 current_line_num == self.current_prompt_line
439 or event.ControlDown() ):
439 ):
440 new_buffer = self.get_history_previous(
440 new_buffer = self.get_history_previous(
441 self.input_buffer)
441 self.input_buffer)
442 if new_buffer is not None:
442 if new_buffer is not None:
@@ -446,9 +446,9 b' class WxController(ConsoleWidget, PrefilterFrontEnd):'
446 self.GotoPos(self.current_prompt_pos)
446 self.GotoPos(self.current_prompt_pos)
447 # Down history
447 # Down history
448 elif event.KeyCode == wx.WXK_DOWN and (
448 elif event.KeyCode == wx.WXK_DOWN and (
449 ( current_line_num == self.LineCount -1 and
449 event.ControlDown() or
450 event.Modifiers in (wx.MOD_NONE, wx.MOD_WIN) )
450 current_line_num == self.LineCount -1
451 or event.ControlDown() ):
451 ):
452 new_buffer = self.get_history_next()
452 new_buffer = self.get_history_next()
453 if new_buffer is not None:
453 if new_buffer is not None:
454 self.input_buffer = new_buffer
454 self.input_buffer = new_buffer
General Comments 0
You need to be logged in to leave comments. Login now