From 31894549a46f65261b55536652ebdc09777a03bb 2008-04-01 23:17:39 From: ldufrechou Date: 2008-04-01 23:17:39 Subject: [PATCH] Support for true raw_input: Now supports %cpaste! Not already perfect: %cpaste a=1 print 'cool' for b in range(10): print 'go' -- result is: 'cool' --- diff --git a/IPython/gui/wx/ipshell_nonblocking.py b/IPython/gui/wx/ipshell_nonblocking.py index f3164d9..8d34ced 100644 --- a/IPython/gui/wx/ipshell_nonblocking.py +++ b/IPython/gui/wx/ipshell_nonblocking.py @@ -92,7 +92,7 @@ class NonBlockingIPShell(object): def __init__(self,argv=[],user_ns={},user_global_ns=None, cin=None, cout=None, cerr=None, - ask_exit_handler=None): + ask_exit_handler=None, rawinput=None): ''' @param argv: Command line options for IPython @type argv: list @@ -114,7 +114,7 @@ class NonBlockingIPShell(object): #ipython0 initialisation self.initIpython0(argv, user_ns, user_global_ns, cin, cout, cerr, - ask_exit_handler) + ask_exit_handler, rawinput) #vars used by _execute self._iter_more = 0 @@ -133,7 +133,7 @@ class NonBlockingIPShell(object): def initIpython0(self, argv=[], user_ns={}, user_global_ns=None, cin=None, cout=None, cerr=None, - ask_exit_handler=None): + ask_exit_handler=None, rawinput=None): #first we redefine in/out/error functions of IPython if cin: IPython.Shell.Term.cin = cin @@ -167,7 +167,8 @@ class NonBlockingIPShell(object): self._IP.set_hook('shell_hook',self._shell) #we replace the ipython default input command caller by our method - IPython.iplib.raw_input_original = self._raw_input + IPython.iplib.raw_input_original = rawinput + #we replace the ipython default exit command by our method self._IP.exit = ask_exit_handler #we replace the help command @@ -339,12 +340,6 @@ class NonBlockingIPShell(object): ''' pass - #def _askExit(self): - # ''' - # Can be redefined to generate post event to exit the Ipython shell - # ''' - # pass - def _getHistoryMaxIndex(self): ''' returns the max length of the history buffer @@ -385,18 +380,6 @@ class NonBlockingIPShell(object): ''' self._doc_text = text - def _raw_input(self, prompt=''): - ''' - Custom raw_input() replacement. Get's current line from console buffer. - - @param prompt: Prompt to print. Here for compatability as replacement. - @type prompt: string - - @return: The current command line text. - @rtype: string - ''' - return self._line_to_execute - def _execute(self): ''' Executes the current line provided by the shell object. diff --git a/IPython/gui/wx/ipython_view.py b/IPython/gui/wx/ipython_view.py index 9ae70e9..310528f 100644 --- a/IPython/gui/wx/ipython_view.py +++ b/IPython/gui/wx/ipython_view.py @@ -47,11 +47,12 @@ class WxNonBlockingIPShell(NonBlockingIPShell): def __init__(self, parent, argv=[],user_ns={},user_global_ns=None, cin=None, cout=None, cerr=None, - ask_exit_handler=None): + ask_exit_handler=None, rawinput=None): NonBlockingIPShell.__init__(self,argv,user_ns,user_global_ns, cin, cout, cerr, - ask_exit_handler) + ask_exit_handler, + rawinput) self.parent = parent @@ -394,7 +395,7 @@ class WxConsoleView(stc.StyledTextCtrl): elif event.GetKeyCode() == wx.WXK_BACK: self.moveCursorOnNewValidKey() if self.getCursorPos() > self.getCurrentPromptStart(): - self.removeFromTo(self.getCursorPos()-1,self.getCursorPos()) + event.Skip() return True if skip: @@ -470,8 +471,9 @@ class IPShellWidget(wx.Panel): self.IP = wx_ip_shell else: self.IP = WxNonBlockingIPShell(self, - cout = self.cout,cerr = self.cout, - ask_exit_handler = self.askExitCallback) + cout = self.cout, cerr = self.cout, + ask_exit_handler = self.askExitCallback, + rawinput = self.rawInput) ### IPython wx console view instanciation ### #If user didn't defined an intro text, we create one for him @@ -548,9 +550,17 @@ class IPShellWidget(wx.Panel): def setCurrentState(self, state): self.cur_state = state self.updateStatusTracker(self.cur_state) - + #---------------------------- Ipython raw_input ----------------------------------- + def rawInput(self, prompt=''): + self.setCurrentState('WAITING_USER_INPUT') + while self.cur_state != 'WAIT_END_OF_EXECUTION': + pass + line = self.text_ctrl.getCurrentLine() + line = line.split('\n') + return line[-2] + #---------------------------- IPython pager --------------------------------------- - def pager(self,text):#,start=0,screen_lines=0,pager_cmd = None): + def pager(self,text): if self.pager_state == 'INIT': #print >>sys.__stdout__,"PAGER state:",self.pager_state @@ -623,15 +633,20 @@ class IPShellWidget(wx.Panel): self.pager(self.doc) return + if self.cur_state == 'WAITING_USER_INPUT': + line=self.text_ctrl.getCurrentLine() + self.text_ctrl.write('\n') + self.setCurrentState('WAIT_END_OF_EXECUTION') + return + if event.GetKeyCode() in [ord('q'),ord('Q')]: if self.pager_state == 'WAITING': self.pager_state = 'DONE' self.stateShowPrompt() return -# if self.cur_state == 'WAIT_END_OF_EXECUTION': -# print self.cur_state -# self.text_ctrl.write('.') + if self.cur_state == 'WAITING_USER_INPUT': + event.Skip() if self.cur_state == 'IDLE': if event.KeyCode == wx.WXK_UP: diff --git a/IPython/gui/wx/wxIPython.py b/IPython/gui/wx/wxIPython.py index 8346979..a7c5e8e 100644 --- a/IPython/gui/wx/wxIPython.py +++ b/IPython/gui/wx/wxIPython.py @@ -121,6 +121,7 @@ class MyFrame(wx.Frame): states = {'IDLE':'Idle', 'DO_EXECUTE_LINE':'Send command', 'WAIT_END_OF_EXECUTION':'Running command', + 'WAITING_USER_INPUT':'Waiting user input', 'SHOW_DOC':'Showing doc', 'SHOW_PROMPT':'Showing prompt'} self.statusbar.SetStatusText(states[text], 0)