##// END OF EJS Templates
Take in account remarks by Fernando on code review
Gael Varoquaux -
Show More
@@ -334,15 +334,20 b' class LineFrontEndBase(FrontEndBase):'
334 self.execute(cleaned_buffer, raw_string=current_buffer)
334 self.execute(cleaned_buffer, raw_string=current_buffer)
335 return True
335 return True
336 else:
336 else:
337 # Start a new line.
337 new_line_pos = -new_line_pos
338 new_line_pos = -new_line_pos
338 lines = current_buffer.split('\n')[:-1]
339 lines = current_buffer.split('\n')[:-1]
339 prompt_less_lines = prompt_less_buffer.split('\n')
340 prompt_less_lines = prompt_less_buffer.split('\n')
341 # Create the new line, with the continuation prompt, and the
342 # same amount of indent than the line above it.
340 new_line = self.continuation_prompt() + \
343 new_line = self.continuation_prompt() + \
341 self._get_indent_string('\n'.join(
344 self._get_indent_string('\n'.join(
342 prompt_less_lines[:new_line_pos-1]))
345 prompt_less_lines[:new_line_pos-1]))
343 if len(lines) == 1:
346 if len(lines) == 1:
347 # We are starting a first continuation line. Indent it.
344 new_line += '\t'
348 new_line += '\t'
345 elif current_buffer[:-1].split('\n')[-1].rstrip().endswith(':'):
349 elif current_buffer[:-1].split('\n')[-1].rstrip().endswith(':'):
350 # The last line ends with ":", autoindent the new line.
346 new_line += '\t'
351 new_line += '\t'
347
352
348 if new_line_pos == 0:
353 if new_line_pos == 0:
1 NO CONTENT: file renamed from IPython/frontend/_process/__init__.py to IPython/frontend/process/__init__.py
NO CONTENT: file renamed from IPython/frontend/_process/__init__.py to IPython/frontend/process/__init__.py
1 NO CONTENT: file renamed from IPython/frontend/_process/killableprocess.py to IPython/frontend/process/killableprocess.py
NO CONTENT: file renamed from IPython/frontend/_process/killableprocess.py to IPython/frontend/process/killableprocess.py
1 NO CONTENT: file renamed from IPython/frontend/_process/pipedprocess.py to IPython/frontend/process/pipedprocess.py
NO CONTENT: file renamed from IPython/frontend/_process/pipedprocess.py to IPython/frontend/process/pipedprocess.py
1 NO CONTENT: file renamed from IPython/frontend/_process/winprocess.py to IPython/frontend/process/winprocess.py
NO CONTENT: file renamed from IPython/frontend/_process/winprocess.py to IPython/frontend/process/winprocess.py
@@ -14,6 +14,7 b' __docformat__ = "restructuredtext en"'
14
14
15 from IPython.frontend.linefrontendbase import LineFrontEndBase
15 from IPython.frontend.linefrontendbase import LineFrontEndBase
16 from copy import deepcopy
16 from copy import deepcopy
17 import nose.tools as nt
17
18
18 class ConcreteLineFrontEnd(LineFrontEndBase):
19 class ConcreteLineFrontEnd(LineFrontEndBase):
19 """ A concrete class to test the LineFrontEndBase.
20 """ A concrete class to test the LineFrontEndBase.
@@ -29,10 +30,8 b' def test_is_complete():'
29 """ Tests line completion heuristic.
30 """ Tests line completion heuristic.
30 """
31 """
31 frontend = ConcreteLineFrontEnd()
32 frontend = ConcreteLineFrontEnd()
32 assert not frontend.is_complete('for x in \\')
33 yield nt.assert_true, not frontend.is_complete('for x in \\')
33 assert not frontend.is_complete('for x in (1, ):')
34 yield nt.assert_true, not frontend.is_complete('for x in (1, ):')
34 assert frontend.is_complete('for x in (1, ):\n pass')
35 yield nt.assert_true, frontend.is_complete('for x in (1, ):\n pass')
35
36
36
37
37 if __name__ == '__main__':
38 test_is_complete()
@@ -111,20 +111,20 b' def test_multiline():'
111 f.input_buffer += 'print 1'
111 f.input_buffer += 'print 1'
112 f._on_enter()
112 f._on_enter()
113 out_value = f.out.getvalue()
113 out_value = f.out.getvalue()
114 assert_equal(out_value, '')
114 yield assert_equal, out_value, ''
115 f._on_enter()
115 f._on_enter()
116 out_value = f.out.getvalue()
116 out_value = f.out.getvalue()
117 assert_equal(out_value, '1\n')
117 yield assert_equal, out_value, '1\n'
118 f = TestPrefilterFrontEnd()
118 f = TestPrefilterFrontEnd()
119 f.input_buffer='(1 +'
119 f.input_buffer='(1 +'
120 f._on_enter()
120 f._on_enter()
121 f.input_buffer += '0)'
121 f.input_buffer += '0)'
122 f._on_enter()
122 f._on_enter()
123 out_value = f.out.getvalue()
123 out_value = f.out.getvalue()
124 assert_equal(out_value, '')
124 yield assert_equal, out_value, ''
125 f._on_enter()
125 f._on_enter()
126 out_value = f.out.getvalue()
126 out_value = f.out.getvalue()
127 assert_equal(out_value, '1\n')
127 yield assert_equal, out_value, '1\n'
128
128
129
129
130 @isolate_ipython0
130 @isolate_ipython0
@@ -137,13 +137,13 b' def test_capture():'
137 'import os; out=os.fdopen(1, "w"); out.write("1") ; out.flush()'
137 'import os; out=os.fdopen(1, "w"); out.write("1") ; out.flush()'
138 f._on_enter()
138 f._on_enter()
139 out_value = f.out.getvalue()
139 out_value = f.out.getvalue()
140 assert_equal(out_value, '1')
140 yield assert_equal, out_value, '1'
141 f = TestPrefilterFrontEnd()
141 f = TestPrefilterFrontEnd()
142 f.input_buffer = \
142 f.input_buffer = \
143 'import os; out=os.fdopen(2, "w"); out.write("1") ; out.flush()'
143 'import os; out=os.fdopen(2, "w"); out.write("1") ; out.flush()'
144 f._on_enter()
144 f._on_enter()
145 out_value = f.out.getvalue()
145 out_value = f.out.getvalue()
146 assert_equal(out_value, '1')
146 yield assert_equal, out_value, '1'
147
147
148
148
149 @isolate_ipython0
149 @isolate_ipython0
@@ -191,8 +191,8 b' def test_completion_simple():'
191 f.input_buffer = 'zz'
191 f.input_buffer = 'zz'
192 f.complete_current_input()
192 f.complete_current_input()
193 out_value = f.out.getvalue()
193 out_value = f.out.getvalue()
194 assert_equal(out_value, '\nzzza zzzb ')
194 yield assert_equal, out_value, '\nzzza zzzb '
195 assert_equal(f.input_buffer, 'zzz')
195 yield assert_equal, f.input_buffer, 'zzz'
196
196
197
197
198 @isolate_ipython0
198 @isolate_ipython0
@@ -207,8 +207,8 b' def test_completion_parenthesis():'
207 f.input_buffer = 'map(zz'
207 f.input_buffer = 'map(zz'
208 f.complete_current_input()
208 f.complete_current_input()
209 out_value = f.out.getvalue()
209 out_value = f.out.getvalue()
210 assert_equal(out_value, '\nzzza zzzb ')
210 yield assert_equal, out_value, '\nzzza zzzb '
211 assert_equal(f.input_buffer, 'map(zzz')
211 yield assert_equal, f.input_buffer, 'map(zzz'
212
212
213
213
214 @isolate_ipython0
214 @isolate_ipython0
@@ -16,7 +16,7 b' from cStringIO import StringIO'
16 from time import sleep
16 from time import sleep
17 import sys
17 import sys
18
18
19 from IPython.frontend._process import PipedProcess
19 from IPython.frontend.process import PipedProcess
20 from IPython.testing import decorators as testdec
20 from IPython.testing import decorators as testdec
21
21
22
22
@@ -65,7 +65,24 b' _DEFAULT_STYLE = {'
65 'tripledouble' : 'fore:#7F0000',
65 'tripledouble' : 'fore:#7F0000',
66 'class' : 'fore:#0000FF,bold,underline',
66 'class' : 'fore:#0000FF,bold,underline',
67 'def' : 'fore:#007F7F,bold',
67 'def' : 'fore:#007F7F,bold',
68 'operator' : 'bold'
68 'operator' : 'bold',
69
70 # Default colors
71 'trace' : '#FAFAF1', # Nice green
72 'stdout' : '#FDFFD3', # Nice yellow
73 'stderr' : '#FFF1F1', # Nice red
74
75 # Default scintilla settings
76 'antialiasing' : True,
77 'carret_color' : 'BLACK',
78 'background_color' :'WHITE',
79
80 #prompt definition
81 'prompt_in1' : \
82 '\n\x01\x1b[0;34m\x02In [\x01\x1b[1;34m\x02$number\x01\x1b[0;34m\x02]: \x01\x1b[0m\x02',
83
84 'prompt_out': \
85 '\x01\x1b[0;31m\x02Out[\x01\x1b[1;31m\x02$number\x01\x1b[0;31m\x02]: \x01\x1b[0m\x02',
69 }
86 }
70
87
71 # new style numbers
88 # new style numbers
@@ -88,6 +105,9 b" ANSI_STYLES = {'0;30': [0, 'BLACK'], '0;31': [1, 'RED'],"
88 [13, 'MEDIUM VIOLET RED'],
105 [13, 'MEDIUM VIOLET RED'],
89 '1;36': [14, 'LIGHT STEEL BLUE'], '1;37': [15, 'YELLOW']}
106 '1;36': [14, 'LIGHT STEEL BLUE'], '1;37': [15, 'YELLOW']}
90
107
108 # XXX: Maybe one day we should factor this code with ColorANSI. Right now
109 # ColorANSI is hard to reuse and makes our code more complex.
110
91 #we define platform specific fonts
111 #we define platform specific fonts
92 if wx.Platform == '__WXMSW__':
112 if wx.Platform == '__WXMSW__':
93 FACES = { 'times': 'Times New Roman',
113 FACES = { 'times': 'Times New Roman',
@@ -274,35 +294,21 b' class ConsoleWidget(editwindow.EditWindow):'
274
294
275
295
276 def configure_scintilla(self):
296 def configure_scintilla(self):
277
297 """ Set up all the styling option of the embedded scintilla
278 p = self.style
298 widget.
299 """
300 p = self.style.copy()
279
301
280 #First we define the special background colors
281 if 'trace' in p:
282 _COMPLETE_BUFFER_BG = p['trace']
283 else:
284 _COMPLETE_BUFFER_BG = '#FAFAF1' # Nice green
285
286 if 'stdout' in p:
287 _INPUT_BUFFER_BG = p['stdout']
288 else:
289 _INPUT_BUFFER_BG = '#FDFFD3' # Nice yellow
290
291 if 'stderr' in p:
292 _ERROR_BG = p['stderr']
293 else:
294 _ERROR_BG = '#FFF1F1' # Nice red
295
296 # Marker for complete buffer.
302 # Marker for complete buffer.
297 self.MarkerDefine(_COMPLETE_BUFFER_MARKER, stc.STC_MARK_BACKGROUND,
303 self.MarkerDefine(_COMPLETE_BUFFER_MARKER, stc.STC_MARK_BACKGROUND,
298 background = _COMPLETE_BUFFER_BG)
304 background=p['trace'])
299
305
300 # Marker for current input buffer.
306 # Marker for current input buffer.
301 self.MarkerDefine(_INPUT_MARKER, stc.STC_MARK_BACKGROUND,
307 self.MarkerDefine(_INPUT_MARKER, stc.STC_MARK_BACKGROUND,
302 background = _INPUT_BUFFER_BG)
308 background=p['stdout'])
303 # Marker for tracebacks.
309 # Marker for tracebacks.
304 self.MarkerDefine(_ERROR_MARKER, stc.STC_MARK_BACKGROUND,
310 self.MarkerDefine(_ERROR_MARKER, stc.STC_MARK_BACKGROUND,
305 background = _ERROR_BG)
311 background=p['stderr'])
306
312
307 self.SetEOLMode(stc.STC_EOL_LF)
313 self.SetEOLMode(stc.STC_EOL_LF)
308
314
@@ -326,10 +332,7 b' class ConsoleWidget(editwindow.EditWindow):'
326 self.SetWrapMode(stc.STC_WRAP_WORD)
332 self.SetWrapMode(stc.STC_WRAP_WORD)
327 self.SetBufferedDraw(True)
333 self.SetBufferedDraw(True)
328
334
329 if 'antialiasing' in p:
335 self.SetUseAntiAliasing(p['antialiasing'])
330 self.SetUseAntiAliasing(p['antialiasing'])
331 else:
332 self.SetUseAntiAliasing(True)
333
336
334 self.SetLayoutCache(stc.STC_CACHE_PAGE)
337 self.SetLayoutCache(stc.STC_CACHE_PAGE)
335 self.SetUndoCollection(False)
338 self.SetUndoCollection(False)
@@ -357,15 +360,9 b' class ConsoleWidget(editwindow.EditWindow):'
357
360
358 # styles
361 # styles
359
362
360 if 'carret_color' in p:
363 self.SetCaretForeground(p['carret_color'])
361 self.SetCaretForeground(p['carret_color'])
362 else:
363 self.SetCaretForeground('BLACK')
364
364
365 if 'background_color' in p:
365 background_color = p['background_color']
366 background_color = p['background_color']
367 else:
368 background_color = 'WHITE'
369
366
370 if 'default' in p:
367 if 'default' in p:
371 if 'back' not in p['default']:
368 if 'back' not in p['default']:
@@ -383,70 +380,42 b' class ConsoleWidget(editwindow.EditWindow):'
383 background_color,
380 background_color,
384 self.faces['size'], self.faces['mono']))
381 self.faces['size'], self.faces['mono']))
385
382
386 #all styles = default one
387 self.StyleClearAll()
383 self.StyleClearAll()
388
384
389 # XXX: two lines below are usefull if not using the lexer
385 # XXX: two lines below are usefull if not using the lexer
390 #for style in self.ANSI_STYLES.values():
386 #for style in self.ANSI_STYLES.values():
391 # self.StyleSetSpec(style[0], "bold,fore:%s" % style[1])
387 # self.StyleSetSpec(style[0], "bold,fore:%s" % style[1])
392
388
393 #prompt definition
389 # prompt definition
394 if 'prompt_in1' in p:
390 self.prompt_in1 = p['prompt_in1']
395 self.prompt_in1 = p['prompt_in1']
391 self.prompt_out = p['prompt_out']
396 else:
397 self.prompt_in1 = \
398 '\n\x01\x1b[0;34m\x02In [\x01\x1b[1;34m\x02$number\x01\x1b[0;34m\x02]: \x01\x1b[0m\x02'
399
400 if 'prompt_out' in p:
401 self.prompt_out = p['prompt_out']
402 else:
403 self.prompt_out = \
404 '\x01\x1b[0;31m\x02Out[\x01\x1b[1;31m\x02$number\x01\x1b[0;31m\x02]: \x01\x1b[0m\x02'
405
392
406 self.output_prompt_template = string.Template(self.prompt_out)
393 self.output_prompt_template = string.Template(self.prompt_out)
407 self.input_prompt_template = string.Template(self.prompt_in1)
394 self.input_prompt_template = string.Template(self.prompt_in1)
408
395
409 if 'stdout' in p:
396 self.StyleSetSpec(_STDOUT_STYLE, p['stdout'])
410 self.StyleSetSpec(_STDOUT_STYLE, p['stdout'])
397 self.StyleSetSpec(_STDERR_STYLE, p['stderr'])
411 if 'stderr' in p:
398 self.StyleSetSpec(_TRACE_STYLE, p['trace'])
412 self.StyleSetSpec(_STDERR_STYLE, p['stderr'])
399 self.StyleSetSpec(stc.STC_STYLE_BRACELIGHT, p['bracegood'])
413 if 'trace' in p:
400 self.StyleSetSpec(stc.STC_STYLE_BRACEBAD, p['bracebad'])
414 self.StyleSetSpec(_TRACE_STYLE, p['trace'])
401 self.StyleSetSpec(stc.STC_P_COMMENTLINE, p['comment'])
415 if 'bracegood' in p:
402 self.StyleSetSpec(stc.STC_P_NUMBER, p['number'])
416 self.StyleSetSpec(stc.STC_STYLE_BRACELIGHT, p['bracegood'])
403 self.StyleSetSpec(stc.STC_P_STRING, p['string'])
417 if 'bracebad' in p:
404 self.StyleSetSpec(stc.STC_P_CHARACTER, p['char'])
418 self.StyleSetSpec(stc.STC_STYLE_BRACEBAD, p['bracebad'])
405 self.StyleSetSpec(stc.STC_P_WORD, p['keyword'])
419 if 'comment' in p:
406 self.StyleSetSpec(stc.STC_P_WORD2, p['keyword'])
420 self.StyleSetSpec(stc.STC_P_COMMENTLINE, p['comment'])
407 self.StyleSetSpec(stc.STC_P_TRIPLE, p['triple'])
421 if 'number' in p:
408 self.StyleSetSpec(stc.STC_P_TRIPLEDOUBLE, p['tripledouble'])
422 self.StyleSetSpec(stc.STC_P_NUMBER, p['number'])
409 self.StyleSetSpec(stc.STC_P_CLASSNAME, p['class'])
423 if 'string' in p:
410 self.StyleSetSpec(stc.STC_P_DEFNAME, p['def'])
424 self.StyleSetSpec(stc.STC_P_STRING, p['string'])
411 self.StyleSetSpec(stc.STC_P_OPERATOR, p['operator'])
425 if 'char' in p:
412 self.StyleSetSpec(stc.STC_P_COMMENTBLOCK, p['comment'])
426 self.StyleSetSpec(stc.STC_P_CHARACTER, p['char'])
413
427 if 'keyword' in p:
414 edge_column = p['edge_column']
428 self.StyleSetSpec(stc.STC_P_WORD, p['keyword'])
415 if edge_column is not None and edge_column > 0:
429 if 'keyword' in p:
416 #we add a vertical line to console widget
430 self.StyleSetSpec(stc.STC_P_WORD2, p['keyword'])
417 self.SetEdgeMode(stc.STC_EDGE_LINE)
431 if 'triple' in p:
418 self.SetEdgeColumn(edge_column)
432 self.StyleSetSpec(stc.STC_P_TRIPLE, p['triple'])
433 if 'tripledouble' in p:
434 self.StyleSetSpec(stc.STC_P_TRIPLEDOUBLE, p['tripledouble'])
435 if 'class' in p:
436 self.StyleSetSpec(stc.STC_P_CLASSNAME, p['class'])
437 if 'def' in p:
438 self.StyleSetSpec(stc.STC_P_DEFNAME, p['def'])
439 if 'operator' in p:
440 self.StyleSetSpec(stc.STC_P_OPERATOR, p['operator'])
441 if 'comment' in p:
442 self.StyleSetSpec(stc.STC_P_COMMENTBLOCK, p['comment'])
443
444 if 'edge_column' in p:
445 edge_column = p['edge_column']
446 if edge_column is not None and edge_column > 0:
447 #we add a vertical line to console widget
448 self.SetEdgeMode(stc.STC_EDGE_LINE)
449 self.SetEdgeColumn(88)
450
419
451
420
452 #--------------------------------------------------------------------------
421 #--------------------------------------------------------------------------
@@ -32,7 +32,7 b' import wx'
32 from wx import stc
32 from wx import stc
33
33
34 # Ipython-specific imports.
34 # Ipython-specific imports.
35 from IPython.frontend._process import PipedProcess
35 from IPython.frontend.process import PipedProcess
36 from console_widget import ConsoleWidget, _COMPLETE_BUFFER_MARKER, \
36 from console_widget import ConsoleWidget, _COMPLETE_BUFFER_MARKER, \
37 _ERROR_MARKER, _INPUT_MARKER
37 _ERROR_MARKER, _INPUT_MARKER
38 from IPython.frontend.prefilterfrontend import PrefilterFrontEnd
38 from IPython.frontend.prefilterfrontend import PrefilterFrontEnd
@@ -507,8 +507,9 b' class WxController(ConsoleWidget, PrefilterFrontEnd):'
507 new_lines = []
507 new_lines = []
508 if self._input_state == 'readline':
508 if self._input_state == 'readline':
509 position = self.GetCurrentPos()
509 position = self.GetCurrentPos()
510 continuation_prompt = self.continuation_prompt()[:-1]
510 for line in self.input_buffer.split('\n'):
511 for line in self.input_buffer.split('\n'):
511 if not line == self.continuation_prompt()[:-1]:
512 if not line == continuation_prompt:
512 new_lines.append(line)
513 new_lines.append(line)
513 self.input_buffer = '\n'.join(new_lines)
514 self.input_buffer = '\n'.join(new_lines)
514 self.GotoPos(position)
515 self.GotoPos(position)
@@ -528,9 +529,11 b' class WxController(ConsoleWidget, PrefilterFrontEnd):'
528 # input_buffer filters this out.
529 # input_buffer filters this out.
529 if sys.platform == 'win32':
530 if sys.platform == 'win32':
530 self.input_buffer = self.input_buffer
531 self.input_buffer = self.input_buffer
532 old_prompt_num = self.current_prompt_pos
531 has_executed = PrefilterFrontEnd._on_enter(self,
533 has_executed = PrefilterFrontEnd._on_enter(self,
532 new_line_pos=new_line_pos)
534 new_line_pos=new_line_pos)
533 if not has_executed:
535 if old_prompt_num == self.current_prompt_pos:
536 # No execution has happened
534 self.GotoPos(self.GetLineEndPosition(current_line_num + 1))
537 self.GotoPos(self.GetLineEndPosition(current_line_num + 1))
535 return has_executed
538 return has_executed
536
539
@@ -109,7 +109,7 b' def find_packages():'
109 add_package(packages, 'gui')
109 add_package(packages, 'gui')
110 add_package(packages, 'gui.wx')
110 add_package(packages, 'gui.wx')
111 add_package(packages, 'frontend', tests=True)
111 add_package(packages, 'frontend', tests=True)
112 add_package(packages, 'frontend._process')
112 add_package(packages, 'frontend.process')
113 add_package(packages, 'frontend.wx')
113 add_package(packages, 'frontend.wx')
114 add_package(packages, 'frontend.cocoa', tests=True)
114 add_package(packages, 'frontend.cocoa', tests=True)
115 add_package(packages, 'kernel', config=True, tests=True, scripts=True)
115 add_package(packages, 'kernel', config=True, tests=True, scripts=True)
General Comments 0
You need to be logged in to leave comments. Login now