Example #1
0
    def highlight_current_cell(self):
        """Highlight current cell"""
        if self.cell_separators is None or \
          not self.highlight_current_cell_enabled:
            return
        cursor, whole_file_selected, whole_screen_selected =\
            self.select_current_cell_in_visible_portion()
        selection = TextDecoration(cursor)
        selection.format.setProperty(QTextFormat.FullWidthSelection,
                                     to_qvariant(True))
        selection.format.setBackground(self.currentcell_color)

        if whole_file_selected:
            self.clear_extra_selections('current_cell')
        elif whole_screen_selected:
            has_cell_separators = False
            for oedata in self.outlineexplorer_data_list():
                if oedata.def_type == oedata.CELL:
                    has_cell_separators = True
                    break
            if has_cell_separators:
                self.set_extra_selections('current_cell', [selection])
                self.update_extra_selections()
            else:
                self.clear_extra_selections('current_cell')
        else:
            self.set_extra_selections('current_cell', [selection])
            self.update_extra_selections()
Example #2
0
    def highlight_current_cell(self):
        """Highlight current cell"""
        if (not self.has_cell_separators
                or not self.highlight_current_cell_enabled):
            self._current_cell_cursor = None
            return
        cursor, whole_file_selected = self.select_current_cell()

        def same_selection(c1, c2):
            if c1 is None or c2 is None:
                return False
            return (c1.selectionStart() == c2.selectionStart()
                    and c1.selectionEnd() == c2.selectionEnd())

        if same_selection(self._current_cell_cursor, cursor):
            # Already correct
            return
        self._current_cell_cursor = cursor
        selection = TextDecoration(cursor)
        selection.format.setProperty(QTextFormat.FullWidthSelection,
                                     to_qvariant(True))
        selection.format.setBackground(self.currentcell_color)

        if whole_file_selected:
            self.clear_extra_selections('current_cell')
        else:
            self.set_extra_selections('current_cell', [selection])
            self.update_extra_selections()
Example #3
0
 def highlight_current_line(self):
     """Highlight current line"""
     selection = TextDecoration(self.textCursor())
     selection.format.setProperty(QTextFormat.FullWidthSelection,
                                  to_qvariant(True))
     selection.format.setBackground(self.currentline_color)
     selection.cursor.clearSelection()
     self.set_extra_selections('current_line', [selection])
     self.update_extra_selections()
Example #4
0
    def highlight_current_cell(self):
        """Highlight current cell"""
        if (not self.has_cell_separators
                or not self.highlight_current_cell_enabled):
            return
        cursor, whole_file_selected = self.select_current_cell()
        selection = TextDecoration(cursor)
        selection.format.setProperty(QTextFormat.FullWidthSelection,
                                     to_qvariant(True))
        selection.format.setBackground(self.currentcell_color)

        if whole_file_selected:
            self.clear_extra_selections('current_cell')
        else:
            self.set_extra_selections('current_cell', [selection])
            self.update_extra_selections()
Example #5
0
 def __highlight(self, positions, color=None, cancel=False):
     if cancel:
         self.clear_extra_selections('brace_matching')
         return
     extra_selections = []
     for position in positions:
         if position > self.get_position('eof'):
             return
         selection = TextDecoration(self.textCursor())
         selection.format.setBackground(color)
         selection.cursor.clearSelection()
         selection.cursor.setPosition(position)
         selection.cursor.movePosition(QTextCursor.NextCharacter,
                                       QTextCursor.KeepAnchor)
         extra_selections.append(selection)
     self.set_extra_selections('brace_matching', extra_selections)
     self.update_extra_selections()
Example #6
0
    def _decorate_block(self, start, end):
        """
        Create a decoration and add it to the editor.

        Args:
            start (int) start line of the decoration
            end (int) end line of the decoration
        """
        color = self._get_scope_highlight_color()
        draw_order = DRAW_ORDERS.get('codefolding')
        d = TextDecoration(self.editor.document(), start_line=max(0, start - 1),
                           end_line=end, draw_order=draw_order)
        d.set_background(color)
        d.set_full_width(True, clear=False)
        self.editor.decorations.add(d)
        self._scope_decos.append(d)
Example #7
0
 def _add_fold_decoration(self, block, end_line):
     """
     Add fold decorations (boxes arround a folded block in the editor
     widget).
     """
     start_line = block.blockNumber()
     text = self.editor.get_text_region(start_line + 1, end_line)
     draw_order = DRAW_ORDERS.get('codefolding')
     deco = TextDecoration(block, draw_order=draw_order)
     deco.signals.clicked.connect(self._on_fold_deco_clicked)
     deco.tooltip = text
     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[start_line] = deco
     self.editor.decorations.add(deco)
Example #8
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)