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