Package: ipython
Version: 0.9.1-3
Severity: normal
Usertags: origin-ubuntu ubuntu-patch karmic

IPython has compatibility issues when used with python-wxgtk2.6. This
bug is known upstream, and has been fixed in Ubuntu with the attached
patch, taken by Gael Varoquaux (an IPython developer) from the IPython
trunk.

The Ubuntu bug is here:
https://bugs.launchpad.net/ubuntu/+source/ipython/+bug/370878
diff -ru ipython/IPython/frontend/wx/console_widget.py ipython-fix/IPython/frontend/wx/console_widget.py
--- ipython/IPython/frontend/wx/console_widget.py	2009-05-16 15:21:17.000000000 +0200
+++ ipython-fix/IPython/frontend/wx/console_widget.py	2009-05-16 15:37:53.000000000 +0200
@@ -330,25 +330,26 @@
         """
         catched = True
         # 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_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
@@ -356,8 +357,7 @@
         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):
+            if key_code in (13, wx.WXK_NUMPAD_ENTER):
                 catched = True
                 self.CallTipCancel()
                 self.write('\n', refresh=False)
@@ -368,19 +368,19 @@
                     self.input_buffer = self.input_buffer
                 self._on_enter()
 
-            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()) < \
@@ -390,7 +390,7 @@
                         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 self.GetCurrentPos() > self.current_prompt_pos:
                     event.Skip()
                 catched = True
diff -ru ipython/IPython/frontend/wx/wx_frontend.py ipython-fix/IPython/frontend/wx/wx_frontend.py
--- ipython/IPython/frontend/wx/wx_frontend.py	2009-05-16 15:21:04.000000000 +0200
+++ ipython-fix/IPython/frontend/wx/wx_frontend.py	2009-05-16 15:37:53.000000000 +0200
@@ -368,7 +368,8 @@
         """
         # FIXME: This method needs to be broken down in smaller ones.
         current_line_number = 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:
@@ -382,39 +383,38 @@
                 # XXX: We need to make really sure we
                 # get back to a prompt.
         elif self._input_state == 'subprocess' and (
-                ( event.KeyCode<256 and
+                ( 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_number == self.current_prompt_line and
-                        event.Modifiers in (wx.MOD_NONE, wx.MOD_WIN) ) 
+            if key_code == wx.WXK_UP and (
+                    current_line_number == self.current_prompt_line 
                     or event.ControlDown() ):
                 new_buffer = self.get_history_previous(
                                             self.input_buffer)
@@ -424,15 +424,14 @@
                         # Go to first line, for seemless history up.
                         self.GotoPos(self.current_prompt_pos)
             # Down history
-            elif event.KeyCode == wx.WXK_DOWN and (
-                    ( current_line_number == self.LineCount -1 and
-                        event.Modifiers in (wx.MOD_NONE, wx.MOD_WIN) ) 
+            elif key_code == wx.WXK_DOWN and (
+                    current_line_number == self.LineCount -1 
                     or event.ControlDown() ):
                 new_buffer = self.get_history_next()
                 if new_buffer is not None:
                     self.input_buffer = new_buffer
             # Tab-completion
-            elif event.KeyCode == ord('\t'):
+            elif key_code == ord('\t'):
                 current_line, current_line_number = self.CurLine
                 if not re.match(r'^\s*$', current_line):
                     self.complete_current_input()
@@ -447,7 +446,7 @@
     def _on_key_up(self, event, skip=True):
         """ Called when any key is released.
         """
-        if event.KeyCode in (59, ord('.')):
+        if event.GetKeyCode() in (59, ord('.')):
             # Intercepting '.'
             event.Skip()
             wx.CallAfter(self._popup_completion, create=True)

Reply via email to