Krita Source Code Documentation
Loading...
Searching...
No Matches
krita.sceditor.highlighter.PythonHighlighter Class Reference
+ Inheritance diagram for krita.sceditor.highlighter.PythonHighlighter:

Public Member Functions

 __init__ (self, edit)
 
 highlightBlock (self, text)
 
 highlightRules (self, text, start, finish)
 
 updateFonts (self, font)
 
 updateHighlighter (self, font)
 
 updateRules (self)
 

Public Attributes

 base_format
 
 callableFormat
 
 document
 
 empty_format
 
 keywordFormat
 
 keywords
 
 magicFormat
 
 multiLineStringBegin
 
 multiLineStringEnd
 
 multiLineStringFormat
 
 qtFormat
 
 quotationFormat1
 
 quotationFormat2
 
 rules
 
 selfFormat
 
 singleLineCommentFormat
 

Static Public Attributes

tuple keywords
 

Detailed Description

Definition at line 18 of file highlighter.py.

Constructor & Destructor Documentation

◆ __init__()

krita.sceditor.highlighter.PythonHighlighter.__init__ ( self,
edit )

Reimplemented in krita.sceditor.highlighter.QtQmlHighlighter.

Definition at line 29 of file highlighter.py.

29 def __init__(self, edit):
30 document = edit.document()
31 QtGui.QSyntaxHighlighter.__init__(self, document)
32
33 base_format = QtGui.QTextCharFormat()
34 base_format.setFont(edit.font())
35
36 self.base_format = base_format
37 self.document = document
38
39 self.updateHighlighter(base_format.font())
40

Member Function Documentation

◆ highlightBlock()

krita.sceditor.highlighter.PythonHighlighter.highlightBlock ( self,
text )

Definition at line 41 of file highlighter.py.

41 def highlightBlock(self, text):
42
43 self.setCurrentBlockState(0)
44
45 if text.trimmed().isEmpty():
46 self.setFormat(0, len(text), self.empty_format)
47 return
48
49 self.setFormat(0, len(text), self.base_format)
50
51 startIndex = 0
52 if self.previousBlockState() != 1:
53 startIndex = self.multiLineStringBegin.indexIn(text)
54
55 if startIndex > -1:
56 self.highlightRules(text, 0, startIndex)
57 else:
58 self.highlightRules(text, 0, len(text))
59
60 while startIndex >= 0:
61
62 endIndex = self.multiLineStringEnd.indexIn(text,
63 startIndex + len(self.multiLineStringBegin.pattern()))
64 if endIndex == -1:
65 self.setCurrentBlockState(1)
66 commentLength = text.length() - startIndex
67 else:
68 commentLength = endIndex - startIndex + \
69 self.multiLineStringEnd.matchedLength()
70 self.highlightRules(text, endIndex, len(text))
71
72 self.setFormat(startIndex, commentLength, self.multiLineStringFormat)
73 startIndex = self.multiLineStringBegin.indexIn(text,
74 startIndex + commentLength)
75

References KisPipeBrushParasite.dim, KisSpinBoxUnitManager.dim, FlattenSpec.dim, and xcfLayer.dim.

◆ highlightRules()

krita.sceditor.highlighter.PythonHighlighter.highlightRules ( self,
text,
start,
finish )

Definition at line 76 of file highlighter.py.

76 def highlightRules(self, text, start, finish):
77
78 for expression, format in self.rules:
79
80 index = expression.indexIn(text, start)
81 while index >= start and index < finish:
82 length = expression.matchedLength()
83 self.setFormat(index, min(length, finish - index), format)
84 index = expression.indexIn(text, index + length)
85

References krita.sceditor.highlighter.PythonHighlighter.rules, krita.sceditor.highlighter.QtQmlHighlighter.rules, scripter.ui_scripter.syntax.syntax.PythonHighlighter.rules, KisCompositeProgressProxy.setFormat(), KisNodeProgressProxy.setFormat(), KoFakeProgressProxy.setFormat(), KoProgressBar.setFormat(), KoUpdater.setFormat(), KoProgressProxy.setFormat(), and RecorderConfig.setFormat().

◆ updateFonts()

krita.sceditor.highlighter.PythonHighlighter.updateFonts ( self,
font )

Definition at line 86 of file highlighter.py.

86 def updateFonts(self, font):
87
88 self.base_format.setFont(font)
89 self.empty_format = QtGui.QTextCharFormat(self.base_format)
90 # self.empty_format.setFontPointSize(font.pointSize()/4.0)
91
92 self.keywordFormat = QtGui.QTextCharFormat(self.base_format)
93 self.keywordFormat.setForeground(QtCore.Qt.GlobalColor.darkBlue)
94 self.keywordFormat.setFontWeight(QtGui.QFont.Weight.Bold)
95 self.callableFormat = QtGui.QTextCharFormat(self.base_format)
96 self.callableFormat.setForeground(QtCore.Qt.GlobalColor.darkBlue)
97 self.magicFormat = QtGui.QTextCharFormat(self.base_format)
98 self.magicFormat.setForeground(QtGui.QColor(224, 128, 0))
99 self.qtFormat = QtGui.QTextCharFormat(self.base_format)
100 self.qtFormat.setForeground(QtCore.Qt.GlobalColor.blue)
101 self.qtFormat.setFontWeight(QtGui.QFont.Weight.Bold)
102 self.selfFormat = QtGui.QTextCharFormat(self.base_format)
103 self.selfFormat.setForeground(QtCore.Qt.GlobalColor.red)
104 # self.selfFormat.setFontItalic(True)
105 self.singleLineCommentFormat = QtGui.QTextCharFormat(self.base_format)
106 self.singleLineCommentFormat.setForeground(QtCore.Qt.GlobalColor.darkGreen)
107 self.multiLineStringFormat = QtGui.QTextCharFormat(self.base_format)
108 self.multiLineStringFormat.setBackground(
109 QtGui.QBrush(QtGui.QColor(127, 127, 255)))
110 self.quotationFormat1 = QtGui.QTextCharFormat(self.base_format)
111 self.quotationFormat1.setForeground(QtCore.Qt.GlobalColor.blue)
112 self.quotationFormat2 = QtGui.QTextCharFormat(self.base_format)
113 self.quotationFormat2.setForeground(QtCore.Qt.GlobalColor.blue)
114

References krita.sceditor.highlighter.PythonHighlighter.base_format, and krita.sceditor.highlighter.PythonHighlighter.empty_format.

◆ updateHighlighter()

◆ updateRules()

krita.sceditor.highlighter.PythonHighlighter.updateRules ( self)

Reimplemented in krita.sceditor.highlighter.QtQmlHighlighter.

Definition at line 115 of file highlighter.py.

115 def updateRules(self):
116
117 self.rules = []
118 self.rules += map(lambda s: (QtCore.QRegularExpression(r"\b" + s + r"\b"),
119 self.keywordFormat), self.keywords)
120
121 self.rules.append((QtCore.QRegularExpression(r"\b[A-Za-z_]+\‍(.*\‍)"), self.callableFormat))
122 self.rules.append((QtCore.QRegularExpression(r"\b__[a-z]+__\b"), self.magicFormat))
123 self.rules.append((QtCore.QRegularExpression(r"\bself\b"), self.selfFormat))
124 self.rules.append((QtCore.QRegularExpression(r"\bQ([A-Z][a-z]*)+\b"), self.qtFormat))
125
126 self.rules.append((QtCore.QRegularExpression(r"#[^\n]*"), self.singleLineCommentFormat))
127
128 self.multiLineStringBegin = QtCore.QRegularExpression(r'\"\"\"')
129 self.multiLineStringEnd = QtCore.QRegularExpression(r'\"\"\"')
130
131 self.rules.append((QtCore.QRegularExpression(r'\"[^\n]*\"'), self.quotationFormat1))
132 self.rules.append((QtCore.QRegularExpression(r"'[^\n]*'"), self.quotationFormat2))
133

Member Data Documentation

◆ base_format

krita.sceditor.highlighter.PythonHighlighter.base_format

Definition at line 36 of file highlighter.py.

◆ callableFormat

krita.sceditor.highlighter.PythonHighlighter.callableFormat

Definition at line 95 of file highlighter.py.

◆ document

krita.sceditor.highlighter.PythonHighlighter.document

Definition at line 37 of file highlighter.py.

◆ empty_format

krita.sceditor.highlighter.PythonHighlighter.empty_format

Definition at line 46 of file highlighter.py.

◆ keywordFormat

krita.sceditor.highlighter.PythonHighlighter.keywordFormat

Definition at line 92 of file highlighter.py.

◆ keywords [1/2]

tuple krita.sceditor.highlighter.PythonHighlighter.keywords
static
Initial value:
= (
"and", "del", "for", "is", "raise",
"assert", "elif", "from", "lambda", "return",
"break", "else", "global", "not", "try",
"class", "except", "if", "or", "while",
"continue", "exec", "import", "pass", "yield",
"def", "finally", "in", "print"
)

Definition at line 20 of file highlighter.py.

◆ keywords [2/2]

krita.sceditor.highlighter.PythonHighlighter.keywords

Definition at line 119 of file highlighter.py.

◆ magicFormat

krita.sceditor.highlighter.PythonHighlighter.magicFormat

Definition at line 97 of file highlighter.py.

◆ multiLineStringBegin

krita.sceditor.highlighter.PythonHighlighter.multiLineStringBegin

Definition at line 128 of file highlighter.py.

◆ multiLineStringEnd

krita.sceditor.highlighter.PythonHighlighter.multiLineStringEnd

Definition at line 129 of file highlighter.py.

◆ multiLineStringFormat

krita.sceditor.highlighter.PythonHighlighter.multiLineStringFormat

Definition at line 72 of file highlighter.py.

◆ qtFormat

krita.sceditor.highlighter.PythonHighlighter.qtFormat

Definition at line 99 of file highlighter.py.

◆ quotationFormat1

krita.sceditor.highlighter.PythonHighlighter.quotationFormat1

Definition at line 110 of file highlighter.py.

◆ quotationFormat2

krita.sceditor.highlighter.PythonHighlighter.quotationFormat2

Definition at line 112 of file highlighter.py.

◆ rules

krita.sceditor.highlighter.PythonHighlighter.rules

Definition at line 117 of file highlighter.py.

◆ selfFormat

krita.sceditor.highlighter.PythonHighlighter.selfFormat

Definition at line 102 of file highlighter.py.

◆ singleLineCommentFormat

krita.sceditor.highlighter.PythonHighlighter.singleLineCommentFormat

Definition at line 105 of file highlighter.py.


The documentation for this class was generated from the following file: