Show More
@@ -141,7 +141,7 b' class IFrontEnd(Interface):' | |||||
141 | pass |
|
141 | pass | |
142 |
|
142 | |||
143 |
|
143 | |||
144 |
def get_history_previous(current |
|
144 | def get_history_previous(current_block): | |
145 | """Returns the block previous in the history. Saves currentBlock if |
|
145 | """Returns the block previous in the history. Saves currentBlock if | |
146 | the history_cursor is currently at the end of the input history""" |
|
146 | the history_cursor is currently at the end of the input history""" | |
147 | pass |
|
147 | pass | |
@@ -294,14 +294,14 b' class FrontEndBase(object):' | |||||
294 | return result |
|
294 | return result | |
295 |
|
295 | |||
296 |
|
296 | |||
297 |
def get_history_previous(self, current |
|
297 | def get_history_previous(self, current_block): | |
298 | """ Returns previous history string and decrement history cursor. |
|
298 | """ Returns previous history string and decrement history cursor. | |
299 | """ |
|
299 | """ | |
300 | command = self.history.get_history_item(self.history_cursor - 1) |
|
300 | command = self.history.get_history_item(self.history_cursor - 1) | |
301 |
|
301 | |||
302 | if command is not None: |
|
302 | if command is not None: | |
303 | if(self.history_cursor == len(self.history.input_cache)): |
|
303 | if(self.history_cursor+1 == len(self.history.input_cache)): | |
304 |
self.history.input_cache[self.history_cursor] = current |
|
304 | self.history.input_cache[self.history_cursor] = current_block | |
305 | self.history_cursor -= 1 |
|
305 | self.history_cursor -= 1 | |
306 | return command |
|
306 | return command | |
307 |
|
307 |
@@ -31,11 +31,6 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 | # The added tab stop to the string. It may, for instance, come from |
|
|||
35 | # copy and pasting something with tabs. |
|
|||
36 | tab_stop = 0 |
|
|||
37 | # FIXME: We still have to deal with this. |
|
|||
38 |
|
||||
39 | #-------------------------------------------------------------------------- |
|
34 | #-------------------------------------------------------------------------- | |
40 | # Public API |
|
35 | # Public API | |
41 | #-------------------------------------------------------------------------- |
|
36 | #-------------------------------------------------------------------------- | |
@@ -81,7 +76,7 b' class LineFrontEndBase(FrontEndBase):' | |||||
81 | return failure |
|
76 | return failure | |
82 |
|
77 | |||
83 |
|
78 | |||
84 | def on_enter(self): |
|
79 | def _on_enter(self): | |
85 | """ Called when the return key is pressed in a line editing |
|
80 | """ Called when the return key is pressed in a line editing | |
86 | buffer. |
|
81 | buffer. | |
87 | """ |
|
82 | """ | |
@@ -93,11 +88,14 b' class LineFrontEndBase(FrontEndBase):' | |||||
93 | if ( not self.multi_line_input |
|
88 | if ( not self.multi_line_input | |
94 | or re.findall(r"\n[\t ]*$", cleaned_buffer)): |
|
89 | or re.findall(r"\n[\t ]*$", cleaned_buffer)): | |
95 | if self.is_complete(cleaned_buffer): |
|
90 | if self.is_complete(cleaned_buffer): | |
96 | self._add_history(None, cleaned_buffer.rstrip()) |
|
91 | self.history.input_cache[-1] = \ | |
|
92 | current_buffer | |||
97 | result = self.shell.execute(cleaned_buffer) |
|
93 | result = self.shell.execute(cleaned_buffer) | |
98 | self.render_result(result) |
|
94 | self.render_result(result) | |
99 | self.new_prompt(self.prompt % (result['number'] + 1)) |
|
95 | self.new_prompt(self.prompt % (result['number'] + 1)) | |
100 | self.multi_line_input = False |
|
96 | self.multi_line_input = False | |
|
97 | # Start a new empty history entry | |||
|
98 | self._add_history(None, '') | |||
101 | else: |
|
99 | else: | |
102 | if self.multi_line_input: |
|
100 | if self.multi_line_input: | |
103 | self.write('\n' + self._get_indent_string(current_buffer)) |
|
101 | self.write('\n' + self._get_indent_string(current_buffer)) |
@@ -113,6 +113,7 b' class ConsoleWidget(editwindow.EditWindow):' | |||||
113 | self.autocomplete_mode = autocomplete_mode |
|
113 | self.autocomplete_mode = autocomplete_mode | |
114 |
|
114 | |||
115 | self.Bind(wx.EVT_KEY_DOWN, self._on_key_down) |
|
115 | self.Bind(wx.EVT_KEY_DOWN, self._on_key_down) | |
|
116 | self.Bind(wx.EVT_KEY_UP, self._on_key_up) | |||
116 |
|
117 | |||
117 |
|
118 | |||
118 | def configure_scintilla(self): |
|
119 | def configure_scintilla(self): | |
@@ -124,11 +125,11 b' class ConsoleWidget(editwindow.EditWindow):' | |||||
124 | self.CmdKeyAssign(ord('='), stc.STC_SCMOD_CTRL|stc.STC_SCMOD_SHIFT, |
|
125 | self.CmdKeyAssign(ord('='), stc.STC_SCMOD_CTRL|stc.STC_SCMOD_SHIFT, | |
125 | stc.STC_CMD_ZOOMIN) |
|
126 | stc.STC_CMD_ZOOMIN) | |
126 |
|
127 | |||
127 | self.CmdKeyAssign(stc.STC_KEY_PRIOR, stc.STC_SCMOD_SHIFT, |
|
128 | #self.CmdKeyAssign(stc.STC_KEY_PRIOR, stc.STC_SCMOD_SHIFT, | |
128 | stc.STC_CMD_PAGEUP) |
|
129 | # stc.STC_CMD_PAGEUP) | |
129 |
|
130 | |||
130 | self.CmdKeyAssign(stc.STC_KEY_NEXT, stc.STC_SCMOD_SHIFT, |
|
131 | #self.CmdKeyAssign(stc.STC_KEY_NEXT, stc.STC_SCMOD_SHIFT, | |
131 | stc.STC_CMD_PAGEDOWN) |
|
132 | # stc.STC_CMD_PAGEDOWN) | |
132 |
|
133 | |||
133 | # Keys: we need to clear some of the keys the that don't play |
|
134 | # Keys: we need to clear some of the keys the that don't play | |
134 | # well with a console. |
|
135 | # well with a console. | |
@@ -259,17 +260,6 b' class ConsoleWidget(editwindow.EditWindow):' | |||||
259 | self.StyleSetSpec(style[0], "bold,fore:%s" % style[1]) |
|
260 | self.StyleSetSpec(style[0], "bold,fore:%s" % style[1]) | |
260 |
|
261 | |||
261 |
|
262 | |||
262 | def removeFromTo(self, from_pos, to_pos): |
|
|||
263 | if from_pos < to_pos: |
|
|||
264 | self.SetSelection(from_pos, to_pos) |
|
|||
265 | self.DeleteBack() |
|
|||
266 |
|
||||
267 |
|
||||
268 | def selectFromTo(self, from_pos, to_pos): |
|
|||
269 | self.SetSelectionStart(from_pos) |
|
|||
270 | self.SetSelectionEnd(to_pos) |
|
|||
271 |
|
||||
272 |
|
||||
273 | def writeCompletion(self, possibilities): |
|
263 | def writeCompletion(self, possibilities): | |
274 | if self.autocomplete_mode == 'IPYTHON': |
|
264 | if self.autocomplete_mode == 'IPYTHON': | |
275 | max_len = len(max(possibilities, key=len)) |
|
265 | max_len = len(max(possibilities, key=len)) | |
@@ -310,6 +300,11 b' class ConsoleWidget(editwindow.EditWindow):' | |||||
310 | maxrange = self.GetScrollRange(wx.VERTICAL) |
|
300 | maxrange = self.GetScrollRange(wx.VERTICAL) | |
311 | self.ScrollLines(maxrange) |
|
301 | self.ScrollLines(maxrange) | |
312 |
|
302 | |||
|
303 | def on_enter(self): | |||
|
304 | """ Called when the return key is hit. | |||
|
305 | """ | |||
|
306 | pass | |||
|
307 | ||||
313 |
|
308 | |||
314 | def _on_key_down(self, event, skip=True): |
|
309 | def _on_key_down(self, event, skip=True): | |
315 | """ Key press callback used for correcting behavior for |
|
310 | """ Key press callback used for correcting behavior for | |
@@ -319,22 +314,35 b' class ConsoleWidget(editwindow.EditWindow):' | |||||
319 | Return True if event as been catched. |
|
314 | Return True if event as been catched. | |
320 | """ |
|
315 | """ | |
321 | catched = False |
|
316 | catched = False | |
|
317 | # Intercept some specific keys. | |||
322 | if event.KeyCode == ord('L') and event.ControlDown() : |
|
318 | if event.KeyCode == ord('L') and event.ControlDown() : | |
323 | skip = False |
|
|||
324 | catched = True |
|
319 | catched = True | |
325 | self.scroll_to_bottom() |
|
320 | self.scroll_to_bottom() | |
|
321 | elif event.KeyCode == wx.WXK_PAGEUP and event.ShiftDown(): | |||
|
322 | catched = True | |||
|
323 | self.ScrollPages(-1) | |||
|
324 | elif event.KeyCode == wx.WXK_PAGEDOWN and event.ShiftDown(): | |||
|
325 | catched = True | |||
|
326 | self.ScrollPages(1) | |||
326 |
|
327 | |||
327 | if self.AutoCompActive(): |
|
328 | if self.AutoCompActive(): | |
328 | event.Skip() |
|
329 | event.Skip() | |
329 | else: |
|
330 | else: | |
330 |
if event.KeyCode |
|
331 | if event.KeyCode in (13, wx.WXK_NUMPAD_ENTER) and \ | |
|
332 | event.Modifiers in (wx.MOD_NONE, wx.MOD_WIN): | |||
|
333 | catched = True | |||
|
334 | self._on_enter() | |||
|
335 | ||||
|
336 | elif event.KeyCode == wx.WXK_HOME: | |||
331 | if event.Modifiers in (wx.MOD_NONE, wx.MOD_WIN): |
|
337 | if event.Modifiers in (wx.MOD_NONE, wx.MOD_WIN): | |
332 | self.GotoPos(self.current_prompt_pos) |
|
338 | self.GotoPos(self.current_prompt_pos) | |
333 | catched = True |
|
339 | catched = True | |
334 |
|
340 | |||
335 | elif event.Modifiers in (wx.MOD_SHIFT, wx.MOD_WIN) : |
|
341 | elif event.Modifiers in (wx.MOD_SHIFT, wx.MOD_WIN) : | |
336 | self.selectFromTo(self.current_prompt_pos, |
|
342 | # FIXME: This behavior is not ideal: if the selection | |
337 | self.GetCurrentPos()) |
|
343 | # is already started, it will jump. | |
|
344 | self.SetSelectionStart(self.current_prompt_pos) | |||
|
345 | self.SetSelectionEnd(self.GetCurrentPos()) | |||
338 | catched = True |
|
346 | catched = True | |
339 |
|
347 | |||
340 | elif event.KeyCode == wx.WXK_UP: |
|
348 | elif event.KeyCode == wx.WXK_UP: | |
@@ -355,16 +363,18 b' class ConsoleWidget(editwindow.EditWindow):' | |||||
355 | if skip and not catched: |
|
363 | if skip and not catched: | |
356 | event.Skip() |
|
364 | event.Skip() | |
357 |
|
365 | |||
358 | if event.KeyCode not in (wx.WXK_PAGEUP, wx.WXK_PAGEDOWN)\ |
|
|||
359 | and event.Modifiers in (wx.MOD_NONE, wx.MOD_WIN, |
|
|||
360 | wx.MOD_SHIFT): |
|
|||
361 | # If cursor is outside the editing region, put it back. |
|
|||
362 | if self.GetCurrentPos() < self.current_prompt_pos: |
|
|||
363 | self.GotoPos(self.current_prompt_pos) |
|
|||
364 |
|
||||
365 | return catched |
|
366 | return catched | |
366 |
|
367 | |||
367 |
|
368 | |||
|
369 | def _on_key_up(self, event, skip=True): | |||
|
370 | """ If cursor is outside the editing region, put it back. | |||
|
371 | """ | |||
|
372 | event.Skip() | |||
|
373 | if self.GetCurrentPos() < self.current_prompt_pos: | |||
|
374 | self.GotoPos(self.current_prompt_pos) | |||
|
375 | ||||
|
376 | ||||
|
377 | ||||
368 |
|
378 | |||
369 | if __name__ == '__main__': |
|
379 | if __name__ == '__main__': | |
370 | # Some simple code to test the console widget. |
|
380 | # Some simple code to test the console widget. |
@@ -63,12 +63,8 b' class IPythonWxController(LineFrontEndBase, ConsoleWidget):' | |||||
63 | widget handle them, and put our logic afterward. |
|
63 | widget handle them, and put our logic afterward. | |
64 | """ |
|
64 | """ | |
65 | current_line_number = self.GetCurrentLine() |
|
65 | current_line_number = self.GetCurrentLine() | |
66 | # Capture enter |
|
|||
67 | if event.KeyCode in (13, wx.WXK_NUMPAD_ENTER) and \ |
|
|||
68 | event.Modifiers in (wx.MOD_NONE, wx.MOD_WIN): |
|
|||
69 | self.on_enter() |
|
|||
70 | # Up history |
|
66 | # Up history | |
71 |
|
|
67 | if event.KeyCode == wx.WXK_UP and ( | |
72 | ( current_line_number == self.current_prompt_line and |
|
68 | ( current_line_number == self.current_prompt_line and | |
73 | event.Modifiers in (wx.MOD_NONE, wx.MOD_WIN) ) |
|
69 | event.Modifiers in (wx.MOD_NONE, wx.MOD_WIN) ) | |
74 | or event.ControlDown() ): |
|
70 | or event.ControlDown() ): | |
@@ -76,6 +72,9 b' class IPythonWxController(LineFrontEndBase, ConsoleWidget):' | |||||
76 | self.get_current_edit_buffer()) |
|
72 | self.get_current_edit_buffer()) | |
77 | if new_buffer is not None: |
|
73 | if new_buffer is not None: | |
78 | self.replace_current_edit_buffer(new_buffer) |
|
74 | self.replace_current_edit_buffer(new_buffer) | |
|
75 | if self.GetCurrentLine() > self.current_prompt_line: | |||
|
76 | # Go to first line, for seemless history up. | |||
|
77 | self.GotoPos(self.current_prompt_pos) | |||
79 | # Down history |
|
78 | # Down history | |
80 | elif event.KeyCode == wx.WXK_DOWN and ( |
|
79 | elif event.KeyCode == wx.WXK_DOWN and ( | |
81 | ( current_line_number == self.LineCount -1 and |
|
80 | ( current_line_number == self.LineCount -1 and | |
@@ -85,7 +84,7 b' class IPythonWxController(LineFrontEndBase, ConsoleWidget):' | |||||
85 | if new_buffer is not None: |
|
84 | if new_buffer is not None: | |
86 | self.replace_current_edit_buffer(new_buffer) |
|
85 | self.replace_current_edit_buffer(new_buffer) | |
87 | else: |
|
86 | else: | |
88 |
ConsoleWidget._on_key_down(self, event, skip= |
|
87 | ConsoleWidget._on_key_down(self, event, skip=skip) | |
89 |
|
88 | |||
90 |
|
89 | |||
91 |
|
90 |
@@ -56,7 +56,7 b' class History(object):' | |||||
56 | """ Returns the history string at index, where index is the |
|
56 | """ Returns the history string at index, where index is the | |
57 | distance from the end (positive). |
|
57 | distance from the end (positive). | |
58 | """ |
|
58 | """ | |
59 | if index>0 and index<len(self.input_cache): |
|
59 | if index>=0 and index<len(self.input_cache): | |
60 | return self.input_cache[index] |
|
60 | return self.input_cache[index] | |
61 |
|
61 | |||
62 |
|
62 |
General Comments 0
You need to be logged in to leave comments.
Login now