From 234064bef708133c0723665aec43903fdef78622 2008-04-01 21:25:34 From: ldufrechou Date: 2008-04-01 21:25:34 Subject: [PATCH] BIG improvement on cout management. Now doing: while 1: print 'cool' display 'cool' in the console while the code is interpreted. --- diff --git a/IPython/gui/wx/ipython_view.py b/IPython/gui/wx/ipython_view.py index 9b700e8..9ae70e9 100644 --- a/IPython/gui/wx/ipython_view.py +++ b/IPython/gui/wx/ipython_view.py @@ -302,18 +302,6 @@ class WxConsoleView(stc.StyledTextCtrl): return self.GetTextRange(self.getCurrentPromptStart(), self.getCurrentLineEnd()) - def showReturned(self, text): - ''' - Show returned text from last command and print new prompt. - - @param text: Text to show. - @type text: string - ''' - self.write('\n'+text) - if text: - self.write('\n') - self.showPrompt() - def moveCursorOnNewValidKey(self): #If cursor is at wrong position put it at last line... if self.GetCurrentPos() < self.getCurrentPromptStart(): @@ -461,6 +449,7 @@ class IPShellWidget(wx.Panel): because it seems to be more useful Any idea to make it more 'generic' welcomed. ''' + def __init__(self, parent, intro=None, background_color="BLACK", add_button_handler=None, wx_ip_shell=None, @@ -475,7 +464,6 @@ class IPShellWidget(wx.Panel): ### IPython non blocking shell instanciation ### self.cout = StringIO() - self.add_button_handler = add_button_handler if wx_ip_shell is not None: @@ -501,9 +489,11 @@ class IPShellWidget(wx.Panel): self.IP.getPrompt(), intro=welcome_text, background_color=background_color) + + self.cout.write = self.text_ctrl.write self.text_ctrl.Bind(wx.EVT_KEY_DOWN, self.keyPress, self.text_ctrl) - + ### making the layout of the panel ### sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.text_ctrl, 1, wx.EXPAND) @@ -525,6 +515,7 @@ class IPShellWidget(wx.Panel): def stateDoExecuteLine(self): #print >>sys.__stdout__,"command:",self.getCurrentLine() line=self.text_ctrl.getCurrentLine() + self.text_ctrl.write('\n') self.IP.doExecute((line.replace('\t',' '*4)).encode('cp1252')) self.updateHistoryTracker(self.text_ctrl.getCurrentLine()) self.setCurrentState('WAIT_END_OF_EXECUTION') @@ -550,10 +541,7 @@ class IPShellWidget(wx.Panel): self.text_ctrl.setPrompt(self.IP.getPrompt()) self.text_ctrl.setIndentation(self.IP.getIndentation()) self.text_ctrl.setPromptCount(self.IP.getPromptCount()) - rv = self.cout.getvalue() - if rv: rv = rv.strip('\n') - self.text_ctrl.showReturned(rv) - self.cout.truncate(0) + self.text_ctrl.showPrompt() self.IP.initHistoryIndex() self.setCurrentState('IDLE') @@ -640,8 +628,11 @@ class IPShellWidget(wx.Panel): self.pager_state = 'DONE' self.stateShowPrompt() return - - #scroll_position = self.text_ctrl.GetScrollPos(wx.VERTICAL) + +# if self.cur_state == 'WAIT_END_OF_EXECUTION': +# print self.cur_state +# self.text_ctrl.write('.') + if self.cur_state == 'IDLE': if event.KeyCode == wx.WXK_UP: history = self.IP.historyBack() @@ -669,7 +660,7 @@ class IPShellWidget(wx.Panel): return event.Skip() - + #------------------------ Hook Section ----------------------------------- def updateHistoryTracker(self,command_line): ''' diff --git a/IPython/gui/wx/wxIPython.py b/IPython/gui/wx/wxIPython.py index 2916875..8346979 100644 --- a/IPython/gui/wx/wxIPython.py +++ b/IPython/gui/wx/wxIPython.py @@ -36,8 +36,7 @@ class MyFrame(wx.Frame): self.ipython_panel = IPShellWidget(self,background_color = "BLACK") - #self.ipython_panel = WxIPythonViewPanel(self, - # background_color = "WHITE") + #self.ipython_panel = IPShellWidget(self,background_color = "WHITE") self.ipython_panel.setHistoryTrackerHook(self.history_panel.write) self.ipython_panel.setStatusTrackerHook(self.updateStatus)