Ejemplo n.º 1
0
 def on_char(self, event):
     keycode = event.GetKeyCode()
     ctrl = event.ControlDown()
     shift = event.ShiftDown()
     if keycode == wx.WXK_RETURN and shift and not ctrl:
         try:
             self.execute()
         except NotFound:
             pass
     else:
         _WXTextView.on_char(self, event)
Ejemplo n.º 2
0
 def __init__(self,
              parent,
              id=-1,
              pos=wx.DefaultPosition,
              size=wx.DefaultSize,
              style=0):
     _WXTextView.__init__(self,
                          parent,
                          id=id,
                          pos=pos,
                          size=size,
                          style=style)
     self.actions[(wx.WXK_TAB, False, False)] = 'complete'
     self.actions[(wx.WXK_RETURN, False, False)] = 'insert_newline_indented'
Ejemplo n.º 3
0
 def insert(self, i, textmodel):
     needscell = True
     try:
         i0, cell = self.find_cell()
         if not (i == i0 or i == i0 + length(cell)):
             needscell = False
     except NotFound:
         pass
     try:
         find_cell(textmodel.texel, 0)
         hascell = True
     except NotFound:
         hascell = False
     if needscell and not hascell:
         cell = Cell(NULL_TEXEL, NULL_TEXEL)
         self.model.insert(i, mk_textmodel(cell))
         info = self._remove, i, i + length(cell)
         self.add_undo(info)
         i = i + 1
     _WXTextView.insert(self, i, textmodel)
Ejemplo n.º 4
0
 def handle_action(self, action, shift=False):
     if action != 'complete':
         self.clear_temp()
         return _WXTextView.handle_action(self, action, shift)
     try:
         i0, cell = self.find_cell()
     except NotFound:
         return
     index = self.index
     if index <= i0 or index >= i0 + length(cell):
         return
     if self.has_temp():
         self.clear_temp()
         maxoptions = 2000
     else:
         maxoptions = 200
     word = self.get_word(index)
     completer = rlcompleter.Completer(INTERPRETER.namespace)
     options = set()
     i = 0
     while True:
         option = completer.complete(word, i)
         i += 1
         if option is None or len(options) == maxoptions:
             break
         options.add(option)
     if not options:
         self.print_temp("\n[No completion]\n")
     else:
         completion = reduce(common, options)[len(word):]
         if completion and len(options) != maxoptions:
             self.model.insert_text(index, completion)
             info = self._remove, index, index + len(completion)
             self.add_undo(info)
             index += len(completion)
         else:
             options = list(sorted(options))
             s = ', '.join(options)
             s = s.replace('(', '')  # I don't like the bracket
             if len(options) == maxoptions:
                 s += ' ... '
             self.print_temp('\n' + s + '\n')
     self.index = index