From df2d46507baac7e02603f67b8610117797fb2781 2009-05-16 13:08:31 From: Gael Varoquaux Date: 2009-05-16 13:08:31 Subject: [PATCH] BUG: Make the frontend compatible with wxPython 2.6 --- diff --git a/IPython/frontend/wx/console_widget.py b/IPython/frontend/wx/console_widget.py index 8fcb17a..8c7967f 100644 --- a/IPython/frontend/wx/console_widget.py +++ b/IPython/frontend/wx/console_widget.py @@ -447,29 +447,30 @@ class ConsoleWidget(editwindow.EditWindow): # different callbacks share local variables? # Intercept some specific keys. - if event.KeyCode == ord('L') and event.ControlDown() : + key_code = event.GetKeyCode() + if key_code == ord('L') and event.ControlDown() : self.scroll_to_bottom() - elif event.KeyCode == ord('K') and event.ControlDown() : + elif key_code == ord('K') and event.ControlDown() : self.input_buffer = '' - elif event.KeyCode == ord('A') and event.ControlDown() : + elif key_code == ord('A') and event.ControlDown() : self.GotoPos(self.GetLength()) self.SetSelectionStart(self.current_prompt_pos) self.SetSelectionEnd(self.GetCurrentPos()) catched = True - elif event.KeyCode == ord('E') and event.ControlDown() : + elif key_code == ord('E') and event.ControlDown() : self.GotoPos(self.GetLength()) catched = True - elif event.KeyCode == wx.WXK_PAGEUP: + elif key_code == wx.WXK_PAGEUP: self.ScrollPages(-1) - elif event.KeyCode == wx.WXK_PAGEDOWN: + elif key_code == wx.WXK_PAGEDOWN: self.ScrollPages(1) - elif event.KeyCode == wx.WXK_HOME: + elif key_code == wx.WXK_HOME: self.GotoPos(self.GetLength()) - elif event.KeyCode == wx.WXK_END: + elif key_code == wx.WXK_END: self.GotoPos(self.GetLength()) - elif event.KeyCode == wx.WXK_UP and event.ShiftDown(): + elif key_code == wx.WXK_UP and event.ShiftDown(): self.ScrollLines(-1) - elif event.KeyCode == wx.WXK_DOWN and event.ShiftDown(): + elif key_code == wx.WXK_DOWN and event.ShiftDown(): self.ScrollLines(1) else: catched = False @@ -477,13 +478,12 @@ class ConsoleWidget(editwindow.EditWindow): if self.AutoCompActive(): event.Skip() else: - if event.KeyCode in (13, wx.WXK_NUMPAD_ENTER) and \ - event.Modifiers in (wx.MOD_NONE, wx.MOD_WIN, - wx.MOD_SHIFT): + if key_code in (13, wx.WXK_NUMPAD_ENTER): + # XXX: not catching modifiers, to be wx2.6-compatible catched = True if not self.enter_catched: self.CallTipCancel() - if event.Modifiers == wx.MOD_SHIFT: + if event.ShiftDown(): # Try to force execution self.GotoPos(self.GetLength()) self.write('\n' + self.continuation_prompt(), @@ -493,19 +493,18 @@ class ConsoleWidget(editwindow.EditWindow): self._on_enter() self.enter_catched = True - elif event.KeyCode == wx.WXK_HOME: - if event.Modifiers in (wx.MOD_NONE, wx.MOD_WIN): + elif key_code == wx.WXK_HOME: + if not event.ShiftDown(): self.GotoPos(self.current_prompt_pos) catched = True - - elif event.Modifiers == wx.MOD_SHIFT: + else: # FIXME: This behavior is not ideal: if the selection # is already started, it will jump. self.SetSelectionStart(self.current_prompt_pos) self.SetSelectionEnd(self.GetCurrentPos()) catched = True - elif event.KeyCode == wx.WXK_UP: + elif key_code == wx.WXK_UP: if self.GetCurrentLine() > self.current_prompt_line: if self.GetCurrentLine() == self.current_prompt_line + 1 \ and self.GetColumn(self.GetCurrentPos()) < \ @@ -515,18 +514,18 @@ class ConsoleWidget(editwindow.EditWindow): event.Skip() catched = True - elif event.KeyCode in (wx.WXK_LEFT, wx.WXK_BACK): + elif key_code in (wx.WXK_LEFT, wx.WXK_BACK): if not self._keep_cursor_in_buffer(self.GetCurrentPos() - 1): event.Skip() catched = True - elif event.KeyCode == wx.WXK_RIGHT: + elif key_code == wx.WXK_RIGHT: if not self._keep_cursor_in_buffer(self.GetCurrentPos() + 1): event.Skip() catched = True - elif event.KeyCode == wx.WXK_DELETE: + elif key_code == wx.WXK_DELETE: if not self._keep_cursor_in_buffer(self.GetCurrentPos() - 1): event.Skip() catched = True @@ -535,7 +534,7 @@ class ConsoleWidget(editwindow.EditWindow): # Put the cursor back in the edit region if not self._keep_cursor_in_buffer(): if not (self.GetCurrentPos() == self.GetLength() - and event.KeyCode == wx.WXK_DELETE): + and key_code == wx.WXK_DELETE): event.Skip() catched = True diff --git a/IPython/frontend/wx/wx_frontend.py b/IPython/frontend/wx/wx_frontend.py index d07ca3e..497c4ea 100644 --- a/IPython/frontend/wx/wx_frontend.py +++ b/IPython/frontend/wx/wx_frontend.py @@ -389,7 +389,8 @@ class WxController(ConsoleWidget, PrefilterFrontEnd): """ # FIXME: This method needs to be broken down in smaller ones. current_line_num = self.GetCurrentLine() - if event.KeyCode in (ord('c'), ord('C')) and event.ControlDown(): + key_code = event.GetKeyCode() + if key_code in (ord('c'), ord('C')) and event.ControlDown(): # Capture Control-C if self._input_state == 'subprocess': if self.debug: @@ -403,40 +404,39 @@ class WxController(ConsoleWidget, PrefilterFrontEnd): # XXX: We need to make really sure we # get back to a prompt. elif self._input_state == 'subprocess' and ( - ( event.KeyCode<256 and - not event.ControlDown() ) + ( key_code <256 and not event.ControlDown() ) or - ( event.KeyCode in (ord('d'), ord('D')) and + ( key_code in (ord('d'), ord('D')) and event.ControlDown())): # We are running a process, we redirect keys. ConsoleWidget._on_key_down(self, event, skip=skip) - char = chr(event.KeyCode) + char = chr(key_code) # Deal with some inconsistency in wx keycodes: if char == '\r': char = '\n' elif not event.ShiftDown(): char = char.lower() - if event.ControlDown() and event.KeyCode in (ord('d'), ord('D')): + if event.ControlDown() and key_code in (ord('d'), ord('D')): char = '\04' self._running_process.process.stdin.write(char) self._running_process.process.stdin.flush() - elif event.KeyCode in (ord('('), 57, 53): + elif key_code in (ord('('), 57, 53): # Calltips event.Skip() self.do_calltip() - elif self.AutoCompActive() and not event.KeyCode == ord('\t'): + elif self.AutoCompActive() and not key_code == ord('\t'): event.Skip() - if event.KeyCode in (wx.WXK_BACK, wx.WXK_DELETE): + if key_code in (wx.WXK_BACK, wx.WXK_DELETE): wx.CallAfter(self._popup_completion, create=True) - elif not event.KeyCode in (wx.WXK_UP, wx.WXK_DOWN, wx.WXK_LEFT, + elif not key_code in (wx.WXK_UP, wx.WXK_DOWN, wx.WXK_LEFT, wx.WXK_RIGHT, wx.WXK_ESCAPE): wx.CallAfter(self._popup_completion) else: # Up history - if event.KeyCode == wx.WXK_UP and ( - ( current_line_num == self.current_prompt_line and - event.Modifiers in (wx.MOD_NONE, wx.MOD_WIN) ) - or event.ControlDown() ): + if key_code == wx.WXK_UP and ( + event.ControlDown() or + current_line_num == self.current_prompt_line + ): new_buffer = self.get_history_previous( self.input_buffer) if new_buffer is not None: @@ -446,9 +446,9 @@ class WxController(ConsoleWidget, PrefilterFrontEnd): self.GotoPos(self.current_prompt_pos) # Down history elif event.KeyCode == wx.WXK_DOWN and ( - ( current_line_num == self.LineCount -1 and - event.Modifiers in (wx.MOD_NONE, wx.MOD_WIN) ) - or event.ControlDown() ): + event.ControlDown() or + current_line_num == self.LineCount -1 + ): new_buffer = self.get_history_next() if new_buffer is not None: self.input_buffer = new_buffer