src/eric7/EricGui/EricGenericDiffHighlighter.py

branch
eric7
changeset 10922
36a90a94765c
parent 10458
2074b8393649
child 11090
f5f5f5803935
equal deleted inserted replaced
10921:495f084a737e 10922:36a90a94765c
8 """ 8 """
9 9
10 import re 10 import re
11 11
12 from PyQt6.QtGui import QFont, QSyntaxHighlighter, QTextCharFormat 12 from PyQt6.QtGui import QFont, QSyntaxHighlighter, QTextCharFormat
13
14 from eric7 import Preferences
15 13
16 14
17 def TERMINAL(pattern): 15 def TERMINAL(pattern):
18 """ 16 """
19 Function to mark a pattern as the final one to search for. 17 Function to mark a pattern as the final one to search for.
41 39
42 @param doc reference to the text document 40 @param doc reference to the text document
43 @type QTextDocument 41 @type QTextDocument
44 """ 42 """
45 super().__init__(doc) 43 super().__init__(doc)
46
47 self.regenerateRules()
48
49 def __initColours(self):
50 """
51 Private method to initialize the highlighter colours.
52 """
53 self.textColor = Preferences.getDiffColour("TextColor")
54 self.addedColor = Preferences.getDiffColour("AddedColor")
55 self.removedColor = Preferences.getDiffColour("RemovedColor")
56 self.replacedColor = Preferences.getDiffColour("ReplacedColor")
57 self.contextColor = Preferences.getDiffColour("ContextColor")
58 self.headerColor = Preferences.getDiffColour("HeaderColor")
59 self.whitespaceColor = Preferences.getDiffColour("BadWhitespaceColor")
60 44
61 def createRules(self, *rules): 45 def createRules(self, *rules):
62 """ 46 """
63 Public method to create the highlighting rules. 47 Public method to create the highlighting rules.
64 48
110 @param bold flag indicating bold text 94 @param bold flag indicating bold text
111 @type bool 95 @type bool
112 @return format definiton 96 @return format definiton
113 @rtype QTextCharFormat 97 @rtype QTextCharFormat
114 """ 98 """
115 font = Preferences.getEditorOtherFonts("MonospacedFont") 99 font = QFont(self.baseFont)
116 charFormat = QTextCharFormat() 100 charFormat = QTextCharFormat()
117 charFormat.setFontFamilies([font.family()]) 101 charFormat.setFontFamilies([font.family()])
118 charFormat.setFontPointSize(font.pointSize()) 102 charFormat.setFontPointSize(font.pointSize())
119 103
120 if fg: 104 if fg:
161 length = len(group) 145 length = len(group)
162 if formatStr[groupIndex]: 146 if formatStr[groupIndex]:
163 self.setFormat(start, start + length, formatStr[groupIndex]) 147 self.setFormat(start, start + length, formatStr[groupIndex])
164 start += length 148 start += length
165 149
166 def regenerateRules(self): 150 def regenerateRules(self, colors, font):
167 """ 151 """
168 Public method to initialize or regenerate the syntax highlighter rules. 152 Public method to initialize or regenerate the syntax highlighter rules.
153
154 @param colors dictionary containing the different color values (keys are
155 "text", "added", "removed","replaced", "context", "header", "whitespace")
156 @type dict[str: QColor]
157 @param font font
158 @type QFont
169 """ 159 """
160 self.baseFont = font
170 self.normalFormat = self.makeFormat() 161 self.normalFormat = self.makeFormat()
171 162
172 self.__initColours() 163 self.textColor = colors["text"]
164 self.addedColor = colors["added"]
165 self.removedColor = colors["removed"]
166 self.replacedColor = colors["replaced"]
167 self.contextColor = colors["context"]
168 self.headerColor = colors["header"]
169 self.whitespaceColor = colors["whitespace"]
173 170
174 self._rules = [] 171 self._rules = []
175 self.generateRules() 172 self.generateRules()
176 173
177 def generateRules(self): 174 def generateRules(self):

eric ide

mercurial