##// END OF EJS Templates
Correct small history bug. Add busy cursor.
Gael Varoquaux -
Show More
@@ -87,8 +87,8 b' class LineFrontEndBase(FrontEndBase):'
87
87
88
88
89 def is_complete(self, string):
89 def is_complete(self, string):
90 if ( len(self.get_current_edit_buffer().split('\n'))>1
90 if ( len(self.get_current_edit_buffer().split('\n'))>2
91 and not re.findall(r"\n[\t ]*$", string)):
91 and not re.findall(r"\n[\t ]*\n[\t ]*$", string)):
92 return False
92 return False
93 else:
93 else:
94 return FrontEndBase.is_complete(self, string)
94 return FrontEndBase.is_complete(self, string)
@@ -103,7 +103,7 b' class LineFrontEndBase(FrontEndBase):'
103 # Create a false result, in case there is an exception
103 # Create a false result, in case there is an exception
104 self.last_result = dict(number=self.prompt_number)
104 self.last_result = dict(number=self.prompt_number)
105 try:
105 try:
106 self.history.input_cache[-1] = raw_string
106 self.history.input_cache[-1] = raw_string.rstrip()
107 result = self.shell.execute(python_string)
107 result = self.shell.execute(python_string)
108 self.last_result = result
108 self.last_result = result
109 self.render_result(result)
109 self.render_result(result)
@@ -121,8 +121,7 b' class LineFrontEndBase(FrontEndBase):'
121 self.new_prompt(self.prompt % (self.last_result['number'] + 1))
121 self.new_prompt(self.prompt % (self.last_result['number'] + 1))
122 # Start a new empty history entry
122 # Start a new empty history entry
123 self._add_history(None, '')
123 self._add_history(None, '')
124 # The result contains useful information that can be used
124 self.history_cursor = len(self.history.input_cache) - 1
125 # elsewhere.
126
125
127
126
128 def _on_enter(self):
127 def _on_enter(self):
@@ -131,13 +130,12 b' class LineFrontEndBase(FrontEndBase):'
131 """
130 """
132 current_buffer = self.get_current_edit_buffer()
131 current_buffer = self.get_current_edit_buffer()
133 cleaned_buffer = self.prefilter_input(current_buffer)
132 cleaned_buffer = self.prefilter_input(current_buffer)
134 if self.is_complete(cleaned_buffer + '\n'):
133 if self.is_complete(cleaned_buffer):
135 # The '\n' is important in case prefiltering empties the
136 # line, to get a new prompt.
137 self.execute(cleaned_buffer, raw_string=current_buffer)
134 self.execute(cleaned_buffer, raw_string=current_buffer)
138 else:
135 else:
139 if len(current_buffer.split('\n'))>1:
136 if len(current_buffer.split('\n'))>2:
140 self.write(self._get_indent_string(current_buffer))
137 # We need to clean the trailing '\n'
138 self.write(self._get_indent_string(current_buffer[:-1]))
141 else:
139 else:
142 self.write('\t')
140 self.write('\t')
143
141
@@ -99,7 +99,7 b' class ConsoleWidget(editwindow.EditWindow):'
99
99
100 def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition,
100 def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition,
101 size=wx.DefaultSize, style=0,
101 size=wx.DefaultSize, style=0,
102 autocomplete_mode='IPYTHON'):
102 autocomplete_mode='STC'):
103 """ Autocomplete_mode: Can be 'IPYTHON' or 'STC'
103 """ Autocomplete_mode: Can be 'IPYTHON' or 'STC'
104 'IPYTHON' show autocompletion the ipython way
104 'IPYTHON' show autocompletion the ipython way
105 'STC" show it scintilla text control way
105 'STC" show it scintilla text control way
@@ -152,6 +152,10 b' class ConsoleWidget(editwindow.EditWindow):'
152 self.SetTabWidth(4)
152 self.SetTabWidth(4)
153
153
154 self.EnsureCaretVisible()
154 self.EnsureCaretVisible()
155 # Tell autocompletion to choose automaticaly out of a single
156 # choice list
157 self.AutoCompSetChooseSingle(True)
158 self.AutoCompSetMaxHeight(10)
155
159
156 self.SetMargins(3, 3) #text is moved away from border with 3px
160 self.SetMargins(3, 3) #text is moved away from border with 3px
157 # Suppressing Scintilla margins
161 # Suppressing Scintilla margins
@@ -271,7 +275,7 b' class ConsoleWidget(editwindow.EditWindow):'
271 self.StyleSetSpec(style[0], "bold,fore:%s" % style[1])
275 self.StyleSetSpec(style[0], "bold,fore:%s" % style[1])
272
276
273
277
274 def writeCompletion(self, possibilities):
278 def write_completion(self, possibilities):
275 if self.autocomplete_mode == 'IPYTHON':
279 if self.autocomplete_mode == 'IPYTHON':
276 max_len = len(max(possibilities, key=len))
280 max_len = len(max(possibilities, key=len))
277 max_symbol = ' '*max_len
281 max_symbol = ' '*max_len
@@ -304,6 +308,7 b' class ConsoleWidget(editwindow.EditWindow):'
304 last_word = self.get_current_edit_buffer()
308 last_word = self.get_current_edit_buffer()
305 for breaker in splitter:
309 for breaker in splitter:
306 last_word = last_word.split(breaker)[-1]
310 last_word = last_word.split(breaker)[-1]
311 self.AutoCompSetMaxHeight(len(possibilities))
307 self.AutoCompShow(len(last_word), " ".join(possibilities))
312 self.AutoCompShow(len(last_word), " ".join(possibilities))
308
313
309
314
@@ -329,7 +334,7 b' class ConsoleWidget(editwindow.EditWindow):'
329 # Intercept some specific keys.
334 # Intercept some specific keys.
330 if event.KeyCode == ord('L') and event.ControlDown() :
335 if event.KeyCode == ord('L') and event.ControlDown() :
331 self.scroll_to_bottom()
336 self.scroll_to_bottom()
332 if event.KeyCode == ord('K') and event.ControlDown() :
337 elif event.KeyCode == ord('K') and event.ControlDown() :
333 self.replace_current_edit_buffer('')
338 self.replace_current_edit_buffer('')
334 elif event.KeyCode == wx.WXK_PAGEUP and event.ShiftDown():
339 elif event.KeyCode == wx.WXK_PAGEUP and event.ShiftDown():
335 self.ScrollPages(-1)
340 self.ScrollPages(-1)
@@ -22,6 +22,7 b' __docformat__ = "restructuredtext en"'
22
22
23
23
24 import wx
24 import wx
25 import re
25 from console_widget import ConsoleWidget
26 from console_widget import ConsoleWidget
26
27
27 from IPython.frontend.prefilterfrontend import PrefilterFrontEnd
28 from IPython.frontend.prefilterfrontend import PrefilterFrontEnd
@@ -49,6 +50,22 b' class IPythonWxController(PrefilterFrontEnd, ConsoleWidget):'
49 # Capture Character keys
50 # Capture Character keys
50 self.Bind(wx.EVT_KEY_DOWN, self._on_key_down)
51 self.Bind(wx.EVT_KEY_DOWN, self._on_key_down)
51
52
53
54 def do_completion(self):
55 line = self.get_current_edit_buffer()
56 completions = self.complete(line)
57 self.write_completion(completions)
58
59
60 def execute(self, *args, **kwargs):
61 self._cursor = wx.BusyCursor()
62 PrefilterFrontEnd.execute(self, *args, **kwargs)
63
64
65 def after_execute(self):
66 PrefilterFrontEnd.after_execute(self)
67 del self._cursor
68
52 #--------------------------------------------------------------------------
69 #--------------------------------------------------------------------------
53 # Private API
70 # Private API
54 #--------------------------------------------------------------------------
71 #--------------------------------------------------------------------------
@@ -59,6 +76,9 b' class IPythonWxController(PrefilterFrontEnd, ConsoleWidget):'
59 widget handle them, and put our logic afterward.
76 widget handle them, and put our logic afterward.
60 """
77 """
61 current_line_number = self.GetCurrentLine()
78 current_line_number = self.GetCurrentLine()
79 if self.AutoCompActive():
80 event.Skip()
81 else:
62 # Up history
82 # Up history
63 if event.KeyCode == wx.WXK_UP and (
83 if event.KeyCode == wx.WXK_UP and (
64 ( current_line_number == self.current_prompt_line and
84 ( current_line_number == self.current_prompt_line and
@@ -79,6 +99,12 b' class IPythonWxController(PrefilterFrontEnd, ConsoleWidget):'
79 new_buffer = self.get_history_next()
99 new_buffer = self.get_history_next()
80 if new_buffer is not None:
100 if new_buffer is not None:
81 self.replace_current_edit_buffer(new_buffer)
101 self.replace_current_edit_buffer(new_buffer)
102 elif event.KeyCode == ord('\t'):
103 last_line = self.get_current_edit_buffer().split('\n')[-1]
104 if not re.match(r'^\s*$', last_line):
105 self.do_completion()
106 else:
107 event.Skip()
82 else:
108 else:
83 ConsoleWidget._on_key_down(self, event, skip=skip)
109 ConsoleWidget._on_key_down(self, event, skip=skip)
84
110
General Comments 0
You need to be logged in to leave comments. Login now