Show More
@@ -109,7 +109,7 b' class WxConsoleView(stc.StyledTextCtrl):' | |||
|
109 | 109 | |
|
110 | 110 | def __init__(self,parent,prompt,intro="",background_color="BLACK", |
|
111 | 111 | pos=wx.DefaultPosition, ID = -1, size=wx.DefaultSize, |
|
112 | style=0): | |
|
112 | style=0, autocomplete_mode = 'IPYTHON'): | |
|
113 | 113 | ''' |
|
114 | 114 | Initialize console view. |
|
115 | 115 | |
@@ -121,6 +121,9 b' class WxConsoleView(stc.StyledTextCtrl):' | |||
|
121 | 121 | @param background_color: Can be BLACK or WHITE |
|
122 | 122 | @type background_color: string |
|
123 | 123 | @param other: init param of styledTextControl (can be used as-is) |
|
124 | @param autocomplete_mode: Can be 'IPYTHON' or 'STC' | |
|
125 | 'IPYTHON' show autocompletion the ipython way | |
|
126 | 'STC" show it scintilla text control way | |
|
124 | 127 | ''' |
|
125 | 128 | stc.StyledTextCtrl.__init__(self, parent, ID, pos, size, style) |
|
126 | 129 | |
@@ -213,6 +216,8 b' class WxConsoleView(stc.StyledTextCtrl):' | |||
|
213 | 216 | self.setPrompt(prompt) |
|
214 | 217 | self.showPrompt() |
|
215 | 218 | |
|
219 | self.autocomplete_mode = autocomplete_mode | |
|
220 | ||
|
216 | 221 | self.Bind(wx.EVT_KEY_DOWN, self._onKeypress, self) |
|
217 | 222 | |
|
218 | 223 | def asyncWrite(self, text): |
@@ -354,7 +359,17 b' class WxConsoleView(stc.StyledTextCtrl):' | |||
|
354 | 359 | self.removeFromTo(self.getCurrentPromptStart(),self.getCurrentLineEnd()) |
|
355 | 360 | self.changeLine(history) |
|
356 | 361 | |
|
362 | def setCompletionMethod(self, completion): | |
|
363 | if completion in ['IPYTHON','STC']: | |
|
364 | self.autocomplete_mode = completion | |
|
365 | else: | |
|
366 | raise AttributeError | |
|
367 | ||
|
368 | def getCompletionMethod(self, completion): | |
|
369 | return self.autocomplete_mode | |
|
370 | ||
|
357 | 371 | def writeCompletion(self, possibilities): |
|
372 | if self.autocomplete_mode == 'IPYTHON': | |
|
358 | 373 | max_len = len(max(possibilities,key=len)) |
|
359 | 374 | max_symbol =' '*max_len |
|
360 | 375 | |
@@ -379,6 +394,15 b' class WxConsoleView(stc.StyledTextCtrl):' | |||
|
379 | 394 | buf+=symbol+'\n' |
|
380 | 395 | pos = 1 |
|
381 | 396 | self.write(buf) |
|
397 | else: | |
|
398 | possibilities.sort() # Python sorts are case sensitive | |
|
399 | self.AutoCompSetIgnoreCase(False) | |
|
400 | #let compute the length ot last word | |
|
401 | splitter = [' ','(','[','{'] | |
|
402 | last_word = self.getCurrentLine() | |
|
403 | for breaker in splitter: | |
|
404 | last_word = last_word.split(breaker)[-1] | |
|
405 | self.AutoCompShow(len(last_word), " ".join(possibilities)) | |
|
382 | 406 | |
|
383 | 407 | def _onKeypress(self, event, skip=True): |
|
384 | 408 | ''' |
@@ -394,6 +418,8 b' class WxConsoleView(stc.StyledTextCtrl):' | |||
|
394 | 418 | @return: Return True if event as been catched. |
|
395 | 419 | @rtype: boolean |
|
396 | 420 | ''' |
|
421 | ||
|
422 | if not self.AutoCompActive(): | |
|
397 | 423 | if event.GetKeyCode() == wx.WXK_HOME: |
|
398 | 424 | if event.Modifiers == wx.MOD_NONE: |
|
399 | 425 | self.moveCursorOnNewValidKey() |
@@ -428,6 +454,8 b' class WxConsoleView(stc.StyledTextCtrl):' | |||
|
428 | 454 | event.Skip() |
|
429 | 455 | return True |
|
430 | 456 | return False |
|
457 | else: | |
|
458 | event.Skip() | |
|
431 | 459 | |
|
432 | 460 | def OnUpdateUI(self, evt): |
|
433 | 461 | # check for matching braces |
@@ -516,11 +544,23 b' class IPShellWidget(wx.Panel):' | |||
|
516 | 544 | |
|
517 | 545 | self.cout.write = self.text_ctrl.asyncWrite |
|
518 | 546 | |
|
547 | self.completion_option = wx.CheckBox(self, -1, "Scintilla completion") | |
|
548 | self.completion_option.SetValue(False) | |
|
549 | option_text = wx.StaticText(self,-1,'Options:') | |
|
550 | ||
|
519 | 551 | self.text_ctrl.Bind(wx.EVT_KEY_DOWN, self.keyPress) |
|
552 | self.Bind(wx.EVT_CHECKBOX, self.evtCheckOptionCompletion, self.completion_option) | |
|
520 | 553 | |
|
521 | 554 | ### making the layout of the panel ### |
|
522 | 555 | sizer = wx.BoxSizer(wx.VERTICAL) |
|
523 | 556 | sizer.Add(self.text_ctrl, 1, wx.EXPAND) |
|
557 | option_sizer = wx.BoxSizer(wx.HORIZONTAL) | |
|
558 | sizer.Add(option_sizer,0) | |
|
559 | option_sizer.AddMany([(10,15), | |
|
560 | option_text, | |
|
561 | (20,15), | |
|
562 | self.completion_option | |
|
563 | ]) | |
|
524 | 564 | self.SetAutoLayout(True) |
|
525 | 565 | sizer.Fit(self) |
|
526 | 566 | sizer.SetSizeHints(self) |
@@ -630,12 +670,20 b' class IPShellWidget(wx.Panel):' | |||
|
630 | 670 | autocompletions, etc. |
|
631 | 671 | ''' |
|
632 | 672 | if event.GetKeyCode() == ord('C'): |
|
633 | if event.Modifiers == wx.MOD_CONTROL: | |
|
673 | if event.Modifiers == wx.MOD_CONTROL or event.Modifiers == wx.MOD_ALT: | |
|
634 | 674 | if self.cur_state == 'WAIT_END_OF_EXECUTION': |
|
635 | 675 | #we raise an exception inside the IPython thread container |
|
636 | 676 | self.IP.ce.raise_exc(KeyboardInterrupt) |
|
637 | 677 | return |
|
638 | 678 | |
|
679 | #let this before 'wx.WXK_RETURN' because we have to put 'IDLE' | |
|
680 | #mode if AutoComp has been set as inactive | |
|
681 | if self.cur_state == 'COMPLETING': | |
|
682 | if not self.text_ctrl.AutoCompActive(): | |
|
683 | self.cur_state = 'IDLE' | |
|
684 | else: | |
|
685 | event.Skip() | |
|
686 | ||
|
639 | 687 | if event.KeyCode == wx.WXK_RETURN: |
|
640 | 688 | if self.cur_state == 'IDLE': |
|
641 | 689 | #we change the state ot the state machine |
@@ -680,6 +728,7 b' class IPShellWidget(wx.Panel):' | |||
|
680 | 728 | return |
|
681 | 729 | completed, possibilities = self.IP.complete(self.text_ctrl.getCurrentLine()) |
|
682 | 730 | if len(possibilities) > 1: |
|
731 | if self.text_ctrl.autocomplete_mode == 'IPYTHON': | |
|
683 | 732 | cur_slice = self.text_ctrl.getCurrentLine() |
|
684 | 733 | self.text_ctrl.write('\n') |
|
685 | 734 | self.text_ctrl.writeCompletion(possibilities) |
@@ -688,10 +737,22 b' class IPShellWidget(wx.Panel):' | |||
|
688 | 737 | self.text_ctrl.showPrompt() |
|
689 | 738 | self.text_ctrl.write(cur_slice) |
|
690 | 739 | self.text_ctrl.changeLine(completed or cur_slice) |
|
691 | ||
|
740 | else: | |
|
741 | self.cur_state = 'COMPLETING' | |
|
742 | self.text_ctrl.writeCompletion(possibilities) | |
|
743 | else: | |
|
744 | self.text_ctrl.changeLine(completed or cur_slice) | |
|
692 | 745 | return |
|
693 | 746 | event.Skip() |
|
694 | 747 | |
|
748 | #------------------------ Option Section --------------------------------- | |
|
749 | def evtCheckOptionCompletion(self, event): | |
|
750 | if event.IsChecked(): | |
|
751 | self.text_ctrl.setCompletionMethod('STC') | |
|
752 | else: | |
|
753 | self.text_ctrl.setCompletionMethod('IPYTHON') | |
|
754 | self.text_ctrl.SetFocus() | |
|
755 | ||
|
695 | 756 | #------------------------ Hook Section ----------------------------------- |
|
696 | 757 | def updateHistoryTracker(self,command_line): |
|
697 | 758 | ''' |
General Comments 0
You need to be logged in to leave comments.
Login now