Show More
@@ -32,6 +32,8 class LineFrontEndBase(FrontEndBase): | |||
|
32 | 32 | # it when there is an exception. |
|
33 | 33 | prompt_number = 1 |
|
34 | 34 | |
|
35 | # To bootstrap | |
|
36 | last_result = dict(number=0) | |
|
35 | 37 | |
|
36 | 38 | #-------------------------------------------------------------------------- |
|
37 | 39 | # Public API |
@@ -87,11 +89,15 class LineFrontEndBase(FrontEndBase): | |||
|
87 | 89 | |
|
88 | 90 | |
|
89 | 91 | def is_complete(self, string): |
|
90 | if ( len(self.get_current_edit_buffer().split('\n'))>2 | |
|
92 | if string in ('', '\n'): | |
|
93 | return True | |
|
94 | elif ( len(self.get_current_edit_buffer().split('\n'))>2 | |
|
91 | 95 | and not re.findall(r"\n[\t ]*\n[\t ]*$", string)): |
|
92 | 96 | return False |
|
93 | 97 | else: |
|
94 | return FrontEndBase.is_complete(self, string) | |
|
98 | # Add line returns here, to make sure that the statement is | |
|
99 | # complete. | |
|
100 | return FrontEndBase.is_complete(self, string.rstrip() + '\n\n') | |
|
95 | 101 | |
|
96 | 102 | |
|
97 | 103 | def execute(self, python_string, raw_string=None): |
@@ -63,6 +63,9 _STDERR_STYLE = 16 | |||
|
63 | 63 | _TRACE_STYLE = 17 |
|
64 | 64 | |
|
65 | 65 | |
|
66 | # system colors | |
|
67 | SYS_COLOUR_BACKGROUND = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BACKGROUND) | |
|
68 | ||
|
66 | 69 | #------------------------------------------------------------------------------- |
|
67 | 70 | # The console widget class |
|
68 | 71 | #------------------------------------------------------------------------------- |
@@ -99,10 +102,10 class ConsoleWidget(editwindow.EditWindow): | |||
|
99 | 102 | |
|
100 | 103 | def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition, |
|
101 | 104 | size=wx.DefaultSize, style=0, |
|
102 |
autocomplete_mode=' |
|
|
103 |
""" Autocomplete_mode: Can be ' |
|
|
104 |
' |
|
|
105 | 'STC" show it scintilla text control way | |
|
105 | autocomplete_mode='popup'): | |
|
106 | """ Autocomplete_mode: Can be 'popup' or 'text' | |
|
107 | 'text' show autocompletion in the text buffer | |
|
108 | 'popup' show it with a dropdown popup | |
|
106 | 109 | """ |
|
107 | 110 | editwindow.EditWindow.__init__(self, parent, id, pos, size, style) |
|
108 | 111 | self.configure_scintilla() |
@@ -265,7 +268,7 class ConsoleWidget(editwindow.EditWindow): | |||
|
265 | 268 | """ |
|
266 | 269 | self.SetCaretForeground(self.carret_color) |
|
267 | 270 | |
|
268 | self.StyleClearAll() | |
|
271 | #self.StyleClearAll() | |
|
269 | 272 | self.StyleSetSpec(stc.STC_STYLE_BRACELIGHT, |
|
270 | 273 | "fore:#FF0000,back:#0000FF,bold") |
|
271 | 274 | self.StyleSetSpec(stc.STC_STYLE_BRACEBAD, |
@@ -275,32 +278,18 class ConsoleWidget(editwindow.EditWindow): | |||
|
275 | 278 | self.StyleSetSpec(style[0], "bold,fore:%s" % style[1]) |
|
276 | 279 | |
|
277 | 280 | |
|
278 | def write_completion(self, possibilities): | |
|
279 |
if self.autocomplete_mode == ' |
|
|
281 | def write_completion(self, possibilities, mode=None): | |
|
282 | if mode=='text' or self.autocomplete_mode == 'text': | |
|
280 | 283 | max_len = len(max(possibilities, key=len)) |
|
281 | max_symbol = ' '*max_len | |
|
282 |
|
|
|
283 | #now we check how much symbol we can put on a line... | |
|
284 | test_buffer = max_symbol + ' '*4 | |
|
285 | ||
|
286 | allowed_symbols = 80/len(test_buffer) | |
|
287 | if allowed_symbols == 0: | |
|
288 | allowed_symbols = 1 | |
|
289 | ||
|
290 | pos = 1 | |
|
291 | buf = '' | |
|
284 | current_buffer = self.get_current_edit_buffer() | |
|
285 | ||
|
286 | self.write('\n') | |
|
292 | 287 | for symbol in possibilities: |
|
293 | #buf += symbol+'\n'#*spaces) | |
|
294 | if pos < allowed_symbols: | |
|
295 | spaces = max_len - len(symbol) + 4 | |
|
296 | buf += symbol+' '*spaces | |
|
297 | pos += 1 | |
|
298 | else: | |
|
299 | buf += symbol+'\n' | |
|
300 | pos = 1 | |
|
301 | self.write(buf) | |
|
288 | self.write(symbol.ljust(max_len)) | |
|
289 | self.new_prompt(self.prompt % (self.last_result['number'] + 1)) | |
|
290 | self.replace_current_edit_buffer(current_buffer) | |
|
302 | 291 | else: |
|
303 | possibilities.sort() # Python sorts are case sensitive | |
|
292 | #possibilities.sort() # Python sorts are case sensitive | |
|
304 | 293 | self.AutoCompSetIgnoreCase(False) |
|
305 | 294 | self.AutoCompSetAutoHide(False) |
|
306 | 295 | #let compute the length ot text)last word |
@@ -51,10 +51,24 class IPythonWxController(PrefilterFrontEnd, ConsoleWidget): | |||
|
51 | 51 | self.Bind(wx.EVT_KEY_DOWN, self._on_key_down) |
|
52 | 52 | |
|
53 | 53 | |
|
54 | def do_completion(self): | |
|
54 | def do_completion(self, mode=None): | |
|
55 | """ Do code completion. | |
|
56 | mode can be 'text', 'popup' or 'none' to use default. | |
|
57 | """ | |
|
55 | 58 | line = self.get_current_edit_buffer() |
|
56 | 59 | completions = self.complete(line) |
|
57 | self.write_completion(completions) | |
|
60 | self.write_completion(completions, mode=mode) | |
|
61 | ||
|
62 | ||
|
63 | def update_completion(self): | |
|
64 | line = self.get_current_edit_buffer() | |
|
65 | if self.AutoCompActive() and not line[-1] == '.': | |
|
66 | line = line[:-1] | |
|
67 | completions = self.complete(line) | |
|
68 | choose_single = self.AutoCompGetChooseSingle() | |
|
69 | self.AutoCompSetChooseSingle(False) | |
|
70 | self.write_completion(completions, mode='popup') | |
|
71 | self.AutoCompSetChooseSingle(choose_single) | |
|
58 | 72 | |
|
59 | 73 | |
|
60 | 74 | def execute(self, *args, **kwargs): |
@@ -64,7 +78,8 class IPythonWxController(PrefilterFrontEnd, ConsoleWidget): | |||
|
64 | 78 | |
|
65 | 79 | def after_execute(self): |
|
66 | 80 | PrefilterFrontEnd.after_execute(self) |
|
67 |
|
|
|
81 | if hasattr(self, '_cursor'): | |
|
82 | del self._cursor | |
|
68 | 83 | |
|
69 | 84 | #-------------------------------------------------------------------------- |
|
70 | 85 | # Private API |
@@ -78,6 +93,11 class IPythonWxController(PrefilterFrontEnd, ConsoleWidget): | |||
|
78 | 93 | current_line_number = self.GetCurrentLine() |
|
79 | 94 | if self.AutoCompActive(): |
|
80 | 95 | event.Skip() |
|
96 | if event.KeyCode in (wx.WXK_BACK, wx.WXK_DELETE): | |
|
97 | wx.CallAfter(self.do_completion) | |
|
98 | elif not event.KeyCode in (wx.WXK_UP, wx.WXK_DOWN, wx.WXK_LEFT, | |
|
99 | wx.WXK_RIGHT): | |
|
100 | wx.CallAfter(self.update_completion) | |
|
81 | 101 | else: |
|
82 | 102 | # Up history |
|
83 | 103 | if event.KeyCode == wx.WXK_UP and ( |
@@ -102,14 +122,21 class IPythonWxController(PrefilterFrontEnd, ConsoleWidget): | |||
|
102 | 122 | elif event.KeyCode == ord('\t'): |
|
103 | 123 | last_line = self.get_current_edit_buffer().split('\n')[-1] |
|
104 | 124 | if not re.match(r'^\s*$', last_line): |
|
105 | self.do_completion() | |
|
125 | self.do_completion(mode='text') | |
|
106 | 126 | else: |
|
107 | 127 | event.Skip() |
|
108 | 128 | else: |
|
109 | 129 | ConsoleWidget._on_key_down(self, event, skip=skip) |
|
110 | 130 | |
|
111 | 131 | |
|
112 | ||
|
132 | def _on_key_up(self, event, skip=True): | |
|
133 | if event.KeyCode == 59: | |
|
134 | # Intercepting '.' | |
|
135 | event.Skip() | |
|
136 | self.do_completion(mode='popup') | |
|
137 | else: | |
|
138 | ConsoleWidget._on_key_up(self, event, skip=skip) | |
|
139 | ||
|
113 | 140 | |
|
114 | 141 | if __name__ == '__main__': |
|
115 | 142 | class MainWindow(wx.Frame): |
General Comments 0
You need to be logged in to leave comments.
Login now