Show More
@@ -19,11 +19,9 b' import re' | |||
|
19 | 19 | |
|
20 | 20 | import IPython |
|
21 | 21 | |
|
22 | ||
|
23 | 22 | from frontendbase import FrontEndBase |
|
24 | 23 | from IPython.kernel.core.interpreter import Interpreter |
|
25 | 24 | |
|
26 | ||
|
27 | 25 | def common_prefix(strings): |
|
28 | 26 | ref = strings[0] |
|
29 | 27 | prefix = '' |
@@ -156,8 +154,9 b' class LineFrontEndBase(FrontEndBase):' | |||
|
156 | 154 | if self.is_complete(cleaned_buffer): |
|
157 | 155 | self.execute(cleaned_buffer, raw_string=current_buffer) |
|
158 | 156 | else: |
|
159 |
self.write(self._get_indent_string( |
|
|
160 | if current_buffer.rstrip().endswith(':'): | |
|
157 | self.write(self._get_indent_string( | |
|
158 | current_buffer[:-1])) | |
|
159 | if current_buffer[:-1].split('\n')[-1].rstrip().endswith(':'): | |
|
161 | 160 | self.write('\t') |
|
162 | 161 | |
|
163 | 162 |
@@ -23,16 +23,17 b' import wx' | |||
|
23 | 23 | import wx.stc as stc |
|
24 | 24 | |
|
25 | 25 | from wx.py import editwindow |
|
26 | import sys | |
|
27 | LINESEP = '\n' | |
|
28 | if sys.platform == 'win32': | |
|
29 | LINESEP = '\n\r' | |
|
26 | 30 | |
|
27 | 31 | import re |
|
28 | 32 | |
|
29 | 33 | # FIXME: Need to provide an API for non user-generated display on the |
|
30 | 34 | # screen: this should not be editable by the user. |
|
31 | 35 | |
|
32 | if wx.Platform == '__WXMSW__': | |
|
33 | _DEFAULT_SIZE = 80 | |
|
34 | else: | |
|
35 | _DEFAULT_SIZE = 10 | |
|
36 | _DEFAULT_SIZE = 10 | |
|
36 | 37 | |
|
37 | 38 | _DEFAULT_STYLE = { |
|
38 | 39 | 'stdout' : 'fore:#0000FF', |
@@ -94,7 +95,6 b' class ConsoleWidget(editwindow.EditWindow):' | |||
|
94 | 95 | # The color of the carret (call _apply_style() after setting) |
|
95 | 96 | carret_color = 'BLACK' |
|
96 | 97 | |
|
97 | ||
|
98 | 98 | #-------------------------------------------------------------------------- |
|
99 | 99 | # Public API |
|
100 | 100 | #-------------------------------------------------------------------------- |
@@ -114,6 +114,8 b' class ConsoleWidget(editwindow.EditWindow):' | |||
|
114 | 114 | |
|
115 | 115 | |
|
116 | 116 | def configure_scintilla(self): |
|
117 | self.SetEOLMode(stc.STC_EOL_LF) | |
|
118 | ||
|
117 | 119 | # Ctrl"+" or Ctrl "-" can be used to zoomin/zoomout the text inside |
|
118 | 120 | # the widget |
|
119 | 121 | self.CmdKeyAssign(ord('+'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMIN) |
@@ -206,6 +208,7 b' class ConsoleWidget(editwindow.EditWindow):' | |||
|
206 | 208 | text = self.title_pat.sub('', text) |
|
207 | 209 | segments = self.color_pat.split(text) |
|
208 | 210 | segment = segments.pop(0) |
|
211 | self.GotoPos(self.GetLength()) | |
|
209 | 212 | self.StartStyling(self.GetLength(), 0xFF) |
|
210 | 213 | self.AppendText(segment) |
|
211 | 214 | |
@@ -223,7 +226,7 b' class ConsoleWidget(editwindow.EditWindow):' | |||
|
223 | 226 | |
|
224 | 227 | self.GotoPos(self.GetLength()) |
|
225 | 228 | wx.Yield() |
|
226 | ||
|
229 | ||
|
227 | 230 | |
|
228 | 231 | def new_prompt(self, prompt): |
|
229 | 232 | """ Prints a prompt at start of line, and move the start of the |
@@ -250,8 +253,10 b' class ConsoleWidget(editwindow.EditWindow):' | |||
|
250 | 253 | def get_current_edit_buffer(self): |
|
251 | 254 | """ Returns the text in current edit buffer. |
|
252 | 255 | """ |
|
253 |
|
|
|
254 | self.GetLength()) | |
|
256 | current_edit_buffer = self.GetTextRange(self.current_prompt_pos, | |
|
257 | self.GetLength()) | |
|
258 | current_edit_buffer = current_edit_buffer.replace(LINESEP, '\n') | |
|
259 | return current_edit_buffer | |
|
255 | 260 | |
|
256 | 261 | |
|
257 | 262 | #-------------------------------------------------------------------------- |
@@ -293,7 +298,7 b' class ConsoleWidget(editwindow.EditWindow):' | |||
|
293 | 298 | buf.append(symbol.ljust(max_len)) |
|
294 | 299 | pos += 1 |
|
295 | 300 | else: |
|
296 | buf.append(symbol.rstrip() +'\n') | |
|
301 | buf.append(symbol.rstrip() + '\n') | |
|
297 | 302 | pos = 1 |
|
298 | 303 | self.write(''.join(buf)) |
|
299 | 304 | self.new_prompt(self.prompt % (self.last_result['number'] + 1)) |
@@ -316,12 +321,6 b' class ConsoleWidget(editwindow.EditWindow):' | |||
|
316 | 321 | self.ScrollLines(maxrange) |
|
317 | 322 | |
|
318 | 323 | |
|
319 | def _on_enter(self): | |
|
320 | """ Called when the return key is hit. | |
|
321 | """ | |
|
322 | pass | |
|
323 | ||
|
324 | ||
|
325 | 324 | def _on_key_down(self, event, skip=True): |
|
326 | 325 | """ Key press callback used for correcting behavior for |
|
327 | 326 | console-like interfaces: the cursor is constraint to be after |
@@ -354,6 +353,12 b' class ConsoleWidget(editwindow.EditWindow):' | |||
|
354 | 353 | catched = True |
|
355 | 354 | self.CallTipCancel() |
|
356 | 355 | self.write('\n') |
|
356 | # Under windows scintilla seems to be doing funny stuff to the | |
|
357 | # line returns here, but get_current_edit_buffer filters this | |
|
358 | # out. | |
|
359 | if sys.platform == 'win32': | |
|
360 | self.replace_current_edit_buffer( | |
|
361 | self.get_current_edit_buffer()) | |
|
357 | 362 | self._on_enter() |
|
358 | 363 | |
|
359 | 364 | elif event.KeyCode == wx.WXK_HOME: |
@@ -384,7 +389,11 b' class ConsoleWidget(editwindow.EditWindow):' | |||
|
384 | 389 | catched = True |
|
385 | 390 | |
|
386 | 391 | if skip and not catched: |
|
387 | event.Skip() | |
|
392 | # Put the cursor back in the edit region | |
|
393 | if self.GetCurrentPos() < self.current_prompt_pos: | |
|
394 | self.GotoPos(self.current_prompt_pos) | |
|
395 | else: | |
|
396 | event.Skip() | |
|
388 | 397 | |
|
389 | 398 | return catched |
|
390 | 399 |
@@ -44,6 +44,8 b' class WxController(PrefilterFrontEnd, ConsoleWidget):' | |||
|
44 | 44 | |
|
45 | 45 | output_prompt = \ |
|
46 | 46 | '\x01\x1b[0;31m\x02Out[\x01\x1b[1;31m\x02%i\x01\x1b[0;31m\x02]: \x01\x1b[0m\x02' |
|
47 | ||
|
48 | debug = True | |
|
47 | 49 | |
|
48 | 50 | #-------------------------------------------------------------------------- |
|
49 | 51 | # Public API |
@@ -68,7 +70,6 b' class WxController(PrefilterFrontEnd, ConsoleWidget):' | |||
|
68 | 70 | background=_ERROR_BG) |
|
69 | 71 | |
|
70 | 72 | |
|
71 | ||
|
72 | 73 | def do_completion(self): |
|
73 | 74 | """ Do code completion. |
|
74 | 75 | """ |
@@ -240,6 +241,11 b' class WxController(PrefilterFrontEnd, ConsoleWidget):' | |||
|
240 | 241 | else: |
|
241 | 242 | ConsoleWidget._on_key_up(self, event, skip=skip) |
|
242 | 243 | |
|
244 | def _on_enter(self): | |
|
245 | if self.debug: | |
|
246 | import sys | |
|
247 | print >>sys.__stdout__, repr(self.get_current_edit_buffer()) | |
|
248 | PrefilterFrontEnd._on_enter(self) | |
|
243 | 249 | |
|
244 | 250 | def _set_title(self, title): |
|
245 | 251 | return self.Parent.SetTitle(title) |
General Comments 0
You need to be logged in to leave comments.
Login now