Beispiel #1
0
 def _map_completions(self, completions):
     for completion in completions:
         tooltip = icon = text = match = None
         if isinstance(completion, (tuple, list)):
             match = completion[1]
             text = textutils.asciify(completion[0])
         elif isinstance(completion, dict):
             display = completion.get("display", completion.get('title'))
             text = textutils.asciify(display)
             match = completion.get("match", display)
             icon = completion.get("icon", completion.get('image'))
             tooltip = completion.get("tool_tip")
         else:
             match = text = completion
         yield completion, text, match, icon, tooltip
Beispiel #2
0
 def on_editor_keyPressed(self, event):
     alreadyTyped, start, end = self.editor.wordUnderCursor(
         direction="left", search=True
     )
     if alreadyTyped is None:
         self.completer.hide()
     else:
         self.completer.setCompletionPrefix(alreadyTyped)
         if self.isActive():
             if not (self.completer.setCurrentRow(0) or self.completer.trySetNextModel()):
                 self.completer.hide()
             else:
                 self.completer.complete(self.editor.cursorRect())
         elif not (event.modifiers() & QtCore.Qt.ControlModifier) and \
                 (text.asciify(event.text()) in COMPLETER_CHARS) and \
                 end - start >= self.editor.word_length_to_complete:
             self.completer.runCompleter()
Beispiel #3
0
 def post_key_event(self, event):
     if self.isVisible():
         maxPosition = self.startCursorPosition + len(self.completionPrefix()) + 1
         cursor = self.editor.textCursor()
         
         if self.startCursorPosition <= cursor.position() <= maxPosition:
             cursor.setPosition(self.startCursorPosition, QtGui.QTextCursor.KeepAnchor)
             self.setCompletionPrefix(cursor.selectedText())
             if not self.setCurrentRow(0) and self.trySetNextModel():
                 self.complete(self.editor.cursorRect())
             elif self.model() is None:
                 self.hide()
         else:
             self.hide()
     elif text.asciify(event.text()) in COMPLETER_CHARS:
         alreadyTyped, start, end = self.editor.wordUnderCursor(direction="left", search = True)
         if end - start >= self.editor.wordLengthToComplete:
             self.explicitLaunch = False
             self.runCompleter(self.editor.cursorRect(), alreadyTyped)