Show More
@@ -59,6 +59,9 b' class LineFrontEndBase(FrontEndBase):' | |||||
59 | # The input buffer being edited |
|
59 | # The input buffer being edited | |
60 | input_buffer = '' |
|
60 | input_buffer = '' | |
61 |
|
61 | |||
|
62 | # Set to true for debug output | |||
|
63 | debug = False | |||
|
64 | ||||
62 | #-------------------------------------------------------------------------- |
|
65 | #-------------------------------------------------------------------------- | |
63 | # FrontEndBase interface |
|
66 | # FrontEndBase interface | |
64 | #-------------------------------------------------------------------------- |
|
67 | #-------------------------------------------------------------------------- | |
@@ -143,17 +146,6 b' class LineFrontEndBase(FrontEndBase):' | |||||
143 | print >>sys.__stderr__, string |
|
146 | print >>sys.__stderr__, string | |
144 |
|
147 | |||
145 |
|
148 | |||
146 | def new_prompt(self, prompt): |
|
|||
147 | """ Prints a prompt and starts a new editing buffer. |
|
|||
148 |
|
||||
149 | Subclasses should use this method to make sure that the |
|
|||
150 | terminal is put in a state favorable for a new line |
|
|||
151 | input. |
|
|||
152 | """ |
|
|||
153 | self.input_buffer = '' |
|
|||
154 | self.write(prompt) |
|
|||
155 |
|
||||
156 |
|
||||
157 | def execute(self, python_string, raw_string=None): |
|
149 | def execute(self, python_string, raw_string=None): | |
158 | """ Stores the raw_string in the history, and sends the |
|
150 | """ Stores the raw_string in the history, and sends the | |
159 | python string to the interpreter. |
|
151 | python string to the interpreter. | |
@@ -185,6 +177,7 b' class LineFrontEndBase(FrontEndBase):' | |||||
185 | string = '\n'.join(l.rstrip() for l in string.split('\n')) |
|
177 | string = '\n'.join(l.rstrip() for l in string.split('\n')) | |
186 | return string |
|
178 | return string | |
187 |
|
179 | |||
|
180 | ||||
188 | def after_execute(self): |
|
181 | def after_execute(self): | |
189 | """ All the operations required after an execution to put the |
|
182 | """ All the operations required after an execution to put the | |
190 | terminal back in a shape where it is usable. |
|
183 | terminal back in a shape where it is usable. | |
@@ -197,6 +190,59 b' class LineFrontEndBase(FrontEndBase):' | |||||
197 | self.history_cursor = len(self.history.input_cache) - 1 |
|
190 | self.history_cursor = len(self.history.input_cache) - 1 | |
198 |
|
191 | |||
199 |
|
192 | |||
|
193 | def complete_current_input(self): | |||
|
194 | """ Do code completion on current line. | |||
|
195 | """ | |||
|
196 | if self.debug: | |||
|
197 | print >>sys.__stdout__, "complete_current_input", | |||
|
198 | line = self.input_buffer | |||
|
199 | new_line, completions = self.complete(line) | |||
|
200 | if len(completions)>1: | |||
|
201 | self.write_completion(completions) | |||
|
202 | self.input_buffer = new_line | |||
|
203 | if self.debug: | |||
|
204 | print >>sys.__stdout__, completions | |||
|
205 | ||||
|
206 | ||||
|
207 | def write_completion(self, possibilities): | |||
|
208 | """ Write the list of possible completions. | |||
|
209 | """ | |||
|
210 | current_buffer = self.input_buffer | |||
|
211 | ||||
|
212 | self.write('\n') | |||
|
213 | max_len = len(max(possibilities, key=len)) + 1 | |||
|
214 | ||||
|
215 | #now we check how much symbol we can put on a line... | |||
|
216 | chars_per_line =self.get_line_width() | |||
|
217 | symbols_per_line = max(1, chars_per_line/max_len) | |||
|
218 | ||||
|
219 | pos = 1 | |||
|
220 | buf = [] | |||
|
221 | for symbol in possibilities: | |||
|
222 | if pos < symbols_per_line: | |||
|
223 | buf.append(symbol.ljust(max_len)) | |||
|
224 | pos += 1 | |||
|
225 | else: | |||
|
226 | buf.append(symbol.rstrip() + '\n') | |||
|
227 | pos = 1 | |||
|
228 | self.write(''.join(buf)) | |||
|
229 | self.new_prompt(self.input_prompt_template.substitute( | |||
|
230 | number=self.last_result['number'] + 1)) | |||
|
231 | self.input_buffer = current_buffer | |||
|
232 | ||||
|
233 | ||||
|
234 | ||||
|
235 | def new_prompt(self, prompt): | |||
|
236 | """ Prints a prompt and starts a new editing buffer. | |||
|
237 | ||||
|
238 | Subclasses should use this method to make sure that the | |||
|
239 | terminal is put in a state favorable for a new line | |||
|
240 | input. | |||
|
241 | """ | |||
|
242 | self.input_buffer = '' | |||
|
243 | self.write(prompt) | |||
|
244 | ||||
|
245 | ||||
200 | #-------------------------------------------------------------------------- |
|
246 | #-------------------------------------------------------------------------- | |
201 | # Private API |
|
247 | # Private API | |
202 | #-------------------------------------------------------------------------- |
|
248 | #-------------------------------------------------------------------------- |
@@ -201,33 +201,11 b' class ConsoleWidget(editwindow.EditWindow):' | |||||
201 | self.AutoCompShow(offset, " ".join(possibilities)) |
|
201 | self.AutoCompShow(offset, " ".join(possibilities)) | |
202 |
|
202 | |||
203 |
|
203 | |||
204 | def write_completion(self, possibilities): |
|
204 | def get_line_width(self): | |
205 | # FIXME: This is non Wx specific and needs to be moved into |
|
205 | """ Return the width of the line in characters. | |
206 | # the base class. |
|
206 | """ | |
207 | current_buffer = self.input_buffer |
|
207 | return self.GetSize()[0]/self.GetCharWidth() | |
208 |
|
208 | |||
209 | self.write('\n') |
|
|||
210 | max_len = len(max(possibilities, key=len)) + 1 |
|
|||
211 |
|
||||
212 | #now we check how much symbol we can put on a line... |
|
|||
213 | chars_per_line = self.GetSize()[0]/self.GetCharWidth() |
|
|||
214 | symbols_per_line = max(1, chars_per_line/max_len) |
|
|||
215 |
|
||||
216 | pos = 1 |
|
|||
217 | buf = [] |
|
|||
218 | for symbol in possibilities: |
|
|||
219 | if pos < symbols_per_line: |
|
|||
220 | buf.append(symbol.ljust(max_len)) |
|
|||
221 | pos += 1 |
|
|||
222 | else: |
|
|||
223 | buf.append(symbol.rstrip() + '\n') |
|
|||
224 | pos = 1 |
|
|||
225 | self.write(''.join(buf)) |
|
|||
226 | # FIXME: I have some mixing of interfaces between console_widget |
|
|||
227 | # and wx_frontend, here. |
|
|||
228 | self.new_prompt(self.input_prompt_template.substitute( |
|
|||
229 | number=self.last_result['number'] + 1)) |
|
|||
230 | self.input_buffer = current_buffer |
|
|||
231 |
|
209 | |||
232 | #-------------------------------------------------------------------------- |
|
210 | #-------------------------------------------------------------------------- | |
233 | # Private API |
|
211 | # Private API |
@@ -183,20 +183,6 b' class WxController(ConsoleWidget, PrefilterFrontEnd):' | |||||
183 | self._buffer_flush(event=None) |
|
183 | self._buffer_flush(event=None) | |
184 |
|
184 | |||
185 |
|
185 | |||
186 | def do_completion(self): |
|
|||
187 | """ Do code completion on current line. |
|
|||
188 | """ |
|
|||
189 | if self.debug: |
|
|||
190 | print >>sys.__stdout__, "do_completion", |
|
|||
191 | line = self.input_buffer |
|
|||
192 | new_line, completions = self.complete(line) |
|
|||
193 | if len(completions)>1: |
|
|||
194 | self.write_completion(completions) |
|
|||
195 | self.input_buffer = new_line |
|
|||
196 | if self.debug: |
|
|||
197 | print >>sys.__stdout__, completions |
|
|||
198 |
|
||||
199 |
|
||||
200 | def do_calltip(self): |
|
186 | def do_calltip(self): | |
201 | """ Analyse current and displays useful calltip for it. |
|
187 | """ Analyse current and displays useful calltip for it. | |
202 | """ |
|
188 | """ | |
@@ -394,7 +380,7 b' class WxController(ConsoleWidget, PrefilterFrontEnd):' | |||||
394 | elif event.KeyCode == ord('\t'): |
|
380 | elif event.KeyCode == ord('\t'): | |
395 | last_line = self.input_buffer.split('\n')[-1] |
|
381 | last_line = self.input_buffer.split('\n')[-1] | |
396 | if not re.match(r'^\s*$', last_line): |
|
382 | if not re.match(r'^\s*$', last_line): | |
397 |
self. |
|
383 | self.complete_current_input() | |
398 | else: |
|
384 | else: | |
399 | event.Skip() |
|
385 | event.Skip() | |
400 | else: |
|
386 | else: |
General Comments 0
You need to be logged in to leave comments.
Login now