Пример #1
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)
Пример #2
0
def test_formats(editor):
    deco = TextDecoration(editor.textCursor(), start_line=10, end_line=15)
    deco.set_foreground(QtGui.QColor('#FF0000'))
    deco.set_outline(QtGui.QColor('#FF0000'))
    deco.set_as_spell_check(QtGui.QColor('#FF0000'))
    deco.set_as_error(QtGui.QColor('#FF0000'))
    deco.set_as_error()
    deco.set_as_warning()
Пример #3
0
def test_add_decoration(editor):
    helper = TextHelper(editor)
    helper.goto_line(2, 2)
    cursor = helper.word_under_cursor(select_whole_word=True)
    deco = TextDecoration(cursor)
    deco.set_as_bold()
    deco.set_as_underlined(QtGui.QColor("#FF0000"))
    editor.decorations.append(deco)
    assert not editor.decorations.append(deco)
    assert deco.contains_cursor(cursor)
    # keep editor clean for next tests
    editor.decorations.clear()
Пример #4
0
def test_clear_decoration(editor):
    # should work even when there are no more decorations
    helper = TextHelper(editor)
    editor.decorations.clear()
    cursor = helper.word_under_cursor(select_whole_word=True)
    deco = TextDecoration(cursor)
    deco.set_as_bold()
    deco.set_as_underlined(QtGui.QColor("#FF0000"))
    editor.decorations.append(deco)
    assert not editor.decorations.append(deco)
    editor.decorations.clear()
    assert editor.decorations.append(deco)
    assert editor.decorations.remove(deco)
Пример #5
0
def test_remove_decoration(editor):
    helper = TextHelper(editor)
    TextHelper(editor).goto_line(1, 2)
    cursor = helper.word_under_cursor(select_whole_word=True)
    deco = TextDecoration(cursor)
    deco.set_as_bold()
    deco.set_as_underlined(QtGui.QColor("#FF0000"))
    editor.decorations.append(deco)
    assert editor.decorations.remove(deco)
    # already removed, return False
    assert not editor.decorations.remove(deco)
    assert editor.decorations.append(deco)
    # keep editor clean for next tests
    editor.decorations.clear()
Пример #6
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)
Пример #7
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)
Пример #8
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()
Пример #9
0
 def select_word(self, cursor):
     symbol = cursor.selectedText()
     analyser = self.editor.outline_mode
     for definition in analyser.definitions:
         node = self.find_definition(symbol, definition)
         if node is not None:
             break
     else:
         node = None
     self._definition = None
     if node and node.line != cursor.block().blockNumber():
         self._definition = node
         if self._deco is None:
             if cursor.selectedText():
                 self._deco = TextDecoration(cursor)
                 self._deco.set_foreground(Qt.blue)
                 self._deco.set_as_underlined()
                 self.editor.decorations.append(self._deco)
                 return True
     return False
Пример #10
0
 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)
Пример #11
0
def test_constructors(editor):
    deco = TextDecoration(editor.textCursor(), start_pos=10, end_pos=15)
    deco = TextDecoration(editor.textCursor(), start_line=10, end_line=15)