##// 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 334 self.execute(cleaned_buffer, raw_string=current_buffer)
335 335 return True
336 336 else:
337 # Start a new line.
337 338 new_line_pos = -new_line_pos
338 339 lines = current_buffer.split('\n')[:-1]
339 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 343 new_line = self.continuation_prompt() + \
341 344 self._get_indent_string('\n'.join(
342 345 prompt_less_lines[:new_line_pos-1]))
343 346 if len(lines) == 1:
347 # We are starting a first continuation line. Indent it.
344 348 new_line += '\t'
345 349 elif current_buffer[:-1].split('\n')[-1].rstrip().endswith(':'):
350 # The last line ends with ":", autoindent the new line.
346 351 new_line += '\t'
347 352
348 353 if new_line_pos == 0:
1 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
1 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
@@ -14,6 +14,7 b' __docformat__ = "restructuredtext en"'
14 14
15 15 from IPython.frontend.linefrontendbase import LineFrontEndBase
16 16 from copy import deepcopy
17 import nose.tools as nt
17 18
18 19 class ConcreteLineFrontEnd(LineFrontEndBase):
19 20 """ A concrete class to test the LineFrontEndBase.
@@ -29,10 +30,8 b' def test_is_complete():'
29 30 """ Tests line completion heuristic.
30 31 """
31 32 frontend = ConcreteLineFrontEnd()
32 assert not frontend.is_complete('for x in \\')
33 assert not frontend.is_complete('for x in (1, ):')
34 assert frontend.is_complete('for x in (1, ):\n pass')
33 yield nt.assert_true, not frontend.is_complete('for x in \\')
34 yield nt.assert_true, not frontend.is_complete('for x in (1, ):')
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 111 f.input_buffer += 'print 1'
112 112 f._on_enter()
113 113 out_value = f.out.getvalue()
114 assert_equal(out_value, '')
114 yield assert_equal, out_value, ''
115 115 f._on_enter()
116 116 out_value = f.out.getvalue()
117 assert_equal(out_value, '1\n')
117 yield assert_equal, out_value, '1\n'
118 118 f = TestPrefilterFrontEnd()
119 119 f.input_buffer='(1 +'
120 120 f._on_enter()
121 121 f.input_buffer += '0)'
122 122 f._on_enter()
123 123 out_value = f.out.getvalue()
124 assert_equal(out_value, '')
124 yield assert_equal, out_value, ''
125 125 f._on_enter()
126 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 130 @isolate_ipython0
@@ -137,13 +137,13 b' def test_capture():'
137 137 'import os; out=os.fdopen(1, "w"); out.write("1") ; out.flush()'
138 138 f._on_enter()
139 139 out_value = f.out.getvalue()
140 assert_equal(out_value, '1')
140 yield assert_equal, out_value, '1'
141 141 f = TestPrefilterFrontEnd()
142 142 f.input_buffer = \
143 143 'import os; out=os.fdopen(2, "w"); out.write("1") ; out.flush()'
144 144 f._on_enter()
145 145 out_value = f.out.getvalue()
146 assert_equal(out_value, '1')
146 yield assert_equal, out_value, '1'
147 147
148 148
149 149 @isolate_ipython0
@@ -191,8 +191,8 b' def test_completion_simple():'
191 191 f.input_buffer = 'zz'
192 192 f.complete_current_input()
193 193 out_value = f.out.getvalue()
194 assert_equal(out_value, '\nzzza zzzb ')
195 assert_equal(f.input_buffer, 'zzz')
194 yield assert_equal, out_value, '\nzzza zzzb '
195 yield assert_equal, f.input_buffer, 'zzz'
196 196
197 197
198 198 @isolate_ipython0
@@ -207,8 +207,8 b' def test_completion_parenthesis():'
207 207 f.input_buffer = 'map(zz'
208 208 f.complete_current_input()
209 209 out_value = f.out.getvalue()
210 assert_equal(out_value, '\nzzza zzzb ')
211 assert_equal(f.input_buffer, 'map(zzz')
210 yield assert_equal, out_value, '\nzzza zzzb '
211 yield assert_equal, f.input_buffer, 'map(zzz'
212 212
213 213
214 214 @isolate_ipython0
@@ -16,7 +16,7 b' from cStringIO import StringIO'
16 16 from time import sleep
17 17 import sys
18 18
19 from IPython.frontend._process import PipedProcess
19 from IPython.frontend.process import PipedProcess
20 20 from IPython.testing import decorators as testdec
21 21
22 22
@@ -65,7 +65,24 b' _DEFAULT_STYLE = {'
65 65 'tripledouble' : 'fore:#7F0000',
66 66 'class' : 'fore:#0000FF,bold,underline',
67 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 88 # new style numbers
@@ -88,6 +105,9 b" ANSI_STYLES = {'0;30': [0, 'BLACK'], '0;31': [1, 'RED'],"
88 105 [13, 'MEDIUM VIOLET RED'],
89 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 111 #we define platform specific fonts
92 112 if wx.Platform == '__WXMSW__':
93 113 FACES = { 'times': 'Times New Roman',
@@ -274,35 +294,21 b' class ConsoleWidget(editwindow.EditWindow):'
274 294
275 295
276 296 def configure_scintilla(self):
277
278 p = self.style
297 """ Set up all the styling option of the embedded scintilla
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 302 # Marker for complete buffer.
297 303 self.MarkerDefine(_COMPLETE_BUFFER_MARKER, stc.STC_MARK_BACKGROUND,
298 background = _COMPLETE_BUFFER_BG)
304 background=p['trace'])
299 305
300 306 # Marker for current input buffer.
301 307 self.MarkerDefine(_INPUT_MARKER, stc.STC_MARK_BACKGROUND,
302 background = _INPUT_BUFFER_BG)
308 background=p['stdout'])
303 309 # Marker for tracebacks.
304 310 self.MarkerDefine(_ERROR_MARKER, stc.STC_MARK_BACKGROUND,
305 background = _ERROR_BG)
311 background=p['stderr'])
306 312
307 313 self.SetEOLMode(stc.STC_EOL_LF)
308 314
@@ -326,10 +332,7 b' class ConsoleWidget(editwindow.EditWindow):'
326 332 self.SetWrapMode(stc.STC_WRAP_WORD)
327 333 self.SetBufferedDraw(True)
328 334
329 if 'antialiasing' in p:
330 self.SetUseAntiAliasing(p['antialiasing'])
331 else:
332 self.SetUseAntiAliasing(True)
335 self.SetUseAntiAliasing(p['antialiasing'])
333 336
334 337 self.SetLayoutCache(stc.STC_CACHE_PAGE)
335 338 self.SetUndoCollection(False)
@@ -357,15 +360,9 b' class ConsoleWidget(editwindow.EditWindow):'
357 360
358 361 # styles
359 362
360 if 'carret_color' in p:
361 self.SetCaretForeground(p['carret_color'])
362 else:
363 self.SetCaretForeground('BLACK')
363 self.SetCaretForeground(p['carret_color'])
364 364
365 if 'background_color' in p:
366 background_color = p['background_color']
367 else:
368 background_color = 'WHITE'
365 background_color = p['background_color']
369 366
370 367 if 'default' in p:
371 368 if 'back' not in p['default']:
@@ -383,70 +380,42 b' class ConsoleWidget(editwindow.EditWindow):'
383 380 background_color,
384 381 self.faces['size'], self.faces['mono']))
385 382
386 #all styles = default one
387 383 self.StyleClearAll()
388 384
389 385 # XXX: two lines below are usefull if not using the lexer
390 386 #for style in self.ANSI_STYLES.values():
391 387 # self.StyleSetSpec(style[0], "bold,fore:%s" % style[1])
392 388
393 #prompt definition
394 if 'prompt_in1' in p:
395 self.prompt_in1 = p['prompt_in1']
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'
389 # prompt definition
390 self.prompt_in1 = p['prompt_in1']
391 self.prompt_out = p['prompt_out']
405 392
406 393 self.output_prompt_template = string.Template(self.prompt_out)
407 394 self.input_prompt_template = string.Template(self.prompt_in1)
408 395
409 if 'stdout' in p:
410 self.StyleSetSpec(_STDOUT_STYLE, p['stdout'])
411 if 'stderr' in p:
412 self.StyleSetSpec(_STDERR_STYLE, p['stderr'])
413 if 'trace' in p:
414 self.StyleSetSpec(_TRACE_STYLE, p['trace'])
415 if 'bracegood' in p:
416 self.StyleSetSpec(stc.STC_STYLE_BRACELIGHT, p['bracegood'])
417 if 'bracebad' in p:
418 self.StyleSetSpec(stc.STC_STYLE_BRACEBAD, p['bracebad'])
419 if 'comment' in p:
420 self.StyleSetSpec(stc.STC_P_COMMENTLINE, p['comment'])
421 if 'number' in p:
422 self.StyleSetSpec(stc.STC_P_NUMBER, p['number'])
423 if 'string' in p:
424 self.StyleSetSpec(stc.STC_P_STRING, p['string'])
425 if 'char' in p:
426 self.StyleSetSpec(stc.STC_P_CHARACTER, p['char'])
427 if 'keyword' in p:
428 self.StyleSetSpec(stc.STC_P_WORD, p['keyword'])
429 if 'keyword' in p:
430 self.StyleSetSpec(stc.STC_P_WORD2, p['keyword'])
431 if 'triple' in p:
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)
396 self.StyleSetSpec(_STDOUT_STYLE, p['stdout'])
397 self.StyleSetSpec(_STDERR_STYLE, p['stderr'])
398 self.StyleSetSpec(_TRACE_STYLE, p['trace'])
399 self.StyleSetSpec(stc.STC_STYLE_BRACELIGHT, p['bracegood'])
400 self.StyleSetSpec(stc.STC_STYLE_BRACEBAD, p['bracebad'])
401 self.StyleSetSpec(stc.STC_P_COMMENTLINE, p['comment'])
402 self.StyleSetSpec(stc.STC_P_NUMBER, p['number'])
403 self.StyleSetSpec(stc.STC_P_STRING, p['string'])
404 self.StyleSetSpec(stc.STC_P_CHARACTER, p['char'])
405 self.StyleSetSpec(stc.STC_P_WORD, p['keyword'])
406 self.StyleSetSpec(stc.STC_P_WORD2, p['keyword'])
407 self.StyleSetSpec(stc.STC_P_TRIPLE, p['triple'])
408 self.StyleSetSpec(stc.STC_P_TRIPLEDOUBLE, p['tripledouble'])
409 self.StyleSetSpec(stc.STC_P_CLASSNAME, p['class'])
410 self.StyleSetSpec(stc.STC_P_DEFNAME, p['def'])
411 self.StyleSetSpec(stc.STC_P_OPERATOR, p['operator'])
412 self.StyleSetSpec(stc.STC_P_COMMENTBLOCK, p['comment'])
413
414 edge_column = p['edge_column']
415 if edge_column is not None and edge_column > 0:
416 #we add a vertical line to console widget
417 self.SetEdgeMode(stc.STC_EDGE_LINE)
418 self.SetEdgeColumn(edge_column)
450 419
451 420
452 421 #--------------------------------------------------------------------------
@@ -32,7 +32,7 b' import wx'
32 32 from wx import stc
33 33
34 34 # Ipython-specific imports.
35 from IPython.frontend._process import PipedProcess
35 from IPython.frontend.process import PipedProcess
36 36 from console_widget import ConsoleWidget, _COMPLETE_BUFFER_MARKER, \
37 37 _ERROR_MARKER, _INPUT_MARKER
38 38 from IPython.frontend.prefilterfrontend import PrefilterFrontEnd
@@ -507,8 +507,9 b' class WxController(ConsoleWidget, PrefilterFrontEnd):'
507 507 new_lines = []
508 508 if self._input_state == 'readline':
509 509 position = self.GetCurrentPos()
510 continuation_prompt = self.continuation_prompt()[:-1]
510 511 for line in self.input_buffer.split('\n'):
511 if not line == self.continuation_prompt()[:-1]:
512 if not line == continuation_prompt:
512 513 new_lines.append(line)
513 514 self.input_buffer = '\n'.join(new_lines)
514 515 self.GotoPos(position)
@@ -528,9 +529,11 b' class WxController(ConsoleWidget, PrefilterFrontEnd):'
528 529 # input_buffer filters this out.
529 530 if sys.platform == 'win32':
530 531 self.input_buffer = self.input_buffer
532 old_prompt_num = self.current_prompt_pos
531 533 has_executed = PrefilterFrontEnd._on_enter(self,
532 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 537 self.GotoPos(self.GetLineEndPosition(current_line_num + 1))
535 538 return has_executed
536 539
@@ -109,7 +109,7 b' def find_packages():'
109 109 add_package(packages, 'gui')
110 110 add_package(packages, 'gui.wx')
111 111 add_package(packages, 'frontend', tests=True)
112 add_package(packages, 'frontend._process')
112 add_package(packages, 'frontend.process')
113 113 add_package(packages, 'frontend.wx')
114 114 add_package(packages, 'frontend.cocoa', tests=True)
115 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