Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
    def _get_scope_highlight_color(self):
        """
        Gets the base scope highlight color (derivated from the editor
        background)

        For lighter themes will be a darker color, 
        and for darker ones will be a lighter color
        """
        color = self.editor.sideareas_color
        if color.lightness() < 128:
            color = drift_color(color, 130)
        else:
            color = drift_color(color, 105)
        return color
Ejemplo n.º 3
0
    def _get_scope_highlight_color(self):
        """
        Gets the base scope highlight color (derivated from the editor
        background)

        For lighter themes will be a darker color, 
        and for darker ones will be a lighter color
        """
        color = self.editor.sideareas_color
        if color.lightness() < 128:
            color = drift_color(color, 130)
        else:
            color = drift_color(color, 105)
        return color
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
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(QColor('#808080'))
     self._block_decos.append(deco)
     self.editor.decorations.append(deco)
Ejemplo n.º 6
0
 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.add(deco)
     self._prev_cursor = cursor
Ejemplo n.º 7
0
 def _add_fold_decoration(self, block, region):
     """
     Add fold decorations (boxes arround a folded block in the editor
     widget).
     """
     draw_order = DRAW_ORDERS.get('codefolding')
     deco = TextDecoration(block, draw_order=draw_order)
     deco.signals.clicked.connect(self._on_fold_deco_clicked)
     deco.tooltip = region.text(max_lines=25)
     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(QColor('#808080'))
     self._block_decos.append(deco)
     self.editor.decorations.add(deco)
Ejemplo n.º 8
0
 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