Show More
@@ -76,6 +76,11 b' class LineFrontEndBase(FrontEndBase):' | |||
|
76 | 76 | |
|
77 | 77 | if banner is not None: |
|
78 | 78 | self.banner = banner |
|
79 | ||
|
80 | def start(self): | |
|
81 | """ Put the frontend in a state where it is ready for user | |
|
82 | interaction. | |
|
83 | """ | |
|
79 | 84 | if self.banner is not None: |
|
80 | 85 | self.write(self.banner, refresh=False) |
|
81 | 86 | |
@@ -210,9 +215,10 b' class LineFrontEndBase(FrontEndBase):' | |||
|
210 | 215 | line = self.input_buffer |
|
211 | 216 | new_line, completions = self.complete(line) |
|
212 | 217 | if len(completions)>1: |
|
213 | self.write_completion(completions) | |
|
214 | self.input_buffer = new_line | |
|
218 | self.write_completion(completions, new_line=new_line) | |
|
215 | 219 | if self.debug: |
|
220 | print >>sys.__stdout__, 'line', line | |
|
221 | print >>sys.__stdout__, 'new_line', new_line | |
|
216 | 222 | print >>sys.__stdout__, completions |
|
217 | 223 | |
|
218 | 224 | |
@@ -222,10 +228,15 b' class LineFrontEndBase(FrontEndBase):' | |||
|
222 | 228 | return 80 |
|
223 | 229 | |
|
224 | 230 | |
|
225 | def write_completion(self, possibilities): | |
|
231 | def write_completion(self, possibilities, new_line=None): | |
|
226 | 232 | """ Write the list of possible completions. |
|
233 | ||
|
234 | new_line is the completed input line that should be displayed | |
|
235 | after the completion are writen. If None, the input_buffer | |
|
236 | before the completion is used. | |
|
227 | 237 | """ |
|
228 | current_buffer = self.input_buffer | |
|
238 | if new_line is None: | |
|
239 | new_line = self.input_buffer | |
|
229 | 240 | |
|
230 | 241 | self.write('\n') |
|
231 | 242 | max_len = len(max(possibilities, key=len)) + 1 |
@@ -246,7 +257,7 b' class LineFrontEndBase(FrontEndBase):' | |||
|
246 | 257 | self.write(''.join(buf)) |
|
247 | 258 | self.new_prompt(self.input_prompt_template.substitute( |
|
248 | 259 | number=self.last_result['number'] + 1)) |
|
249 |
self.input_buffer = |
|
|
260 | self.input_buffer = new_line | |
|
250 | 261 | |
|
251 | 262 | |
|
252 | 263 | def new_prompt(self, prompt): |
@@ -24,6 +24,7 b' __docformat__ = "restructuredtext en"' | |||
|
24 | 24 | import sys |
|
25 | 25 | |
|
26 | 26 | from linefrontendbase import LineFrontEndBase, common_prefix |
|
27 | from frontendbase import FrontEndBase | |
|
27 | 28 | |
|
28 | 29 | from IPython.ipmaker import make_IPython |
|
29 | 30 | from IPython.ipapi import IPApi |
@@ -34,6 +35,7 b' from IPython.kernel.core.sync_traceback_trap import SyncTracebackTrap' | |||
|
34 | 35 | from IPython.genutils import Term |
|
35 | 36 | import pydoc |
|
36 | 37 | import os |
|
38 | import sys | |
|
37 | 39 | |
|
38 | 40 | |
|
39 | 41 | def mk_system_call(system_call_function, command): |
@@ -58,6 +60,8 b' class PrefilterFrontEnd(LineFrontEndBase):' | |||
|
58 | 60 | completion... |
|
59 | 61 | """ |
|
60 | 62 | |
|
63 | debug = False | |
|
64 | ||
|
61 | 65 | def __init__(self, ipython0=None, *args, **kwargs): |
|
62 | 66 | """ Parameters: |
|
63 | 67 | ----------- |
@@ -65,12 +69,24 b' class PrefilterFrontEnd(LineFrontEndBase):' | |||
|
65 | 69 | ipython0: an optional ipython0 instance to use for command |
|
66 | 70 | prefiltering and completion. |
|
67 | 71 | """ |
|
72 | LineFrontEndBase.__init__(self, *args, **kwargs) | |
|
73 | self.shell.output_trap = RedirectorOutputTrap( | |
|
74 | out_callback=self.write, | |
|
75 | err_callback=self.write, | |
|
76 | ) | |
|
77 | self.shell.traceback_trap = SyncTracebackTrap( | |
|
78 | formatters=self.shell.traceback_trap.formatters, | |
|
79 | ) | |
|
80 | ||
|
81 | # Start the ipython0 instance: | |
|
68 | 82 | self.save_output_hooks() |
|
69 | 83 | if ipython0 is None: |
|
70 | 84 | # Instanciate an IPython0 interpreter to be able to use the |
|
71 | 85 | # prefiltering. |
|
72 | 86 | # XXX: argv=[] is a bit bold. |
|
73 |
ipython0 = make_IPython(argv=[] |
|
|
87 | ipython0 = make_IPython(argv=[], | |
|
88 | user_ns=self.shell.user_ns, | |
|
89 | user_global_ns=self.shell.user_global_ns) | |
|
74 | 90 | self.ipython0 = ipython0 |
|
75 | 91 | # Set the pager: |
|
76 | 92 | self.ipython0.set_hook('show_in_pager', |
@@ -86,24 +102,24 b' class PrefilterFrontEnd(LineFrontEndBase):' | |||
|
86 | 102 | 'ls -CF') |
|
87 | 103 | # And now clean up the mess created by ipython0 |
|
88 | 104 | self.release_output() |
|
105 | ||
|
106 | ||
|
89 | 107 | if not 'banner' in kwargs and self.banner is None: |
|
90 |
|
|
|
108 | self.banner = self.ipython0.BANNER + """ | |
|
91 | 109 | This is the wx frontend, by Gael Varoquaux. This is EXPERIMENTAL code.""" |
|
92 | 110 | |
|
93 | LineFrontEndBase.__init__(self, *args, **kwargs) | |
|
94 | 111 | # XXX: Hack: mix the two namespaces |
|
95 | self.shell.user_ns.update(self.ipython0.user_ns) | |
|
96 | self.ipython0.user_ns = self.shell.user_ns | |
|
97 | self.shell.user_global_ns.update(self.ipython0.user_global_ns) | |
|
98 | self.ipython0.user_global_ns = self.shell.user_global_ns | |
|
112 | # self.shell.user_ns.update(self.ipython0.user_ns) | |
|
113 | # self.ipython0.user_ns = self.shell.user_ns | |
|
114 | # self.shell.user_global_ns.update(self.ipython0.user_global_ns) | |
|
115 | # self.ipython0.user_global_ns = self.shell.user_global_ns | |
|
99 | 116 | |
|
100 | self.shell.output_trap = RedirectorOutputTrap( | |
|
101 | out_callback=self.write, | |
|
102 | err_callback=self.write, | |
|
103 | ) | |
|
104 | self.shell.traceback_trap = SyncTracebackTrap( | |
|
105 | formatters=self.shell.traceback_trap.formatters, | |
|
106 | ) | |
|
117 | # self.ipython0.user_ns.update(self.shell.user_ns) | |
|
118 | # self.shell.user_ns = self.ipython0.user_ns | |
|
119 | # self.ipython0.user_global_ns.update(self.shell.user_global_ns) | |
|
120 | # self.shell.user_global_ns = self.ipython0.user_global_ns | |
|
121 | ||
|
122 | self.start() | |
|
107 | 123 | |
|
108 | 124 | #-------------------------------------------------------------------------- |
|
109 | 125 | # FrontEndBase interface |
@@ -164,6 +180,8 b' This is the wx frontend, by Gael Varoquaux. This is EXPERIMENTAL code."""' | |||
|
164 | 180 | |
|
165 | 181 | |
|
166 | 182 | def complete(self, line): |
|
183 | # FIXME: This should be factored out in the linefrontendbase | |
|
184 | # method. | |
|
167 | 185 | word = line.split('\n')[-1].split(' ')[-1] |
|
168 | 186 | completions = self.ipython0.complete(word) |
|
169 | 187 | # FIXME: The proper sort should be done in the complete method. |
@@ -128,6 +128,7 b' class WxController(ConsoleWidget, PrefilterFrontEnd):' | |||
|
128 | 128 | # while it is being swapped |
|
129 | 129 | _out_buffer_lock = Lock() |
|
130 | 130 | |
|
131 | # The different line markers used to higlight the prompts. | |
|
131 | 132 | _markers = dict() |
|
132 | 133 | |
|
133 | 134 | #-------------------------------------------------------------------------- |
@@ -238,9 +239,9 b' class WxController(ConsoleWidget, PrefilterFrontEnd):' | |||
|
238 | 239 | true, open the menu. |
|
239 | 240 | """ |
|
240 | 241 | if self.debug: |
|
241 |
print >>sys.__stdout__, "_popup_completion" |
|
|
242 | print >>sys.__stdout__, "_popup_completion" | |
|
242 | 243 | line = self.input_buffer |
|
243 | if (self.AutoCompActive() and not line[-1] == '.') \ | |
|
244 | if (self.AutoCompActive() and line and not line[-1] == '.') \ | |
|
244 | 245 | or create==True: |
|
245 | 246 | suggestion, completions = self.complete(line) |
|
246 | 247 | offset=0 |
@@ -427,7 +428,7 b' class WxController(ConsoleWidget, PrefilterFrontEnd):' | |||
|
427 | 428 | if event.KeyCode in (59, ord('.')): |
|
428 | 429 | # Intercepting '.' |
|
429 | 430 | event.Skip() |
|
430 |
self._popup_completion |
|
|
431 | wx.CallAfter(self._popup_completion, create=True) | |
|
431 | 432 | else: |
|
432 | 433 | ConsoleWidget._on_key_up(self, event, skip=skip) |
|
433 | 434 |
General Comments 0
You need to be logged in to leave comments.
Login now