##// END OF EJS Templates
Make the wx frontend well-behaved under windows.
gvaroquaux -
Show More
@@ -19,11 +19,9 b' import re'
19
19
20 import IPython
20 import IPython
21
21
22
23 from frontendbase import FrontEndBase
22 from frontendbase import FrontEndBase
24 from IPython.kernel.core.interpreter import Interpreter
23 from IPython.kernel.core.interpreter import Interpreter
25
24
26
27 def common_prefix(strings):
25 def common_prefix(strings):
28 ref = strings[0]
26 ref = strings[0]
29 prefix = ''
27 prefix = ''
@@ -156,8 +154,9 b' class LineFrontEndBase(FrontEndBase):'
156 if self.is_complete(cleaned_buffer):
154 if self.is_complete(cleaned_buffer):
157 self.execute(cleaned_buffer, raw_string=current_buffer)
155 self.execute(cleaned_buffer, raw_string=current_buffer)
158 else:
156 else:
159 self.write(self._get_indent_string(current_buffer[:-1]))
157 self.write(self._get_indent_string(
160 if current_buffer.rstrip().endswith(':'):
158 current_buffer[:-1]))
159 if current_buffer[:-1].split('\n')[-1].rstrip().endswith(':'):
161 self.write('\t')
160 self.write('\t')
162
161
163
162
@@ -23,16 +23,17 b' import wx'
23 import wx.stc as stc
23 import wx.stc as stc
24
24
25 from wx.py import editwindow
25 from wx.py import editwindow
26 import sys
27 LINESEP = '\n'
28 if sys.platform == 'win32':
29 LINESEP = '\n\r'
26
30
27 import re
31 import re
28
32
29 # FIXME: Need to provide an API for non user-generated display on the
33 # FIXME: Need to provide an API for non user-generated display on the
30 # screen: this should not be editable by the user.
34 # screen: this should not be editable by the user.
31
35
32 if wx.Platform == '__WXMSW__':
36 _DEFAULT_SIZE = 10
33 _DEFAULT_SIZE = 80
34 else:
35 _DEFAULT_SIZE = 10
36
37
37 _DEFAULT_STYLE = {
38 _DEFAULT_STYLE = {
38 'stdout' : 'fore:#0000FF',
39 'stdout' : 'fore:#0000FF',
@@ -94,7 +95,6 b' class ConsoleWidget(editwindow.EditWindow):'
94 # The color of the carret (call _apply_style() after setting)
95 # The color of the carret (call _apply_style() after setting)
95 carret_color = 'BLACK'
96 carret_color = 'BLACK'
96
97
97
98 #--------------------------------------------------------------------------
98 #--------------------------------------------------------------------------
99 # Public API
99 # Public API
100 #--------------------------------------------------------------------------
100 #--------------------------------------------------------------------------
@@ -114,6 +114,8 b' class ConsoleWidget(editwindow.EditWindow):'
114
114
115
115
116 def configure_scintilla(self):
116 def configure_scintilla(self):
117 self.SetEOLMode(stc.STC_EOL_LF)
118
117 # Ctrl"+" or Ctrl "-" can be used to zoomin/zoomout the text inside
119 # Ctrl"+" or Ctrl "-" can be used to zoomin/zoomout the text inside
118 # the widget
120 # the widget
119 self.CmdKeyAssign(ord('+'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMIN)
121 self.CmdKeyAssign(ord('+'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMIN)
@@ -206,6 +208,7 b' class ConsoleWidget(editwindow.EditWindow):'
206 text = self.title_pat.sub('', text)
208 text = self.title_pat.sub('', text)
207 segments = self.color_pat.split(text)
209 segments = self.color_pat.split(text)
208 segment = segments.pop(0)
210 segment = segments.pop(0)
211 self.GotoPos(self.GetLength())
209 self.StartStyling(self.GetLength(), 0xFF)
212 self.StartStyling(self.GetLength(), 0xFF)
210 self.AppendText(segment)
213 self.AppendText(segment)
211
214
@@ -223,7 +226,7 b' class ConsoleWidget(editwindow.EditWindow):'
223
226
224 self.GotoPos(self.GetLength())
227 self.GotoPos(self.GetLength())
225 wx.Yield()
228 wx.Yield()
226
229
227
230
228 def new_prompt(self, prompt):
231 def new_prompt(self, prompt):
229 """ Prints a prompt at start of line, and move the start of the
232 """ Prints a prompt at start of line, and move the start of the
@@ -250,8 +253,10 b' class ConsoleWidget(editwindow.EditWindow):'
250 def get_current_edit_buffer(self):
253 def get_current_edit_buffer(self):
251 """ Returns the text in current edit buffer.
254 """ Returns the text in current edit buffer.
252 """
255 """
253 return self.GetTextRange(self.current_prompt_pos,
256 current_edit_buffer = self.GetTextRange(self.current_prompt_pos,
254 self.GetLength())
257 self.GetLength())
258 current_edit_buffer = current_edit_buffer.replace(LINESEP, '\n')
259 return current_edit_buffer
255
260
256
261
257 #--------------------------------------------------------------------------
262 #--------------------------------------------------------------------------
@@ -293,7 +298,7 b' class ConsoleWidget(editwindow.EditWindow):'
293 buf.append(symbol.ljust(max_len))
298 buf.append(symbol.ljust(max_len))
294 pos += 1
299 pos += 1
295 else:
300 else:
296 buf.append(symbol.rstrip() +'\n')
301 buf.append(symbol.rstrip() + '\n')
297 pos = 1
302 pos = 1
298 self.write(''.join(buf))
303 self.write(''.join(buf))
299 self.new_prompt(self.prompt % (self.last_result['number'] + 1))
304 self.new_prompt(self.prompt % (self.last_result['number'] + 1))
@@ -316,12 +321,6 b' class ConsoleWidget(editwindow.EditWindow):'
316 self.ScrollLines(maxrange)
321 self.ScrollLines(maxrange)
317
322
318
323
319 def _on_enter(self):
320 """ Called when the return key is hit.
321 """
322 pass
323
324
325 def _on_key_down(self, event, skip=True):
324 def _on_key_down(self, event, skip=True):
326 """ Key press callback used for correcting behavior for
325 """ Key press callback used for correcting behavior for
327 console-like interfaces: the cursor is constraint to be after
326 console-like interfaces: the cursor is constraint to be after
@@ -354,6 +353,12 b' class ConsoleWidget(editwindow.EditWindow):'
354 catched = True
353 catched = True
355 self.CallTipCancel()
354 self.CallTipCancel()
356 self.write('\n')
355 self.write('\n')
356 # Under windows scintilla seems to be doing funny stuff to the
357 # line returns here, but get_current_edit_buffer filters this
358 # out.
359 if sys.platform == 'win32':
360 self.replace_current_edit_buffer(
361 self.get_current_edit_buffer())
357 self._on_enter()
362 self._on_enter()
358
363
359 elif event.KeyCode == wx.WXK_HOME:
364 elif event.KeyCode == wx.WXK_HOME:
@@ -384,7 +389,11 b' class ConsoleWidget(editwindow.EditWindow):'
384 catched = True
389 catched = True
385
390
386 if skip and not catched:
391 if skip and not catched:
387 event.Skip()
392 # Put the cursor back in the edit region
393 if self.GetCurrentPos() < self.current_prompt_pos:
394 self.GotoPos(self.current_prompt_pos)
395 else:
396 event.Skip()
388
397
389 return catched
398 return catched
390
399
@@ -44,6 +44,8 b' class WxController(PrefilterFrontEnd, ConsoleWidget):'
44
44
45 output_prompt = \
45 output_prompt = \
46 '\x01\x1b[0;31m\x02Out[\x01\x1b[1;31m\x02%i\x01\x1b[0;31m\x02]: \x01\x1b[0m\x02'
46 '\x01\x1b[0;31m\x02Out[\x01\x1b[1;31m\x02%i\x01\x1b[0;31m\x02]: \x01\x1b[0m\x02'
47
48 debug = True
47
49
48 #--------------------------------------------------------------------------
50 #--------------------------------------------------------------------------
49 # Public API
51 # Public API
@@ -68,7 +70,6 b' class WxController(PrefilterFrontEnd, ConsoleWidget):'
68 background=_ERROR_BG)
70 background=_ERROR_BG)
69
71
70
72
71
72 def do_completion(self):
73 def do_completion(self):
73 """ Do code completion.
74 """ Do code completion.
74 """
75 """
@@ -240,6 +241,11 b' class WxController(PrefilterFrontEnd, ConsoleWidget):'
240 else:
241 else:
241 ConsoleWidget._on_key_up(self, event, skip=skip)
242 ConsoleWidget._on_key_up(self, event, skip=skip)
242
243
244 def _on_enter(self):
245 if self.debug:
246 import sys
247 print >>sys.__stdout__, repr(self.get_current_edit_buffer())
248 PrefilterFrontEnd._on_enter(self)
243
249
244 def _set_title(self, title):
250 def _set_title(self, title):
245 return self.Parent.SetTitle(title)
251 return self.Parent.SetTitle(title)
General Comments 0
You need to be logged in to leave comments. Login now