Beispiel #1
0
 def paintEvent(self, event):
     # Paints the line numbers
     self._line_color_u = drift_color(self._background_brush.color(), 250)
     self._line_color_s = drift_color(self._background_brush.color(), 280)
     Panel.paintEvent(self, event)
     if self.isVisible():
         painter = QtGui.QPainter(self)
         # get style options (font, size)
         width = self.width()
         height = self.editor.fontMetrics().height()
         font = self.editor.font()
         bold_font = self.editor.font()
         bold_font.setBold(True)
         pen = QtGui.QPen(self._line_color_u)
         pen_selected = QtGui.QPen(self._line_color_s)
         painter.setFont(font)
         # get selection range
         sel_start, sel_end = TextHelper(self.editor).selection_range()
         has_sel = sel_start != sel_end
         cl = TextHelper(self.editor).current_line_nbr()
         # draw every visible blocks
         for top, line, block in self.editor.visible_blocks:
             if ((has_sel and sel_start <= line <= sel_end)
                     or (not has_sel and cl == line)):
                 painter.setPen(pen_selected)
                 painter.setFont(bold_font)
             else:
                 painter.setPen(pen)
                 painter.setFont(font)
             painter.drawText(-3, top, width, height, QtCore.Qt.AlignRight,
                              str(line + 1))
Beispiel #2
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()))
Beispiel #3
0
    def _draw_rect(self, rect, painter):
        """
        Draw the background rectangle using the current style primitive color
        or foldIndicatorBackground if nativeFoldingIndicator is true.

        :param rect: The fold zone rect to draw

        :param painter: The widget's painter.
        """
        c = self._custom_color
        if self._native:
            c = self.get_system_bck_color()
        grad = QtGui.QLinearGradient(rect.topLeft(), rect.topRight())
        if sys.platform == 'darwin':
            grad.setColorAt(0, c.lighter(100))
            grad.setColorAt(1, c.lighter(110))
            outline = c.darker(110)
        else:
            grad.setColorAt(0, c.lighter(110))
            grad.setColorAt(1, c.lighter(130))
            outline = c.darker(100)
        painter.fillRect(rect, grad)
        painter.setPen(QtGui.QPen(outline))
        painter.drawLine(rect.topLeft() + QtCore.QPointF(1, 0),
                         rect.topRight() - QtCore.QPointF(1, 0))
        painter.drawLine(rect.bottomLeft() + QtCore.QPointF(1, 0),
                         rect.bottomRight() - QtCore.QPointF(1, 0))
        painter.drawLine(rect.topRight() + QtCore.QPointF(0, 1),
                         rect.bottomRight() - QtCore.QPointF(0, 1))
        painter.drawLine(rect.topLeft() + QtCore.QPointF(0, 1),
                         rect.bottomLeft() - QtCore.QPointF(0, 1))
Beispiel #4
0
    def set_outline(self, color):
        """
        Uses an outline rectangle.

        :param color: Color of the outline rect
        :type color: QtGui.QColor
        """
        self.format.setProperty(QtGui.QTextFormat.OutlinePen,
                                QtGui.QPen(color))
Beispiel #5
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)
Beispiel #6
0
 def color(self, value):
     self._color = value
     self._pen = QtGui.QPen(self._color)
     TextHelper(self.editor).mark_whole_doc_dirty()
     self.editor.repaint()
     if self.editor:
         for clone in self.editor.clones:
             try:
                 clone.modes.get(self.__class__).color = value
             except KeyError:
                 # this should never happen since we're working with clones
                 pass
Beispiel #7
0
 def _init_style(self):
     self._bg = QtGui.QColor('yellow')
     self._outline = QtGui.QPen(QtGui.QColor('gray'), 1)
Beispiel #8
0
 def __init__(self):
     Mode.__init__(self)
     self._margin_pos = 79
     self._color = QtGui.QColor('red')
     self._pen = QtGui.QPen(self._color)
 def __init__(self):
     super(MarginsMode, self).__init__()
     self._positions = [7, 11, 72, 79]
     self._colors = [QtGui.QColor('red') for _ in range(4)]
     self._pens = [QtGui.QPen(c) for c in self._colors]