From 3fc35df35971bd68e8d5cc5866c5af5a5ed9c73e 2009-04-20 21:25:20 From: Gael Varoquaux Date: 2009-04-20 21:25:20 Subject: [PATCH] Take in account remarks by Fernando on code review --- diff --git a/IPython/frontend/linefrontendbase.py b/IPython/frontend/linefrontendbase.py index 90f133c..1cb1ad6 100644 --- a/IPython/frontend/linefrontendbase.py +++ b/IPython/frontend/linefrontendbase.py @@ -334,15 +334,20 @@ class LineFrontEndBase(FrontEndBase): self.execute(cleaned_buffer, raw_string=current_buffer) return True else: + # Start a new line. new_line_pos = -new_line_pos lines = current_buffer.split('\n')[:-1] prompt_less_lines = prompt_less_buffer.split('\n') + # Create the new line, with the continuation prompt, and the + # same amount of indent than the line above it. new_line = self.continuation_prompt() + \ self._get_indent_string('\n'.join( prompt_less_lines[:new_line_pos-1])) if len(lines) == 1: + # We are starting a first continuation line. Indent it. new_line += '\t' elif current_buffer[:-1].split('\n')[-1].rstrip().endswith(':'): + # The last line ends with ":", autoindent the new line. new_line += '\t' if new_line_pos == 0: diff --git a/IPython/frontend/_process/__init__.py b/IPython/frontend/process/__init__.py similarity index 100% rename from IPython/frontend/_process/__init__.py rename to IPython/frontend/process/__init__.py diff --git a/IPython/frontend/_process/killableprocess.py b/IPython/frontend/process/killableprocess.py similarity index 100% rename from IPython/frontend/_process/killableprocess.py rename to IPython/frontend/process/killableprocess.py diff --git a/IPython/frontend/_process/pipedprocess.py b/IPython/frontend/process/pipedprocess.py similarity index 100% rename from IPython/frontend/_process/pipedprocess.py rename to IPython/frontend/process/pipedprocess.py diff --git a/IPython/frontend/_process/winprocess.py b/IPython/frontend/process/winprocess.py similarity index 100% rename from IPython/frontend/_process/winprocess.py rename to IPython/frontend/process/winprocess.py diff --git a/IPython/frontend/tests/test_linefrontend.py b/IPython/frontend/tests/test_linefrontend.py index 11d3209..d0d53ac 100644 --- a/IPython/frontend/tests/test_linefrontend.py +++ b/IPython/frontend/tests/test_linefrontend.py @@ -14,6 +14,7 @@ __docformat__ = "restructuredtext en" from IPython.frontend.linefrontendbase import LineFrontEndBase from copy import deepcopy +import nose.tools as nt class ConcreteLineFrontEnd(LineFrontEndBase): """ A concrete class to test the LineFrontEndBase. @@ -29,10 +30,8 @@ def test_is_complete(): """ Tests line completion heuristic. """ frontend = ConcreteLineFrontEnd() - assert not frontend.is_complete('for x in \\') - assert not frontend.is_complete('for x in (1, ):') - assert frontend.is_complete('for x in (1, ):\n pass') + yield nt.assert_true, not frontend.is_complete('for x in \\') + yield nt.assert_true, not frontend.is_complete('for x in (1, ):') + yield nt.assert_true, frontend.is_complete('for x in (1, ):\n pass') -if __name__ == '__main__': - test_is_complete() diff --git a/IPython/frontend/tests/test_prefilterfrontend.py b/IPython/frontend/tests/test_prefilterfrontend.py index 5f22439..53e7b8b 100644 --- a/IPython/frontend/tests/test_prefilterfrontend.py +++ b/IPython/frontend/tests/test_prefilterfrontend.py @@ -111,20 +111,20 @@ def test_multiline(): f.input_buffer += 'print 1' f._on_enter() out_value = f.out.getvalue() - assert_equal(out_value, '') + yield assert_equal, out_value, '' f._on_enter() out_value = f.out.getvalue() - assert_equal(out_value, '1\n') + yield assert_equal, out_value, '1\n' f = TestPrefilterFrontEnd() f.input_buffer='(1 +' f._on_enter() f.input_buffer += '0)' f._on_enter() out_value = f.out.getvalue() - assert_equal(out_value, '') + yield assert_equal, out_value, '' f._on_enter() out_value = f.out.getvalue() - assert_equal(out_value, '1\n') + yield assert_equal, out_value, '1\n' @isolate_ipython0 @@ -137,13 +137,13 @@ def test_capture(): 'import os; out=os.fdopen(1, "w"); out.write("1") ; out.flush()' f._on_enter() out_value = f.out.getvalue() - assert_equal(out_value, '1') + yield assert_equal, out_value, '1' f = TestPrefilterFrontEnd() f.input_buffer = \ 'import os; out=os.fdopen(2, "w"); out.write("1") ; out.flush()' f._on_enter() out_value = f.out.getvalue() - assert_equal(out_value, '1') + yield assert_equal, out_value, '1' @isolate_ipython0 @@ -191,8 +191,8 @@ def test_completion_simple(): f.input_buffer = 'zz' f.complete_current_input() out_value = f.out.getvalue() - assert_equal(out_value, '\nzzza zzzb ') - assert_equal(f.input_buffer, 'zzz') + yield assert_equal, out_value, '\nzzza zzzb ' + yield assert_equal, f.input_buffer, 'zzz' @isolate_ipython0 @@ -207,8 +207,8 @@ def test_completion_parenthesis(): f.input_buffer = 'map(zz' f.complete_current_input() out_value = f.out.getvalue() - assert_equal(out_value, '\nzzza zzzb ') - assert_equal(f.input_buffer, 'map(zzz') + yield assert_equal, out_value, '\nzzza zzzb ' + yield assert_equal, f.input_buffer, 'map(zzz' @isolate_ipython0 diff --git a/IPython/frontend/tests/test_process.py b/IPython/frontend/tests/test_process.py index dc8db5f..f0f607c 100644 --- a/IPython/frontend/tests/test_process.py +++ b/IPython/frontend/tests/test_process.py @@ -16,7 +16,7 @@ from cStringIO import StringIO from time import sleep import sys -from IPython.frontend._process import PipedProcess +from IPython.frontend.process import PipedProcess from IPython.testing import decorators as testdec diff --git a/IPython/frontend/wx/console_widget.py b/IPython/frontend/wx/console_widget.py index 984cffc..8fcb17a 100644 --- a/IPython/frontend/wx/console_widget.py +++ b/IPython/frontend/wx/console_widget.py @@ -65,7 +65,24 @@ _DEFAULT_STYLE = { 'tripledouble' : 'fore:#7F0000', 'class' : 'fore:#0000FF,bold,underline', 'def' : 'fore:#007F7F,bold', - 'operator' : 'bold' + 'operator' : 'bold', + + # Default colors + 'trace' : '#FAFAF1', # Nice green + 'stdout' : '#FDFFD3', # Nice yellow + 'stderr' : '#FFF1F1', # Nice red + + # Default scintilla settings + 'antialiasing' : True, + 'carret_color' : 'BLACK', + 'background_color' :'WHITE', + + #prompt definition + 'prompt_in1' : \ + '\n\x01\x1b[0;34m\x02In [\x01\x1b[1;34m\x02$number\x01\x1b[0;34m\x02]: \x01\x1b[0m\x02', + + 'prompt_out': \ + '\x01\x1b[0;31m\x02Out[\x01\x1b[1;31m\x02$number\x01\x1b[0;31m\x02]: \x01\x1b[0m\x02', } # new style numbers @@ -88,6 +105,9 @@ ANSI_STYLES = {'0;30': [0, 'BLACK'], '0;31': [1, 'RED'], [13, 'MEDIUM VIOLET RED'], '1;36': [14, 'LIGHT STEEL BLUE'], '1;37': [15, 'YELLOW']} +# XXX: Maybe one day we should factor this code with ColorANSI. Right now +# ColorANSI is hard to reuse and makes our code more complex. + #we define platform specific fonts if wx.Platform == '__WXMSW__': FACES = { 'times': 'Times New Roman', @@ -274,35 +294,21 @@ class ConsoleWidget(editwindow.EditWindow): def configure_scintilla(self): - - p = self.style + """ Set up all the styling option of the embedded scintilla + widget. + """ + p = self.style.copy() - #First we define the special background colors - if 'trace' in p: - _COMPLETE_BUFFER_BG = p['trace'] - else: - _COMPLETE_BUFFER_BG = '#FAFAF1' # Nice green - - if 'stdout' in p: - _INPUT_BUFFER_BG = p['stdout'] - else: - _INPUT_BUFFER_BG = '#FDFFD3' # Nice yellow - - if 'stderr' in p: - _ERROR_BG = p['stderr'] - else: - _ERROR_BG = '#FFF1F1' # Nice red - # Marker for complete buffer. self.MarkerDefine(_COMPLETE_BUFFER_MARKER, stc.STC_MARK_BACKGROUND, - background = _COMPLETE_BUFFER_BG) + background=p['trace']) # Marker for current input buffer. self.MarkerDefine(_INPUT_MARKER, stc.STC_MARK_BACKGROUND, - background = _INPUT_BUFFER_BG) + background=p['stdout']) # Marker for tracebacks. self.MarkerDefine(_ERROR_MARKER, stc.STC_MARK_BACKGROUND, - background = _ERROR_BG) + background=p['stderr']) self.SetEOLMode(stc.STC_EOL_LF) @@ -326,10 +332,7 @@ class ConsoleWidget(editwindow.EditWindow): self.SetWrapMode(stc.STC_WRAP_WORD) self.SetBufferedDraw(True) - if 'antialiasing' in p: - self.SetUseAntiAliasing(p['antialiasing']) - else: - self.SetUseAntiAliasing(True) + self.SetUseAntiAliasing(p['antialiasing']) self.SetLayoutCache(stc.STC_CACHE_PAGE) self.SetUndoCollection(False) @@ -357,15 +360,9 @@ class ConsoleWidget(editwindow.EditWindow): # styles - if 'carret_color' in p: - self.SetCaretForeground(p['carret_color']) - else: - self.SetCaretForeground('BLACK') + self.SetCaretForeground(p['carret_color']) - if 'background_color' in p: - background_color = p['background_color'] - else: - background_color = 'WHITE' + background_color = p['background_color'] if 'default' in p: if 'back' not in p['default']: @@ -383,70 +380,42 @@ class ConsoleWidget(editwindow.EditWindow): background_color, self.faces['size'], self.faces['mono'])) - #all styles = default one self.StyleClearAll() # XXX: two lines below are usefull if not using the lexer #for style in self.ANSI_STYLES.values(): # self.StyleSetSpec(style[0], "bold,fore:%s" % style[1]) - #prompt definition - if 'prompt_in1' in p: - self.prompt_in1 = p['prompt_in1'] - else: - self.prompt_in1 = \ - '\n\x01\x1b[0;34m\x02In [\x01\x1b[1;34m\x02$number\x01\x1b[0;34m\x02]: \x01\x1b[0m\x02' - - if 'prompt_out' in p: - self.prompt_out = p['prompt_out'] - else: - self.prompt_out = \ - '\x01\x1b[0;31m\x02Out[\x01\x1b[1;31m\x02$number\x01\x1b[0;31m\x02]: \x01\x1b[0m\x02' + # prompt definition + self.prompt_in1 = p['prompt_in1'] + self.prompt_out = p['prompt_out'] self.output_prompt_template = string.Template(self.prompt_out) self.input_prompt_template = string.Template(self.prompt_in1) - if 'stdout' in p: - self.StyleSetSpec(_STDOUT_STYLE, p['stdout']) - if 'stderr' in p: - self.StyleSetSpec(_STDERR_STYLE, p['stderr']) - if 'trace' in p: - self.StyleSetSpec(_TRACE_STYLE, p['trace']) - if 'bracegood' in p: - self.StyleSetSpec(stc.STC_STYLE_BRACELIGHT, p['bracegood']) - if 'bracebad' in p: - self.StyleSetSpec(stc.STC_STYLE_BRACEBAD, p['bracebad']) - if 'comment' in p: - self.StyleSetSpec(stc.STC_P_COMMENTLINE, p['comment']) - if 'number' in p: - self.StyleSetSpec(stc.STC_P_NUMBER, p['number']) - if 'string' in p: - self.StyleSetSpec(stc.STC_P_STRING, p['string']) - if 'char' in p: - self.StyleSetSpec(stc.STC_P_CHARACTER, p['char']) - if 'keyword' in p: - self.StyleSetSpec(stc.STC_P_WORD, p['keyword']) - if 'keyword' in p: - self.StyleSetSpec(stc.STC_P_WORD2, p['keyword']) - if 'triple' in p: - self.StyleSetSpec(stc.STC_P_TRIPLE, p['triple']) - if 'tripledouble' in p: - self.StyleSetSpec(stc.STC_P_TRIPLEDOUBLE, p['tripledouble']) - if 'class' in p: - self.StyleSetSpec(stc.STC_P_CLASSNAME, p['class']) - if 'def' in p: - self.StyleSetSpec(stc.STC_P_DEFNAME, p['def']) - if 'operator' in p: - self.StyleSetSpec(stc.STC_P_OPERATOR, p['operator']) - if 'comment' in p: - self.StyleSetSpec(stc.STC_P_COMMENTBLOCK, p['comment']) - - if 'edge_column' in p: - edge_column = p['edge_column'] - if edge_column is not None and edge_column > 0: - #we add a vertical line to console widget - self.SetEdgeMode(stc.STC_EDGE_LINE) - self.SetEdgeColumn(88) + self.StyleSetSpec(_STDOUT_STYLE, p['stdout']) + self.StyleSetSpec(_STDERR_STYLE, p['stderr']) + self.StyleSetSpec(_TRACE_STYLE, p['trace']) + self.StyleSetSpec(stc.STC_STYLE_BRACELIGHT, p['bracegood']) + self.StyleSetSpec(stc.STC_STYLE_BRACEBAD, p['bracebad']) + self.StyleSetSpec(stc.STC_P_COMMENTLINE, p['comment']) + self.StyleSetSpec(stc.STC_P_NUMBER, p['number']) + self.StyleSetSpec(stc.STC_P_STRING, p['string']) + self.StyleSetSpec(stc.STC_P_CHARACTER, p['char']) + self.StyleSetSpec(stc.STC_P_WORD, p['keyword']) + self.StyleSetSpec(stc.STC_P_WORD2, p['keyword']) + self.StyleSetSpec(stc.STC_P_TRIPLE, p['triple']) + self.StyleSetSpec(stc.STC_P_TRIPLEDOUBLE, p['tripledouble']) + self.StyleSetSpec(stc.STC_P_CLASSNAME, p['class']) + self.StyleSetSpec(stc.STC_P_DEFNAME, p['def']) + self.StyleSetSpec(stc.STC_P_OPERATOR, p['operator']) + self.StyleSetSpec(stc.STC_P_COMMENTBLOCK, p['comment']) + + edge_column = p['edge_column'] + if edge_column is not None and edge_column > 0: + #we add a vertical line to console widget + self.SetEdgeMode(stc.STC_EDGE_LINE) + self.SetEdgeColumn(edge_column) #-------------------------------------------------------------------------- diff --git a/IPython/frontend/wx/wx_frontend.py b/IPython/frontend/wx/wx_frontend.py index e20e558..854c47e 100644 --- a/IPython/frontend/wx/wx_frontend.py +++ b/IPython/frontend/wx/wx_frontend.py @@ -32,7 +32,7 @@ import wx from wx import stc # Ipython-specific imports. -from IPython.frontend._process import PipedProcess +from IPython.frontend.process import PipedProcess from console_widget import ConsoleWidget, _COMPLETE_BUFFER_MARKER, \ _ERROR_MARKER, _INPUT_MARKER from IPython.frontend.prefilterfrontend import PrefilterFrontEnd @@ -507,8 +507,9 @@ class WxController(ConsoleWidget, PrefilterFrontEnd): new_lines = [] if self._input_state == 'readline': position = self.GetCurrentPos() + continuation_prompt = self.continuation_prompt()[:-1] for line in self.input_buffer.split('\n'): - if not line == self.continuation_prompt()[:-1]: + if not line == continuation_prompt: new_lines.append(line) self.input_buffer = '\n'.join(new_lines) self.GotoPos(position) @@ -528,9 +529,11 @@ class WxController(ConsoleWidget, PrefilterFrontEnd): # input_buffer filters this out. if sys.platform == 'win32': self.input_buffer = self.input_buffer + old_prompt_num = self.current_prompt_pos has_executed = PrefilterFrontEnd._on_enter(self, new_line_pos=new_line_pos) - if not has_executed: + if old_prompt_num == self.current_prompt_pos: + # No execution has happened self.GotoPos(self.GetLineEndPosition(current_line_num + 1)) return has_executed diff --git a/setupbase.py b/setupbase.py index cd75644..9c00a35 100644 --- a/setupbase.py +++ b/setupbase.py @@ -109,7 +109,7 @@ def find_packages(): add_package(packages, 'gui') add_package(packages, 'gui.wx') add_package(packages, 'frontend', tests=True) - add_package(packages, 'frontend._process') + add_package(packages, 'frontend.process') add_package(packages, 'frontend.wx') add_package(packages, 'frontend.cocoa', tests=True) add_package(packages, 'kernel', config=True, tests=True, scripts=True)