diff --git a/IPython/frontend/wx/console_widget.py b/IPython/frontend/wx/console_widget.py index 49993d7..36dff24 100644 --- a/IPython/frontend/wx/console_widget.py +++ b/IPython/frontend/wx/console_widget.py @@ -22,6 +22,8 @@ __docformat__ = "restructuredtext en" import wx import wx.stc as stc +from wx.py import editwindow + import re # FIXME: Need to provide an API for non user-generated display on the @@ -64,7 +66,7 @@ _TRACE_STYLE = 17 #------------------------------------------------------------------------------- # The console widget class #------------------------------------------------------------------------------- -class ConsoleWidget(stc.StyledTextCtrl): +class ConsoleWidget(editwindow.EditWindow): """ Specialized styled text control view for console-like workflow. This widget is mainly interested in dealing with the prompt and @@ -100,7 +102,8 @@ class ConsoleWidget(stc.StyledTextCtrl): 'IPYTHON' show autocompletion the ipython way 'STC" show it scintilla text control way """ - stc.StyledTextCtrl.__init__(self, parent, id, pos, size, style) + #stc.StyledTextCtrl.__init__(self, parent, id, pos, size, style) + editwindow.EditWindow.__init__(self, parent, id, pos, size, style) self.configure_scintilla() # FIXME: we need to retrieve this from the interpreter. diff --git a/IPython/frontend/wx/wx_frontend.py b/IPython/frontend/wx/wx_frontend.py index ebf55d2..aac0b24 100644 --- a/IPython/frontend/wx/wx_frontend.py +++ b/IPython/frontend/wx/wx_frontend.py @@ -22,7 +22,7 @@ __docformat__ = "restructuredtext en" import wx from console_widget import ConsoleWidget - +import re import IPython from IPython.kernel.engineservice import EngineService @@ -40,7 +40,15 @@ class IPythonWxController(FrontEndBase, ConsoleWidget): output_prompt = \ '\n\x01\x1b[0;31m\x02Out[\x01\x1b[1;31m\x02%i\x01\x1b[0;31m\x02]: \x01\x1b[0m\x02' - + + # Are we entering multi line input? + multi_line_input = False + + # The added tab stop to the string. It may, for instance, come from + # copy and pasting something with tabs. + tab_stop = 0 + # FIXME: We still have to deal with this. + #-------------------------------------------------------------------------- # Public API #-------------------------------------------------------------------------- @@ -121,10 +129,35 @@ class IPythonWxController(FrontEndBase, ConsoleWidget): """ Called when the return key is pressed in a line editing buffer. """ - result = self.engine.shell.execute(self.get_current_edit_buffer()) - self.render_result(result) - self.new_prompt(self.prompt % result['number']) - + current_buffer = self.get_current_edit_buffer() + current_buffer = current_buffer.replace('\r\n', '\n') + current_buffer = current_buffer.replace('\t', 4*' ') + if ( not self.multi_line_input + or re.findall(r"\n[\t ]*\n[\t ]*$", current_buffer)): + if self.is_complete(current_buffer): + result = self.engine.shell.execute(current_buffer) + self.render_result(result) + self.new_prompt(self.prompt % result['number']) + self.multi_line_input = False + else: + if self.multi_line_input: + self.write(self._get_indent_string(current_buffer[:-1])) + else: + self.multi_line_input = True + self.write('\t') + else: + self.write(self._get_indent_string(current_buffer[:-1])) + + + def _get_indent_string(self, string): + string = string.split('\n')[-1] + indent_chars = len(string) - len(string.lstrip()) + indent_string = '\t'*(indent_chars // 4) + \ + ' '*(indent_chars % 4) + + return indent_string + + if __name__ == '__main__': class MainWindow(wx.Frame): @@ -143,5 +176,5 @@ if __name__ == '__main__': frame.SetSize((780, 460)) shell = frame.shell - #app.MainLoop() +# app.MainLoop()