MCPcopy Index your code
hub / github.com/PyQt5/PyQt / JsonHighlighter

Class JsonHighlighter

Demo/TestSerializeModel.py:34–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32
33
34class JsonHighlighter(QSyntaxHighlighter):
35 def __init__(self, *args, **kwargs):
36 super().__init__(*args, **kwargs)
37 self._rules = [
38 # numbers
39 HighlightingRule(QRegExp('([-0-9.]+)(?!([^"]*"[\\s]*\\:))'), Qt.darkRed),
40 # key
41 HighlightingRule(QRegExp('("[^"]*")\\s*\\:'), Qt.darkBlue),
42 # value
43 HighlightingRule(QRegExp(':+(?:[: []*)("[^"]*")'), Qt.darkGreen),
44 ]
45
46 def highlightBlock(self, text: str) -> None:
47 for rule in self._rules:
48 index = rule.pattern.indexIn(text)
49 while index >= 0:
50 length = rule.pattern.matchedLength()
51 self.setFormat(index, length, rule.format)
52 index = rule.pattern.indexIn(text, index + length)
53
54
55class TestWindow(QWidget, Ui_SerializeWidget):

Callers 1

__init__Method · 0.70

Calls

no outgoing calls

Tested by 1

__init__Method · 0.56