Пример #1
0
 def addError(self, error_type, line, column=1, message=None,
              selectLine=True):
     assert error_type in self.colors and self.colors[error_type] is not None
     selectLine = selectLine or not column
     c = cursorForPosition(self.editor.codeEdit, line, column,
                           selectEndOfLine=selectLine)
     deco = TextDecoration(c, draw_order=error_type + 1, tooltip=message)
     deco.setSpellchecking(color=QColor(self.colors[error_type]))
     self.__decorations.append(deco)
     self.editor.codeEdit.addDecoration(deco)
     if self.checkers_panel:
         self.__markers.append(
             self.checkers_panel.addCheckerMarker(error_type, line, message))
Пример #2
0
class HighlightLineMode(Mode):
    """
    This mode highlights the current line.

    Line color is defined by :attr:`pcef.style.Style.activeLineColor`
    """
    #: Mode identifier
    IDENTIFIER = "Highlight line"

    #: Mode description
    DESCRIPTION = "Highlight the current line in the editor"

    def __init__(self):
        super(HighlightLineMode, self).__init__(
            self.IDENTIFIER, self.DESCRIPTION)
        self.__pos = -1
        self.__decoration = None
        self.__brush = None

    def _onStateChanged(self, state):
        """ Connects/Disconnects to/from CodeEdit signals """
        if state is True:
            self.editor.codeEdit.cursorPositionChanged.connect(self.changeActiveLine)
            self.changeActiveLine()
        else:
            self.editor.codeEdit.cursorPositionChanged.disconnect(self.changeActiveLine)
            self.editor.codeEdit.removeDecoration(self.__decoration)

    def _onStyleChanged(self):
        """ Updates the pygments style """
        self.__brush = QBrush(QColor(self.currentStyle.activeLineColor))
        self.__pos = -1
        self.changeActiveLine()

    @Slot()
    def changeActiveLine(self):
        """ Updates the active line decoration """
        tc = self.editor.codeEdit.textCursor()
        pos = tc.blockNumber()
        if pos != self.__pos:
            self.__pos = pos
            # remove previous selection
            self.editor.codeEdit.removeDecoration(self.__decoration)
            # add new selection
            self.__decoration = TextDecoration(tc)
            self.__decoration.setBackground(self.__brush)
            self.__decoration.setFullWidth()
            self.editor.codeEdit.addDecoration(self.__decoration)
Пример #3
0
 def changeActiveLine(self):
     """ Updates the active line decoration """
     tc = self.editor.codeEdit.textCursor()
     pos = tc.blockNumber()
     if pos != self.__pos:
         self.__pos = pos
         # remove previous selection
         self.editor.codeEdit.removeDecoration(self.__decoration)
         # add new selection
         self.__decoration = TextDecoration(tc)
         self.__decoration.setBackground(self.__brush)
         self.__decoration.setFullWidth()
         self.editor.codeEdit.addDecoration(self.__decoration)
Пример #4
0
 def __createDecoration(self, tc):
     """ Creates the text occurences decoration """
     deco = TextDecoration(tc)
     deco.setBackground(QBrush(QColor(self.currentStyle.searchBackgroundColor)))
     deco.setForeground(QBrush(QColor(self.currentStyle.searchColor)))
     return deco