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