def mouseMoveEvent(self, event): position = event.pos() cursor = self.cursorForPosition(position) block = cursor.block() if settings.ERRORS_HIGHLIGHT_LINE and \ (block.blockNumber()) in self.errors.errorsSummary: message = '\n'.join(self.errors.errorsSummary[block.blockNumber()]) QToolTip.showText(self.mapToGlobal(position), message, self) elif settings.CHECK_HIGHLIGHT_LINE and \ (block.blockNumber()) in self.pep8.pep8checks: message = '\n'.join(self.pep8.pep8checks[block.blockNumber()]) QToolTip.showText(self.mapToGlobal(position), message, self) if event.modifiers() == Qt.ControlModifier: cursor.select(QTextCursor.WordUnderCursor) cursor.movePosition(QTextCursor.Right, QTextCursor.KeepAnchor) if cursor.selectedText().endsWith('(') or \ cursor.selectedText().endsWith('.'): cursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor) self.extraSelections = [] selection = QTextEdit.ExtraSelection() lineColor = QColor( resources.CUSTOM_SCHEME.get( 'linkNavigate', resources.COLOR_SCHEME['linkNavigate'])) selection.format.setForeground(lineColor) selection.format.setFontUnderline(True) selection.cursor = cursor self.extraSelections.append(selection) self.setExtraSelections(self.extraSelections) else: self.extraSelections = [] self.setExtraSelections(self.extraSelections) QPlainTextEdit.mouseMoveEvent(self, event)
def drawCursor(self, cursor): """Draws the cursor position as the selection of the specified cursor.""" es = QTextEdit.ExtraSelection() es.format.setBackground(self.textEdit().palette().color(QPalette.Text)) es.format.setForeground(self.textEdit().palette().color(QPalette.Base)) es.cursor = cursor self.textEdit().setExtraSelections([es])
def highlight_selected_word(self): #Highlight selected variable if not self.isReadOnly() and not self.textCursor().hasSelection(): word = self._text_under_cursor() if self._patIsWord.match(word): lineColor = QColor( resources.CUSTOM_SCHEME.get( 'selected-word', resources.COLOR_SCHEME['selected-word'])) lineColor.setAlpha(100) block = self.document().findBlock(0) cursor = self.document().find(word, block.position(), QTextDocument.FindCaseSensitively or \ QTextDocument.FindWholeWords) while block.isValid() and \ block.blockNumber() <= self._sidebarWidget.highest_line \ and cursor.position() != -1: selection = QTextEdit.ExtraSelection() selection.format.setBackground(lineColor) selection.cursor = cursor self.extraSelections.append(selection) cursor = self.document().find(word, cursor.position(), QTextDocument.FindCaseSensitively or \ QTextDocument.FindWholeWords) block = block.next() self.setExtraSelections(self.extraSelections)
def makeSelection(cursor): selection = QTextEdit.ExtraSelection() selection.format.setBackground(lineColor) selection.format.setProperty(QTextFormat.FullWidthSelection, True) cursor.clearSelection() selection.cursor = cursor return selection
def highlight(self, format, cursors, priority=0, msec=0): """Highlights the selection of an arbitrary list of QTextCursors. format can be a name for a predefined text format or a QTextCharFormat; in the first case the textFormat() method should return a qtextformat to use. priority determines the order of drawing, highlighting with higher priority is drawn over highlighting with lower priority. msec, if > 0, removes the highlighting after that many milliseconds. """ fmt = format if isinstance(format, QTextFormat) else self.textFormat(format) selections = [] for cursor in cursors: es = QTextEdit.ExtraSelection() es.cursor = cursor es.format = fmt selections.append(es) if msec: def clear(selfref=weakref.ref(self)): self = selfref() if self: self.clear(format) timer = QTimer(timeout=clear, singleShot=True) timer.start(msec) self._selections[format] = (priority, selections, timer) else: self._selections[format] = (priority, selections) self.update()
def highlight(self): editor = self.editor.get_editor() text = self.text[editor] for line in text[1]: if text[1][line] == "=": continue selection = QTextEdit.ExtraSelection() block = editor.document().findBlockByLineNumber(line) selection.cursor = editor.textCursor() selection.cursor.setPosition(block.position()) if text[1][line] == "-": lineColor = QColor(255, 0, 0, 50) if text[1][line] == "+": lineColor = QColor(0, 0, 255, 50) selection.format.setBackground(lineColor) selection.format.setProperty(QTextFormat.FullWidthSelection, True) selection.cursor.movePosition(QTextCursor.EndOfBlock) editor.extraSelections.append(selection) editor.setExtraSelections(editor.extraSelections) editor.setReadOnly(True)
def mouseMoveEvent(self, event): position = event.pos() cursor = self.cursorForPosition(position) block = cursor.block() checkers = self._neditable.sorted_checkers for items in checkers: checker, color, _ = items if block.blockNumber() in checker.checks: message = checker.checks[block.blockNumber()][0] QToolTip.showText(self.mapToGlobal(position), message, self) if event.modifiers() == Qt.ControlModifier: cursor.select(QTextCursor.WordUnderCursor) selection_start = cursor.selectionStart() selection_end = cursor.selectionEnd() cursor.setPosition(selection_start - 1) cursor.setPosition(selection_end + 1, QTextCursor.KeepAnchor) if cursor.selectedText()[-1:] in ('(', '.') or \ cursor.selectedText()[:1] in ('.', '@'): self.extraSelections = [] selection = QTextEdit.ExtraSelection() lineColor = QColor( resources.CUSTOM_SCHEME.get( 'linkNavigate', resources.COLOR_SCHEME['linkNavigate'])) selection.format.setForeground(lineColor) selection.format.setFontUnderline(True) selection.cursor = cursor self.extraSelections.append(selection) self.setExtraSelections(self.extraSelections) else: self.extraSelections = [] self.setExtraSelections(self.extraSelections) QPlainTextEdit.mouseMoveEvent(self, event)
def _makeQtExtraSelection(startAbsolutePosition, length): selection = QTextEdit.ExtraSelection() cursor = QTextCursor(self.document()) cursor.setPosition(startAbsolutePosition) cursor.setPosition(startAbsolutePosition + length, QTextCursor.KeepAnchor) selection.cursor = cursor selection.format = self._userExtraSelectionFormat return selection
def highligtCurrentLine(self): newCurrentLineNumber = self.textCursor().blockNumber() if newCurrentLineNumber != self.currentLineNumber: self.currentLineNumber = newCurrentLineNumber hi_selection = QTextEdit.ExtraSelection() hi_selection.format.setBackground(self.currentLineColor) hi_selection.format.setProperty(QTextFormat.FullWidthSelection, True) hi_selection.cursor = self.textCursor() hi_selection.cursor.clearSelection() self.setExtraSelections([hi_selection])
def highlight_current_line(self): """Highlight current line""" selection = QTextEdit.ExtraSelection() # selection.format.setProperty(QTextFormat.FullWidthSelection, # QVariant(True)) selection.format.setBackground(self.currentline_color) selection.cursor = self.textCursor() selection.cursor.clearSelection() self.set_extra_selections('current_line', [selection]) self.update_extra_selections()
def update_highlights(self): boxes = [self.ui.txtTranslated, self.ui.txtOriginal, self.ui.txtComments] for box in boxes: selections = [] text = common.qt_to_unicode(box.toPlainText()) cursor = QTextCursor(box.document()) base_sel = QTextEdit.ExtraSelection() base_sel.cursor = cursor base_sel.format.setForeground(QColor(255, 0, 0)) for match in self.query_re.finditer(text): sel = QTextEdit.ExtraSelection(base_sel) sel.cursor.setPosition(match.start(), QTextCursor.MoveAnchor) sel.cursor.setPosition(match.end(), QTextCursor.KeepAnchor) selections.append(sel) box.setExtraSelections(selections)
def _highlight_current_line(self): self.extra_selections = [] selection = QTextEdit.ExtraSelection() selection.format.setBackground(self._color_current_line) selection.format.setProperty(QTextFormat.FullWidthSelection, QVariant(True)) selection.cursor = self.textCursor() selection.cursor.clearSelection() self.extra_selections.append(selection) self.setExtraSelections(self.extra_selections)
def marcar_error_en_la_linea(self, numero, descripcion): hi_selection = QTextEdit.ExtraSelection() hi_selection.format.setBackground(QColor(255, 220, 220)) hi_selection.format.setProperty(QTextFormat.FullWidthSelection, QVariant(True)) hi_selection.cursor = self.textCursor() posicion_linea = self.document().findBlockByLineNumber(numero).position() hi_selection.cursor.setPosition(posicion_linea) hi_selection.cursor.clearSelection() self.setExtraSelections([hi_selection])
def highlight(self, cursors): """Highlights the selections of the specified QTextCursor instances.""" selections = [] for cursor in cursors: es = QTextEdit.ExtraSelection() es.cursor = cursor es.format = self.format selections.append(es) self.edit().setExtraSelections(selections) if self.time and selections: self._timer.start(self.time)
def highlightCurrentLine(self): selections = [] if (not self.isReadOnly()): selection = QTextEdit.ExtraSelection() lineColor = QColor(240,240,240) selection.format.setBackground(lineColor) selection.format.setProperty(QTextFormat.FullWidthSelection, True) selection.cursor = self.textCursor() selection.cursor.clearSelection() selections.append(selection) self.setExtraSelections(selections)
def highlight_current_line(self): extraSelections = [] if not self.isReadOnly(): selection = QTextEdit.ExtraSelection() lineColor = QColor(Qt.darkCyan) lineColor.setAlpha(20) selection.format.setBackground(lineColor) selection.format.setProperty(QTextFormat.FullWidthSelection, True) selection.cursor = self.textCursor() selection.cursor.clearSelection() extraSelections.append(selection) self.setExtraSelections(extraSelections)
def _makeBraceExtraSelection(self, block, pos, matched): """Make QTextEdit.ExtraSelection for highlighted brace """ sel = QTextEdit.ExtraSelection() sel.cursor = QTextCursor(block) sel.cursor.setPosition(block.position() + pos, QTextCursor.MoveAnchor) sel.cursor.setPosition(block.position() + pos + 1, QTextCursor.KeepAnchor) if matched: sel.format = DEFAULT_STYLE['matchedBrace'] else: sel.format = DEFAULT_STYLE['unMatchedBrace'] return sel
def selections(self): """Build list of extra selections for rectangular selection""" selections = [] cursors = self.cursors() if cursors: background = self._qpart.palette().color(QPalette.Highlight) foreground = self._qpart.palette().color(QPalette.HighlightedText) for cursor in cursors: selection = QTextEdit.ExtraSelection() selection.format.setBackground(background) selection.format.setForeground(foreground) selection.cursor = cursor selections.append(selection) return selections
def highlightCurrentLine(self): #Hilgight background _selection = QTextEdit.ExtraSelection() _selection.cursor = self.textCursor() _selection.cursor.clearSelection() _selection.format.setBackground(self.hl_color) _selection.format.setProperty(QTextFormat.FullWidthSelection, True) extraSelection = [] extraSelection.append(_selection) extras = self.check_brackets() if extras: extraSelection.extend(extras) if not self.qt18720: self.setExtraSelections(extraSelection)
def _makeMatchSelection(self, block, columnIndex, matched): """Make matched or unmatched QTextEdit.ExtraSelection """ selection = QTextEdit.ExtraSelection() if matched: bgColor = Qt.green else: bgColor = Qt.red selection.format.setBackground(bgColor) selection.cursor = QTextCursor(block) selection.cursor.setPosition(block.position() + columnIndex) selection.cursor.movePosition(QTextCursor.Right, QTextCursor.KeepAnchor) return selection
def text_call(self, state=False): self.git = git.Git() path = self.editor.get_project_owner() a_file = self.editor.get_editor_path() text_file = self.editor.get_editor().get_text() if state: self.editor.add_editor('staged({0})'.format( os.path.basename(a_file))) else: self.editor.add_editor('unstaged({0})'.format( os.path.basename(a_file))) editor = self.editor.get_editor() self.text[editor] = self.git.text(path, a_file, state, text_file) editor.insertPlainText(self.text[editor][2]) self.connect(editor, SIGNAL("cursorPositionChanged()"), self.highlight) text = self.text[editor] for line in text[1]: if text[1][line] == "=": continue selection = QTextEdit.ExtraSelection() block = editor.document().findBlockByLineNumber(line) selection.cursor = editor.textCursor() selection.cursor.setPosition(block.position()) if text[1][line] == "-": lineColor = QColor(255, 0, 0, 50) if text[1][line] == "+": lineColor = QColor(0, 0, 255, 50) selection.format.setBackground(lineColor) selection.format.setProperty(QTextFormat.FullWidthSelection, True) selection.cursor.movePosition(QTextCursor.EndOfBlock) editor.extraSelections.append(selection) editor.setExtraSelections(editor.extraSelections) editor.setReadOnly(True) editor.textModified = False
def __highlight(self, positions, color=None, cancel=False): if cancel: self.clear_extra_selections('brace_matching') return extra_selections = [] for position in positions: if position > self.get_position('eof'): return selection = QTextEdit.ExtraSelection() selection.format.setBackground(color) selection.cursor = self.textCursor() selection.cursor.clearSelection() selection.cursor.setPosition(position) selection.cursor.movePosition(QTextCursor.NextCharacter, QTextCursor.KeepAnchor) extra_selections.append(selection) self.set_extra_selections('brace_matching', extra_selections) self.update_extra_selections()
def highlightError(self, index): """Hihglights the error message at the given index and jumps to its location.""" self._currentErrorIndex = index # set text format pos, anchor, url = self._errors[index] es = QTextEdit.ExtraSelection() es.cursor = QTextCursor(self.document()) es.cursor.setPosition(pos) es.cursor.setPosition(anchor, QTextCursor.KeepAnchor) bg = qutil.mixcolor(self.palette().highlight().color(), self.palette().base().color(), 0.4) es.format.setBackground(bg) es.format.setProperty(QTextFormat.FullWidthSelection, True) self.setExtraSelections([es]) # scroll log to the message cursor = QTextCursor(self.document()) cursor.setPosition(anchor) self.setTextCursor(cursor) cursor.setPosition(pos) self.setTextCursor(cursor) # jump to the error location cursor = errors.errors(self._document()).cursor(url, True) if cursor: self.parentWidget().mainwindow().setTextCursor(cursor, findOpenView=True)
def highlight_current_line(self): self.emit(SIGNAL("cursorPositionChange(int, int)"), self.textCursor().blockNumber() + 1, self.textCursor().columnNumber()) self.extraSelections = [] if not self.isReadOnly(): block = self.textCursor() selection = QTextEdit.ExtraSelection() lineColor = self._current_line_color lineColor.setAlpha( resources.CUSTOM_SCHEME.get( "current-line-opacity", resources.COLOR_SCHEME["current-line-opacity"])) checkers = self._neditable.sorted_checkers for items in checkers: checker, color, _ = items if block.blockNumber() in checker.checks: lineColor = QColor(color) lineColor.setAlpha( resources.CUSTOM_SCHEME.get( "checker-background-opacity", resources. COLOR_SCHEME["checker-background-opacity"])) break selection.format.setBackground(lineColor) selection.format.setProperty(QTextFormat.FullWidthSelection, True) selection.cursor = self.textCursor() selection.cursor.clearSelection() self.extraSelections.append(selection) self.setExtraSelections(self.extraSelections) #Re-position tooltip to allow text editing in the line of the error if QToolTip.isVisible(): QToolTip.hideText() if self._braces is not None: self._braces = None cursor = self.textCursor() if cursor.position() == 0: self.setExtraSelections(self.extraSelections) return cursor.movePosition(QTextCursor.PreviousCharacter, QTextCursor.KeepAnchor) text = cursor.selectedText() pos1 = cursor.position() if text in (")", "]", "}"): pos2 = self._match_braces(pos1, text, forward=False) elif text in ("(", "[", "{"): pos2 = self._match_braces(pos1, text, forward=True) else: self.setExtraSelections(self.extraSelections) return if pos2 is not None: self._braces = (pos1, pos2) selection = QTextEdit.ExtraSelection() selection.format.setForeground( QColor( resources.CUSTOM_SCHEME.get( 'brace-foreground', resources.COLOR_SCHEME.get('brace-foreground')))) selection.cursor = cursor self.extraSelections.append(selection) selection = QTextEdit.ExtraSelection() selection.format.setForeground( QColor( resources.CUSTOM_SCHEME.get( 'brace-foreground', resources.COLOR_SCHEME.get('brace-foreground')))) selection.format.setBackground( QColor( resources.CUSTOM_SCHEME.get( 'brace-background', resources.COLOR_SCHEME.get('brace-background')))) selection.cursor = self.textCursor() selection.cursor.setPosition(pos2) selection.cursor.movePosition(QTextCursor.NextCharacter, QTextCursor.KeepAnchor) self.extraSelections.append(selection) else: self._braces = (pos1, ) selection = QTextEdit.ExtraSelection() selection.format.setBackground( QColor( resources.CUSTOM_SCHEME.get( 'brace-background', resources.COLOR_SCHEME.get('brace-background')))) selection.format.setForeground( QColor( resources.CUSTOM_SCHEME.get( 'brace-foreground', resources.COLOR_SCHEME.get('brace-foreground')))) selection.cursor = cursor self.extraSelections.append(selection) self.setExtraSelections(self.extraSelections)
def highlight_current_line(self): self.extraSelections = [] selection = QTextEdit.ExtraSelection() lineColor = QColor( resources.CUSTOM_SCHEME.get('CurrentLine', resources.COLOR_SCHEME['CurrentLine'])) lineColor.setAlpha(20) selection.format.setBackground(lineColor) selection.format.setProperty(QTextFormat.FullWidthSelection, True) selection.cursor = self.textCursor() selection.cursor.clearSelection() self.extraSelections.append(selection) self.setExtraSelections(self.extraSelections) if self._braces is not None: self._braces = None cursor = self.textCursor() if cursor.position() == 0: self.setExtraSelections(self.extraSelections) return cursor.movePosition(QTextCursor.PreviousCharacter, QTextCursor.KeepAnchor) text = cursor.selectedText() pos1 = cursor.position() if text in (')', ']', '}'): pos2 = self._match_braces(pos1, text, forward=False) elif text in ('(', '[', '{'): pos2 = self._match_braces(pos1, text, forward=True) else: self.setExtraSelections(self.extraSelections) return #if pos2 is not None: #self._braces = (pos1, pos2) #selection = QTextEdit.ExtraSelection() #selection.format.setForeground(QColor( #resources.CUSTOM_SCHEME.get('brace-foreground', #resources.COLOR_SCHEME.get('brace-foreground')))) #selection.format.setBackground(QColor( #resources.CUSTOM_SCHEME.get('brace-background', #resources.COLOR_SCHEME.get('brace-background')))) #selection.cursor = cursor #self.extraSelections.append(selection) #selection = QTextEdit.ExtraSelection() #selection.format.setForeground(QColor( #resources.CUSTOM_SCHEME.get('brace-foreground', #resources.COLOR_SCHEME.get('brace-foreground')))) #selection.format.setBackground(QColor( #resources.CUSTOM_SCHEME.get('brace-background', #resources.COLOR_SCHEME.get('brace-background')))) #selection.cursor = self.textCursor() #selection.cursor.setPosition(pos2) #selection.cursor.movePosition(QTextCursor.NextCharacter, #QTextCursor.KeepAnchor) #self.extraSelections.append(selection) #else: #self._braces = (pos1,) #selection = QTextEdit.ExtraSelection() #selection.format.setBackground(QColor( #resources.CUSTOM_SCHEME.get('brace-background', #resources.COLOR_SCHEME.get('brace-background')))) #selection.format.setForeground(QColor( #resources.CUSTOM_SCHEME.get('brace-foreground', #resources.COLOR_SCHEME.get('brace-foreground')))) #selection.cursor = cursor #self.extraSelections.append(selection) self.setExtraSelections(self.extraSelections)
def check_brackets(self): left, right = QTextEdit.ExtraSelection(),\ QTextEdit.ExtraSelection() cursor = self.textCursor() block = cursor.block() data = block.userData() previous, next = None, None if data is not None: position = cursor.position() block_position = cursor.block().position() braces = data.braces N = len(braces) for k in range(0, N): if braces[k].position == position - block_position or\ braces[k].position == position - block_position - 1: previous = braces[k].position + block_position if braces[k].character in ['{', '(', '[']: next = self.match_left(block, braces[k].character, k + 1, 0) elif braces[k].character in ['}', ')', ']']: next = self.match_right(block, braces[k].character, k, 0) # if next is None: # next = -1 if (next is not None and next > 0) \ and (previous is not None and previous > 0): format = QTextCharFormat() cursor.setPosition(previous) cursor.movePosition(QTextCursor.NextCharacter, QTextCursor.KeepAnchor) format.setForeground(QColor('white')) format.setBackground(QColor('blue')) left.format = format left.cursor = cursor cursor.setPosition(next) cursor.movePosition(QTextCursor.NextCharacter, QTextCursor.KeepAnchor) format.setForeground(QColor('white')) format.setBackground(QColor('blue')) right.format = format right.cursor = cursor return left, right elif previous is not None: format = QTextCharFormat() cursor.setPosition(previous) cursor.movePosition(QTextCursor.NextCharacter, QTextCursor.KeepAnchor) format.setForeground(QColor('white')) format.setBackground(QColor('red')) left.format = format left.cursor = cursor return (left, ) elif next is not None: format = QTextCharFormat() cursor.setPosition(next) cursor.movePosition(QTextCursor.NextCharacter, QTextCursor.KeepAnchor) format.setForeground(QColor('white')) format.setBackground(QColor('red')) left.format = format left.cursor = cursor return (left, )
def highlight_current_line(self): self.emit(SIGNAL("cursorPositionChange(int, int)"), self.textCursor().blockNumber() + 1, self.textCursor().columnNumber()) self.extraSelections = [] if not self.isReadOnly(): selection = QTextEdit.ExtraSelection() lineColor = QColor( resources.CUSTOM_SCHEME.get( 'current-line', resources.COLOR_SCHEME['current-line'])) lineColor.setAlpha(20) selection.format.setBackground(lineColor) selection.format.setProperty(QTextFormat.FullWidthSelection, True) selection.cursor = self.textCursor() selection.cursor.clearSelection() self.extraSelections.append(selection) self.setExtraSelections(self.extraSelections) if self._braces is not None: self._braces = None cursor = self.textCursor() if cursor.position() == 0: self.setExtraSelections(self.extraSelections) return cursor.movePosition(QTextCursor.PreviousCharacter, QTextCursor.KeepAnchor) text = unicode(cursor.selectedText()) pos1 = cursor.position() if text in (')', ']', '}'): pos2 = self._match_braces(pos1, text, forward=False) elif text in ('(', '[', '{'): pos2 = self._match_braces(pos1, text, forward=True) else: self.setExtraSelections(self.extraSelections) return if pos2 is not None: self._braces = (pos1, pos2) selection = QTextEdit.ExtraSelection() selection.format.setForeground( QColor( resources.CUSTOM_SCHEME.get( 'brace-foreground', resources.COLOR_SCHEME.get('brace-foreground')))) selection.format.setBackground( QColor( resources.CUSTOM_SCHEME.get( 'brace-background', resources.COLOR_SCHEME.get('brace-background')))) selection.cursor = cursor self.extraSelections.append(selection) selection = QTextEdit.ExtraSelection() selection.format.setForeground( QColor( resources.CUSTOM_SCHEME.get( 'brace-foreground', resources.COLOR_SCHEME.get('brace-foreground')))) selection.format.setBackground( QColor( resources.CUSTOM_SCHEME.get( 'brace-background', resources.COLOR_SCHEME.get('brace-background')))) selection.cursor = self.textCursor() selection.cursor.setPosition(pos2) selection.cursor.movePosition(QTextCursor.NextCharacter, QTextCursor.KeepAnchor) self.extraSelections.append(selection) else: self._braces = (pos1, ) selection = QTextEdit.ExtraSelection() selection.format.setBackground( QColor( resources.CUSTOM_SCHEME.get( 'brace-background', resources.COLOR_SCHEME.get('brace-background')))) selection.format.setForeground( QColor( resources.CUSTOM_SCHEME.get( 'brace-foreground', resources.COLOR_SCHEME.get('brace-foreground')))) selection.cursor = cursor self.extraSelections.append(selection) self.setExtraSelections(self.extraSelections)
def highlight_current_line(self): self.emit(SIGNAL("cursorPositionChange(int, int)"), self.textCursor().blockNumber() + 1, self.textCursor().columnNumber()) self.extraSelections = [] if not self.isReadOnly(): selection = QTextEdit.ExtraSelection() lineColor = QColor( resources.CUSTOM_SCHEME.get( 'current-line', resources.COLOR_SCHEME['current-line'])) lineColor.setAlpha(20) selection.format.setBackground(lineColor) selection.format.setProperty(QTextFormat.FullWidthSelection, True) selection.cursor = self.textCursor() selection.cursor.clearSelection() self.extraSelections.append(selection) self.setExtraSelections(self.extraSelections) #Find Errors if settings.ERRORS_HIGHLIGHT_LINE and \ len(self.errors.errorsSummary) < settings.MAX_HIGHLIGHT_ERRORS: cursor = self.textCursor() for lineno in self.errors.errorsSummary: block = self.document().findBlockByLineNumber(lineno - 1) if not block.isValid(): continue cursor.setPosition(block.position()) selection = QTextEdit.ExtraSelection() selection.format.setUnderlineColor( QColor( resources.CUSTOM_SCHEME.get( 'error-underline', resources.COLOR_SCHEME['error-underline']))) selection.format.setUnderlineStyle( QTextCharFormat.WaveUnderline) selection.cursor = cursor selection.cursor.movePosition(QTextCursor.EndOfBlock, QTextCursor.KeepAnchor) self.extraSelections.append(selection) if self.errors.errorsSummary: self.setExtraSelections(self.extraSelections) #Check Style if settings.CHECK_HIGHLIGHT_LINE and \ len(self.pep8.pep8checks) < settings.MAX_HIGHLIGHT_ERRORS: cursor = self.textCursor() for line in self.pep8.pep8checks: block = self.document().findBlockByLineNumber(line - 1) if not block.isValid(): continue cursor.setPosition(block.position()) selection = QTextEdit.ExtraSelection() selection.format.setUnderlineColor( QColor( resources.CUSTOM_SCHEME.get( 'pep8-underline', resources.COLOR_SCHEME['pep8-underline']))) selection.format.setUnderlineStyle( QTextCharFormat.WaveUnderline) selection.cursor = cursor selection.cursor.movePosition(QTextCursor.EndOfBlock, QTextCursor.KeepAnchor) self.extraSelections.append(selection) if self.pep8.pep8checks: self.setExtraSelections(self.extraSelections) #Re-position tooltip to allow text editing in the line of the error if QToolTip.isVisible(): QToolTip.hideText() if self._braces is not None: self._braces = None cursor = self.textCursor() if cursor.position() == 0: self.setExtraSelections(self.extraSelections) return cursor.movePosition(QTextCursor.PreviousCharacter, QTextCursor.KeepAnchor) text = unicode(cursor.selectedText()) pos1 = cursor.position() if text in (')', ']', '}'): pos2 = self._match_braces(pos1, text, forward=False) elif text in ('(', '[', '{'): pos2 = self._match_braces(pos1, text, forward=True) else: self.setExtraSelections(self.extraSelections) return if pos2 is not None: self._braces = (pos1, pos2) selection = QTextEdit.ExtraSelection() selection.format.setForeground( QColor( resources.CUSTOM_SCHEME.get( 'brace-foreground', resources.COLOR_SCHEME.get('brace-foreground')))) selection.cursor = cursor self.extraSelections.append(selection) selection = QTextEdit.ExtraSelection() selection.format.setForeground( QColor( resources.CUSTOM_SCHEME.get( 'brace-foreground', resources.COLOR_SCHEME.get('brace-foreground')))) selection.format.setBackground( QColor( resources.CUSTOM_SCHEME.get( 'brace-background', resources.COLOR_SCHEME.get('brace-background')))) selection.cursor = self.textCursor() selection.cursor.setPosition(pos2) selection.cursor.movePosition(QTextCursor.NextCharacter, QTextCursor.KeepAnchor) self.extraSelections.append(selection) else: self._braces = (pos1, ) selection = QTextEdit.ExtraSelection() selection.format.setBackground( QColor( resources.CUSTOM_SCHEME.get( 'brace-background', resources.COLOR_SCHEME.get('brace-background')))) selection.format.setForeground( QColor( resources.CUSTOM_SCHEME.get( 'brace-foreground', resources.COLOR_SCHEME.get('brace-foreground')))) selection.cursor = cursor self.extraSelections.append(selection) self.setExtraSelections(self.extraSelections)