-
Notifications
You must be signed in to change notification settings - Fork 27
/
decorations.py
65 lines (53 loc) · 1.72 KB
/
decorations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""
Contains the text decorations manager
"""
import logging
from pyqode.core.api.manager import Manager
def _logger():
return logging.getLogger(__name__)
class TextDecorationsManager(Manager):
"""
Manages the collection of TextDecoration that have been set on the editor
widget.
"""
def __init__(self, editor):
super(TextDecorationsManager, self).__init__(editor)
self._decorations = []
def append(self, decoration):
"""
Adds a text decoration on a CodeEdit instance
:param decoration: Text decoration to add
:type decoration: pyqode.core.api.TextDecoration
"""
if decoration not in self._decorations:
self._decorations.append(decoration)
self._decorations = sorted(
self._decorations, key=lambda sel: sel.draw_order)
self.editor.setExtraSelections(self._decorations)
return True
return False
def remove(self, decoration):
"""
Removes a text decoration from the editor.
:param decoration: Text decoration to remove
:type decoration: pyqode.core.api.TextDecoration
"""
try:
self._decorations.remove(decoration)
self.editor.setExtraSelections(self._decorations)
return True
except ValueError:
return False
def clear(self):
"""
Removes all text decoration from the editor.
"""
self._decorations[:] = []
try:
self.editor.setExtraSelections(self._decorations)
except RuntimeError:
pass
def __iter__(self):
return iter(self._decorations)
def __len__(self):
return len(self._decorations)