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))
 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 #3
0
def test_drift_color():
    assert utils.drift_color(QtGui.QColor("#FFFFFF")).name() == \
           QtGui.QColor("#e8e8e8").name()

    assert utils.drift_color(QtGui.QColor("#202020")).name() == \
           QtGui.QColor("#262626").name()

    assert utils.drift_color(QtGui.QColor("#000000")).name() == \
           QtGui.QColor("#161616").name()
Beispiel #4
0
def test_drift_color():
    assert utils.drift_color(QtGui.QColor("#FFFFFF")).name() == \
           QtGui.QColor("#e8e8e8").name()

    assert utils.drift_color(QtGui.QColor("#202020")).name() == \
           QtGui.QColor("#262626").name()

    assert utils.drift_color(QtGui.QColor("#000000")).name() == \
           QtGui.QColor("#161616").name()
Beispiel #5
0
 def __init__(self, parent):
     super(DockManager, self).__init__(parent)
     self.setStyleSheet(self.qss)
     self.setMovable(False)
     self.setFloatable(False)
     self.color = drift_color(self.palette().window().color(), 120)
     self.color_hover = drift_color(self.palette().window().color(), 110)
     self.setStyleSheet(self.qss %
                        (self.color.name(), self.color_hover.name()))
    def _get_scope_highlight_color(self):
        """
        Gets the base scope highlight color (derivated from the editor
        background)

        """
        color = self.editor.background
        if color.lightness() < 128:
            color = drift_color(color, 130)
        else:
            color = drift_color(color, 105)
        return color
 def _get_format_from_style(self, token, style):
     """ Returns a QTextCharFormat for token by reading a Pygments style.
     """
     result = QtGui.QTextCharFormat()
     items = list(style.style_for_token(token).items())
     for key, value in items:
         if value is None and key == 'color':
             # make sure to use a default visible color for the foreground
             # brush
             value = drift_color(self.background, 1000).name()
         if value:
             if key == 'color':
                 result.setForeground(self._get_brush(value))
             elif key == 'bgcolor':
                 result.setBackground(self._get_brush(value))
             elif key == 'bold':
                 result.setFontWeight(QtGui.QFont.Bold)
             elif key == 'italic':
                 result.setFontItalic(value)
             elif key == 'underline':
                 result.setUnderlineStyle(
                     QtGui.QTextCharFormat.SingleUnderline)
             elif key == 'sans':
                 result.setFontStyleHint(QtGui.QFont.SansSerif)
             elif key == 'roman':
                 result.setFontStyleHint(QtGui.QFont.Times)
             elif key == 'mono':
                 result.setFontStyleHint(QtGui.QFont.TypeWriter)
     if token in [
             Token.Literal.String, Token.Literal.String.Doc, Token.Comment
     ]:
         # mark strings, comments and docstrings regions for further queries
         result.setObjectType(result.UserObject)
     return result
 def _get_format_from_style(self, token, style):
     """ Returns a QTextCharFormat for token by reading a Pygments style.
     """
     result = QtGui.QTextCharFormat()
     items = list(style.style_for_token(token).items())
     for key, value in items:
         if value is None and key == 'color':
             # make sure to use a default visible color for the foreground
             # brush
             value = drift_color(self.background, 1000).name()
         if value:
             if key == 'color':
                 result.setForeground(self._get_brush(value))
             elif key == 'bgcolor':
                 result.setBackground(self._get_brush(value))
             elif key == 'bold':
                 result.setFontWeight(QtGui.QFont.Bold)
             elif key == 'italic':
                 result.setFontItalic(value)
             elif key == 'underline':
                 result.setUnderlineStyle(
                     QtGui.QTextCharFormat.SingleUnderline)
             elif key == 'sans':
                 result.setFontStyleHint(QtGui.QFont.SansSerif)
             elif key == 'roman':
                 result.setFontStyleHint(QtGui.QFont.Times)
             elif key == 'mono':
                 result.setFontStyleHint(QtGui.QFont.TypeWriter)
     if token in [Token.Literal.String, Token.Literal.String.Doc,
                  Token.Comment]:
         # mark strings, comments and docstrings regions for further queries
         result.setObjectType(result.UserObject)
     return result
 def _add_scope_deco(self, start, end, parent_start, parent_end, base_color,
                     factor):
     """
     Adds a scope decoration that enclose the current scope
     :param start: Start of the current scope
     :param end: End of the current scope
     :param parent_start: Start of the parent scope
     :param parent_end: End of the parent scope
     :param base_color: base color for scope decoration
     :param factor: color factor to apply on the base color (to make it
         darker).
     """
     color = drift_color(base_color, factor=factor)
     # upper part
     if start > 0:
         d = TextDecoration(self.editor.document(),
                            start_line=parent_start, end_line=start)
         d.set_full_width(True, clear=False)
         d.draw_order = 2
         d.set_background(color)
         self.editor.decorations.append(d)
         self._scope_decos.append(d)
     # lower part
     if end <= self.editor.document().blockCount():
         d = TextDecoration(self.editor.document(),
                            start_line=end, end_line=parent_end + 1)
         d.set_full_width(True, clear=False)
         d.draw_order = 2
         d.set_background(color)
         self.editor.decorations.append(d)
         self._scope_decos.append(d)
 def _reset_stylesheet(self):
     highlight = drift_color(self.editor.palette().window().color())
     stylesheet = self.STYLESHEET % {
         "tooltip": self.editor.palette().toolTipBase().color().name(),
         "bck": self.editor.palette().window().color().name(),
         "color": self.editor.palette().windowText().color().name(),
         "highlight": highlight.name()}
     self.setStyleSheet(stylesheet)
 def background(self):
     """
     Background color of the caret line. Default is to use a color slightly
     darker/lighter than the background color. You can override the
     automatic color by setting up this property
     """
     if self._color or not self.editor:
         return self._color
     else:
         return drift_color(self.editor.background, 110)
 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)
Beispiel #13
0
 def _add_fold_decoration(self, block, region):
     """
     Add fold decorations (boxes arround a folded block in the editor
     widget).
     """
     deco = TextDecoration(block)
     deco.signals.clicked.connect(self._on_fold_deco_clicked)
     deco.tooltip = region.text(max_lines=25)
     deco.draw_order = 1
     deco.block = block
     deco.select_line()
     deco.set_outline(drift_color(self._get_scope_highlight_color(), 110))
     deco.set_background(self._get_scope_highlight_color())
     deco.set_foreground(QtGui.QColor('#808080'))
     self._block_decos.append(deco)
     self.editor.decorations.append(deco)
Beispiel #14
0
 def _add_fold_decoration(self, block, region):
     """
     Add fold decorations (boxes arround a folded block in the editor
     widget).
     """
     deco = TextDecoration(block)
     deco.signals.clicked.connect(self._on_fold_deco_clicked)
     deco.tooltip = region.text(max_lines=25)
     deco.draw_order = 1
     deco.block = block
     deco.select_line()
     deco.set_outline(drift_color(
         self._get_scope_highlight_color(), 110))
     deco.set_background(self._get_scope_highlight_color())
     deco.set_foreground(QtGui.QColor('#808080'))
     self._block_decos.append(deco)
     self.editor.decorations.append(deco)
    def refresh_decorations(self, force=False):
        """
        Refresh decorations colors. This function is called by the syntax
        highlighter when the style changed so that we may update our
        decorations colors according to the new style.

        """
        cursor = self.editor.textCursor()
        if (self._prev_cursor is None or force or
                self._prev_cursor.blockNumber() != cursor.blockNumber()):
            for deco in self._block_decos:
                self.editor.decorations.remove(deco)
            for deco in self._block_decos:
                deco.set_outline(drift_color(
                    self._get_scope_highlight_color(), 110))
                deco.set_background(self._get_scope_highlight_color())
                self.editor.decorations.append(deco)
        self._prev_cursor = cursor