Example #1
0
 def __init__(self):
     super(SymbolMatcherMode, self).__init__()
     self._decorations = []
     self._match_background = QtGui.QBrush(QtGui.QColor('#B4EEB4'))
     self._match_foreground = QtGui.QColor('red')
     self._unmatch_background = QtGui.QBrush(QtGui.QColor('transparent'))
     self._unmatch_foreground = QtGui.QColor('red')
Example #2
0
 def _create_decoration(self, selection_start, selection_end):
     """ Creates the text occurences decoration """
     deco = TextDecoration(self.editor.document(), selection_start,
                           selection_end)
     deco.set_background(QtGui.QBrush(self.background))
     deco.set_foreground(QtGui.QBrush(self.foreground))
     deco.draw_order = 1
     return deco
Example #3
0
    def on_install(self, editor):
        """
        Extends :meth:`pyqode.core.api.Mode.on_install` method to set the
        editor instance as the parent widget.

        .. warning:: Don't forget to call **super** if you override this
            method!

        :param editor: editor instance
        :type editor: pyqode.core.api.CodeEdit
        """
        Mode.on_install(self, editor)
        self.setParent(editor)
        # Qt5 compatibility
        try:
            self.setPalette(QtWidgets.QApplication.instance().palette())
        except:
            self.setPalette(QtGui.QGuiApplication.palette())

        # Qt5 compatibility
        try:
            self.setFont(QtWidgets.QApplication.instance().font())
        except:
            self.setFont(QtGui.QGuiApplication.font())

        self.editor.panels.refresh()
        self._background_brush = QtGui.QBrush(
            QtGui.QColor(self.palette().window().color()))
        self._foreground_pen = QtGui.QPen(
            QtGui.QColor(self.palette().windowText().color()))
Example #4
0
 def highlight_disabled_columns(self, text):
     fmt = QtGui.QTextCharFormat()
     fmt.setForeground(QtGui.QBrush(self.editor.whitespaces_foreground))
     try:
         self.setFormat(0, 6 if text[6] in ['*', '-'] else 7, fmt)
     except IndexError:
         self.setFormat(0, len(text), fmt)
Example #5
0
 def paintEvent(self, event):
     """ Fills the panel background. """
     super(ReadOnlyPanel, self).paintEvent(event)
     if self.isVisible():
         # fill background
         painter = QtGui.QPainter(self)
         self._background_brush = QtGui.QBrush(self._color)
         painter.fillRect(event.rect(), self._background_brush)
Example #6
0
 def paintEvent(self, event):
     """ Fills the panel background. """
     # pylint: disable=invalid-name
     if self.isVisible():
         # fill background
         self._background_brush = QtGui.QBrush(self.editor.background)
         painter = QtGui.QPainter(self)
         painter.fillRect(event.rect(), self._background_brush)
Example #7
0
 def write(text_edit, text, color):
     text_edit.moveCursor(QtGui.QTextCursor.End)
     fmt = QtGui.QTextCharFormat()
     fmt.setUnderlineStyle(QtGui.QTextCharFormat.NoUnderline)
     fmt.setForeground(QtGui.QBrush(color))
     text_edit.setCurrentCharFormat(fmt)
     text_edit.insertPlainText(text)
     text_edit.moveCursor(QtGui.QTextCursor.End)
Example #8
0
 def _highlight_whitespaces(self, text):
     fmt = QtGui.QTextCharFormat()
     fmt.setForeground(QtGui.QBrush(self.editor.whitespaces_foreground))
     index = self.WHITESPACES.indexIn(text, 0)
     while index >= 0:
         index = self.WHITESPACES.pos(0)
         length = len(self.WHITESPACES.cap(0))
         self.setFormat(index, length, self.formats['whitespace'])
         index = self.WHITESPACES.indexIn(text, index + length)
 def _get_brush(self, color):
     """ Returns a brush for the color.
     """
     result = self._brushes.get(color)
     if result is None:
         qcolor = self._get_color(color)
         result = QtGui.QBrush(qcolor)
         self._brushes[color] = result
     return result
Example #10
0
 def paintEvent(self, event):
     # Fills the panel background using QPalette
     if self.isVisible():
         # fill background
         self._background_brush = QtGui.QBrush(
             QtGui.QColor(self.palette().window().color()))
         self._foreground_pen = QtGui.QPen(
             QtGui.QColor(self.palette().windowText().color()))
         painter = QtGui.QPainter(self)
         painter.fillRect(event.rect(), self._background_brush)
Example #11
0
 def paintEvent(self, event):
     """
     Pains the messages and the visible area on the panel.
     :param event: paint event infos
     """
     if self.isVisible():
         # fill background
         self._background_brush = QtGui.QBrush(self.editor.background)
         painter = QtGui.QPainter(self)
         painter.fillRect(event.rect(), self._background_brush)
         self._draw_messages(painter)
         self._draw_visible_area(painter)
Example #12
0
 def write_with_underline(text_edit, text, color, line, start, end):
     text_edit.moveCursor(QtGui.QTextCursor.End)
     text_edit.setTextColor(color)
     fmt = QtGui.QTextCharFormat()
     fmt.setUnderlineColor(color)
     fmt.setUnderlineStyle(QtGui.QTextCharFormat.SingleUnderline)
     fmt.setForeground(QtGui.QBrush(color))
     text_edit.setCurrentCharFormat(fmt)
     text_edit.insertPlainText(text)
     text_edit.moveCursor(QtGui.QTextCursor.End)
     block = self.document().lastBlock()
     data = self.UserData(text, line, start, end)
     block.setUserData(data)
Example #13
0
 def refresh(self):
     """
     Updates the current line decoration
     """
     if self.enabled and self.line:
         self._clear_deco()
         brush = QtGui.QBrush(self._color)
         self._decoration = TextDecoration(self.editor.textCursor(),
                                           start_line=self.line)
         self._decoration.set_background(brush)
         self._decoration.set_full_width()
         self._decoration.draw_order = 255
         self.editor.decorations.append(self._decoration)
Example #14
0
 def _on_results_available(self, results):
     if len(results) > 1:
         for start, end in results:
             deco = TextDecoration(self.editor.textCursor(),
                                   start_pos=start,
                                   end_pos=end)
             if self.underlined:
                 deco.set_as_underlined(self._background)
             else:
                 deco.set_background(QtGui.QBrush(self._background))
                 deco.set_foreground(self._foreground)
             deco.draw_order = 3
             self.editor.decorations.append(deco)
             self._decorations.append(deco)
 def refresh(self):
     """
     Updates the current line decoration
     """
     if self.enabled:
         self._clear_deco()
         if self._color:
             color = self._color
         else:
             color = drift_color(self.editor.background, 110)
         brush = QtGui.QBrush(color)
         self._decoration = TextDecoration(self.editor.textCursor())
         self._decoration.set_background(brush)
         self._decoration.set_full_width()
         self.editor.decorations.append(self._decoration)
Example #16
0
    def add_marker(self, marker):
        """
        Adds the marker to the panel.

        :param marker: Marker to add
        :type marker: pyqode.core.modes.Marker
        """
        self._markers.append(marker)
        doc = self.editor.document()
        assert isinstance(doc, QtGui.QTextDocument)
        block = doc.findBlockByLineNumber(marker._position)
        marker.block = block
        d = TextDecoration(block)
        d.set_full_width()
        if self._background:
            d.set_background(QtGui.QBrush(self._background))
            marker.decoration = d
        self.editor.decorations.append(d)
        self.repaint()
 def _on_results_available(self, results):
     if len(results) > 500:
         # limit number of results (on very big file where a lots of
         # occurrences can be found, this would totally freeze the editor
         # during a few seconds, with a limit of 500 we can make sure
         # the editor will always remain responsive).
         results = results[:500]
     if len(results) > 1:
         for start, end in results:
             deco = TextDecoration(self.editor.textCursor(),
                                   start_pos=start,
                                   end_pos=end)
             if self.underlined:
                 deco.set_as_underlined(self._background)
             else:
                 deco.set_background(QtGui.QBrush(self._background))
                 deco.set_foreground(self._foreground)
             deco.draw_order = 3
             self.editor.decorations.append(deco)
             self._decorations.append(deco)
Example #18
0
    def _draw_messages(self, painter):
        """
        Draw messages from all subclass of CheckerMode currently
        installed on the editor.

        :type painter: QtGui.QPainter
        """
        checker_modes = []
        for m in self.editor.modes:
            if isinstance(m, modes.CheckerMode):
                checker_modes.append(m)
        for checker_mode in checker_modes:
            for msg in checker_mode.messages:
                block = msg.block
                color = QtGui.QColor(msg.color)
                brush = QtGui.QBrush(color)
                rect = QtCore.QRect()
                rect.setX(self.sizeHint().width() / 4)
                rect.setY(block.blockNumber() * self.get_marker_height())
                rect.setSize(self.get_marker_size())
                painter.fillRect(rect, brush)
Example #19
0
 def _refresh_decorations(self):
     for deco in self._decorations:
         self.editor.decorations.remove(deco)
         deco.set_background(QtGui.QBrush(self.background))
         deco.set_outline(self._outline)
         self.editor.decorations.append(deco)