##// END OF EJS Templates
Synchronous stdout/stderr output.
Gael Varoquaux -
Show More
@@ -0,0 +1,67 b''
1 # encoding: utf-8
2
3 """ Redirects stdout/stderr to given write methods."""
4
5 __docformat__ = "restructuredtext en"
6
7 #-------------------------------------------------------------------------------
8 # Copyright (C) 2008 The IPython Development Team
9 #
10 # Distributed under the terms of the BSD License. The full license is in
11 # the file COPYING, distributed as part of this software.
12 #-------------------------------------------------------------------------------
13
14 #-------------------------------------------------------------------------------
15 # Imports
16 #-------------------------------------------------------------------------------
17
18 import sys
19 from IPython.kernel.core.output_trap import OutputTrap
20
21 class FileLike(object):
22 """ FileLike object that redirects all write to a callback.
23
24 Only the write-related methods are implemented, as well as those
25 required to read a StringIO.
26 """
27 closed = False
28
29 def __init__(self, write):
30 self.write = write
31
32 def flush(self):
33 pass
34
35 def close(self):
36 pass
37
38 def writelines(self, lines):
39 for line in lines:
40 self.write(line)
41
42 def isatty(self):
43 return False
44
45 def getvalue(self):
46 return ''
47
48
49 class SyncOutputTrap(OutputTrap):
50 """ Object which redirect text sent to stdout and stderr to write
51 callbacks.
52 """
53
54 def __init__(self, write_out, write_err):
55 # Store callbacks
56 self.out = FileLike(write_out)
57 self.err = FileLike(write_err)
58
59 # Boolean to check if the stdout/stderr hook is set.
60 self.out_set = False
61 self.err_set = False
62
63 def clear(self):
64 """ Clear out the buffers.
65 """
66 pass
67
@@ -221,6 +221,7 b' class ConsoleWidget(editwindow.EditWindow):'
221 segments.pop(i)
221 segments.pop(i)
222
222
223 self.GotoPos(self.GetLength())
223 self.GotoPos(self.GetLength())
224 wx.Yield()
224
225
225
226
226 def new_prompt(self, prompt):
227 def new_prompt(self, prompt):
@@ -350,6 +351,7 b' class ConsoleWidget(editwindow.EditWindow):'
350 if event.KeyCode in (13, wx.WXK_NUMPAD_ENTER) and \
351 if event.KeyCode in (13, wx.WXK_NUMPAD_ENTER) and \
351 event.Modifiers in (wx.MOD_NONE, wx.MOD_WIN):
352 event.Modifiers in (wx.MOD_NONE, wx.MOD_WIN):
352 catched = True
353 catched = True
354 self.CallTipCancel()
353 self.write('\n')
355 self.write('\n')
354 self._on_enter()
356 self._on_enter()
355
357
@@ -41,7 +41,7 b' _RUNNING_BUFFER_MARKER = 31'
41 class IPythonWxController(PrefilterFrontEnd, ConsoleWidget):
41 class IPythonWxController(PrefilterFrontEnd, ConsoleWidget):
42
42
43 output_prompt = \
43 output_prompt = \
44 '\n\x01\x1b[0;31m\x02Out[\x01\x1b[1;31m\x02%i\x01\x1b[0;31m\x02]: \x01\x1b[0m\x02'
44 '\x01\x1b[0;31m\x02Out[\x01\x1b[1;31m\x02%i\x01\x1b[0;31m\x02]: \x01\x1b[0m\x02'
45
45
46 #--------------------------------------------------------------------------
46 #--------------------------------------------------------------------------
47 # Public API
47 # Public API
@@ -125,9 +125,9 b' class IPythonWxController(PrefilterFrontEnd, ConsoleWidget):'
125 self.MarkerAdd(i, 31)
125 self.MarkerAdd(i, 31)
126 # Update the display:
126 # Update the display:
127 wx.Yield()
127 wx.Yield()
128 # Remove the trailing "\n" for cleaner display
128 ## Remove the trailing "\n" for cleaner display
129 self.SetSelection(self.GetLength()-1, self.GetLength())
129 #self.SetSelection(self.GetLength()-1, self.GetLength())
130 self.ReplaceSelection('')
130 #self.ReplaceSelection('')
131 self.GotoPos(self.GetLength())
131 self.GotoPos(self.GetLength())
132 PrefilterFrontEnd.execute(self, python_string, raw_string=raw_string)
132 PrefilterFrontEnd.execute(self, python_string, raw_string=raw_string)
133
133
@@ -20,13 +20,11 b' __docformat__ = "restructuredtext en"'
20 #-------------------------------------------------------------------------------
20 #-------------------------------------------------------------------------------
21
21
22 # Standard library imports.
22 # Standard library imports.
23 from compiler.ast import Discard
24 from types import FunctionType
23 from types import FunctionType
25
24
26 import __builtin__
25 import __builtin__
27 import codeop
26 import codeop
28 import compiler
27 import compiler
29 import pprint
30 import sys
28 import sys
31 import traceback
29 import traceback
32
30
General Comments 0
You need to be logged in to leave comments. Login now