##// END OF EJS Templates
Traceback capture now working.
Gael Varoquaux -
Show More
@@ -31,6 +31,11 b' class LineFrontEndBase(FrontEndBase):'
31 # Are we entering multi line input?
31 # Are we entering multi line input?
32 multi_line_input = False
32 multi_line_input = False
33
33
34 # We need to keep the prompt number, to be able to increment
35 # it when there is an exception.
36 prompt_number = 1
37
38
34 #--------------------------------------------------------------------------
39 #--------------------------------------------------------------------------
35 # Public API
40 # Public API
36 #--------------------------------------------------------------------------
41 #--------------------------------------------------------------------------
@@ -69,41 +74,67 b' class LineFrontEndBase(FrontEndBase):'
69 self.output_prompt % result['number'],
74 self.output_prompt % result['number'],
70 result['display']['pprint']
75 result['display']['pprint']
71 ) )
76 ) )
72
77
73
78
74 def render_error(self, failure):
79 def render_error(self, failure):
75 self.insert_text('\n\n'+str(failure)+'\n\n')
80 self.insert_text('\n\n'+str(failure)+'\n\n')
76 return failure
81 return failure
82
83
84 def prefilter_input(self, string):
85 string = string.replace('\r\n', '\n')
86 string = string.replace('\t', 4*' ')
87 # Clean the trailing whitespace
88 string = '\n'.join(l.rstrip() for l in string.split('\n'))
89 return string
90
91
92 def is_complete(self, string):
93 if ( self.multi_line_input and not re.findall(r"\n[\t ]*$", string)):
94 return False
95 else:
96 return FrontEndBase.is_complete(self, string)
77
97
78
98
99 def execute(self, python_string, raw_string=None):
100 """ Send the python_string to the interpreter, stores the
101 raw_string in the history and starts a new prompt.
102 """
103 if raw_string is None:
104 raw_string = string
105 # Create a false result, in case there is an exception
106 result = dict(number=self.prompt_number)
107 try:
108 self.history.input_cache[-1] = raw_string
109 result = self.shell.execute(python_string)
110 self.render_result(result)
111 except Exception, e:
112 self.show_traceback()
113 finally:
114 self.prompt_number += 1
115 self.new_prompt(self.prompt % (result['number'] + 1))
116 self.multi_line_input = False
117 # Start a new empty history entry
118 self._add_history(None, '')
119 # The result contains useful information that can be used
120 # elsewhere.
121 self.last_result = result
122
123
79 def _on_enter(self):
124 def _on_enter(self):
80 """ Called when the return key is pressed in a line editing
125 """ Called when the return key is pressed in a line editing
81 buffer.
126 buffer.
82 """
127 """
83 current_buffer = self.get_current_edit_buffer()
128 current_buffer = self.get_current_edit_buffer()
84 current_buffer = current_buffer.replace('\r\n', '\n')
129 cleaned_buffer = self.prefilter_input(current_buffer)
85 current_buffer = current_buffer.replace('\t', 4*' ')
130 if self.is_complete(cleaned_buffer):
86 cleaned_buffer = '\n'.join(l.rstrip()
131 self.execute(cleaned_buffer, raw_string=current_buffer)
87 for l in current_buffer.split('\n'))
88 if ( not self.multi_line_input
89 or re.findall(r"\n[\t ]*$", cleaned_buffer)):
90 if self.is_complete(cleaned_buffer):
91 self.history.input_cache[-1] = \
92 current_buffer
93 result = self.shell.execute(cleaned_buffer)
94 self.render_result(result)
95 self.new_prompt(self.prompt % (result['number'] + 1))
96 self.multi_line_input = False
97 # Start a new empty history entry
98 self._add_history(None, '')
99 else:
100 if self.multi_line_input:
101 self.write('\n' + self._get_indent_string(current_buffer))
102 else:
103 self.multi_line_input = True
104 self.write('\n\t')
105 else:
132 else:
106 self.write('\n'+self._get_indent_string(current_buffer))
133 if self.multi_line_input:
134 self.write('\n' + self._get_indent_string(current_buffer))
135 else:
136 self.multi_line_input = True
137 self.write('\n\t')
107
138
108
139
109 #--------------------------------------------------------------------------
140 #--------------------------------------------------------------------------
@@ -297,7 +297,7 b' class ConsoleWidget(editwindow.EditWindow):'
297 possibilities.sort() # Python sorts are case sensitive
297 possibilities.sort() # Python sorts are case sensitive
298 self.AutoCompSetIgnoreCase(False)
298 self.AutoCompSetIgnoreCase(False)
299 self.AutoCompSetAutoHide(False)
299 self.AutoCompSetAutoHide(False)
300 #let compute the length ot last word
300 #let compute the length ot text)last word
301 splitter = [' ', '(', '[', '{']
301 splitter = [' ', '(', '[', '{']
302 last_word = self.get_current_edit_buffer()
302 last_word = self.get_current_edit_buffer()
303 for breaker in splitter:
303 for breaker in splitter:
@@ -309,7 +309,7 b' class ConsoleWidget(editwindow.EditWindow):'
309 maxrange = self.GetScrollRange(wx.VERTICAL)
309 maxrange = self.GetScrollRange(wx.VERTICAL)
310 self.ScrollLines(maxrange)
310 self.ScrollLines(maxrange)
311
311
312 def on_enter(self):
312 def _on_enter(self):
313 """ Called when the return key is hit.
313 """ Called when the return key is hit.
314 """
314 """
315 pass
315 pass
@@ -3,7 +3,7 b''
3 # ipython1.frontend.cocoa.tests.test_cocoa_frontend -*-
3 # ipython1.frontend.cocoa.tests.test_cocoa_frontend -*-
4
4
5 """Classes to provide a Wx frontend to the
5 """Classes to provide a Wx frontend to the
6 ipython1.kernel.engineservice.EngineService.
6 IPython.kernel.core.interpreter.
7
7
8 """
8 """
9
9
@@ -24,16 +24,12 b' __docformat__ = "restructuredtext en"'
24 import wx
24 import wx
25 from console_widget import ConsoleWidget
25 from console_widget import ConsoleWidget
26
26
27 from IPython.frontend.linefrontendbase import LineFrontEndBase
27 from IPython.frontend.prefilterfrontend import PrefilterFrontEnd
28
28
29 #-------------------------------------------------------------------------------
29 #-------------------------------------------------------------------------------
30 # Classes to implement the Wx frontend
30 # Classes to implement the Wx frontend
31 #-------------------------------------------------------------------------------
31 #-------------------------------------------------------------------------------
32
32 class IPythonWxController(PrefilterFrontEnd, ConsoleWidget):
33
34
35
36 class IPythonWxController(LineFrontEndBase, ConsoleWidget):
37
33
38 output_prompt = \
34 output_prompt = \
39 '\n\x01\x1b[0;31m\x02Out[\x01\x1b[1;31m\x02%i\x01\x1b[0;31m\x02]: \x01\x1b[0m\x02'
35 '\n\x01\x1b[0;31m\x02Out[\x01\x1b[1;31m\x02%i\x01\x1b[0;31m\x02]: \x01\x1b[0m\x02'
@@ -48,7 +44,7 b' class IPythonWxController(LineFrontEndBase, ConsoleWidget):'
48 """ Create Shell instance.
44 """ Create Shell instance.
49 """
45 """
50 ConsoleWidget.__init__(self, parent, id, pos, size, style)
46 ConsoleWidget.__init__(self, parent, id, pos, size, style)
51 LineFrontEndBase.__init__(self)
47 PrefilterFrontEnd.__init__(self)
52
48
53 # Capture Character keys
49 # Capture Character keys
54 self.Bind(wx.EVT_KEY_DOWN, self._on_key_down)
50 self.Bind(wx.EVT_KEY_DOWN, self._on_key_down)
@@ -38,6 +38,8 b' class TracebackTrap(object):'
38 def hook(self, *args):
38 def hook(self, *args):
39 """ This method actually implements the hook.
39 """ This method actually implements the hook.
40 """
40 """
41 import sys
42 print >>sys.stderr, "I have been raised"
41
43
42 self.args = args
44 self.args = args
43
45
General Comments 0
You need to be logged in to leave comments. Login now