pycrossword  0.2
Pure-Python implementation of a crossword puzzle generator and editor
Public Member Functions | Public Attributes | Static Public Attributes | Private Attributes | List of all members
pycross.utils.utils.JsonHiliter Class Reference

Syntax highlighter class for JSON. More...

Inheritance diagram for pycross.utils.utils.JsonHiliter:

Public Member Functions

def __init__ (self, QtGui.QTextDocument parent, decode_errors=False, on_decode_error=None, on_decode_success=None)
 
def highlightBlock (self, text)
 

Public Attributes

 decode_errors
 bool whether JSON decode errors must be highlighted dynamically More...
 
 decoder
 

Static Public Attributes

list PATTERNS
 Regex-based patterns and their corresponding color values. More...
 
 sig_parse_error = QtCore.pyqtSignal(QtGui.QSyntaxHighlighter, str, str, int, int, int)
 
 sig_parse_success = QtCore.pyqtSignal(QtGui.QSyntaxHighlighter)
 

Private Attributes

 _error_format
 

Detailed Description

Syntax highlighter class for JSON.

Used in pycross::forms::WordSrcDialog (DB table definition).

See also
QSyntaxHighlighter docs

Constructor & Destructor Documentation

◆ __init__()

def pycross.utils.utils.JsonHiliter.__init__ (   self,
QtGui.QTextDocument  parent,
  decode_errors = False,
  on_decode_error = None,
  on_decode_success = None 
)

Member Function Documentation

◆ highlightBlock()

def pycross.utils.utils.JsonHiliter.highlightBlock (   self,
  text 
)

Member Data Documentation

◆ _error_format

pycross.utils.utils.JsonHiliter._error_format
private

◆ decode_errors

pycross.utils.utils.JsonHiliter.decode_errors

bool whether JSON decode errors must be highlighted dynamically

◆ decoder

pycross.utils.utils.JsonHiliter.decoder

◆ PATTERNS

list pycross.utils.utils.JsonHiliter.PATTERNS
static
Initial value:
= [
# operators (dot, comma, colon)
(re.compile(r'([\.,\:])'), 1, QtGui.QColor(QtCore.Qt.red)),
# brackets
(re.compile(r'([\{\}\[\]\(\)])'), 1, QtGui.QColor(QtCore.Qt.gray)),
# numbers
(re.compile(r'([\s,\:\{\[\(])([\-\+]?[\d\.]+)([\s,\:\}\]\)]?)'), 2, QtGui.QColor(QtCore.Qt.blue)),
(re.compile(r'([\s,\:\{\[\(])([\-\+]?[\d\.]+$)'), 2, QtGui.QColor(QtCore.Qt.blue)),
(re.compile(r'(^[\-\+]?[\d\.]+)([\s,\:\}\]\)]?)'), 1, QtGui.QColor(QtCore.Qt.blue)),
(re.compile(r'(^[\-\+]?[\d\.]+$)'), 1, QtGui.QColor(QtCore.Qt.blue)),
# boolean
(re.compile(r'([\s,\:\{\[\(])(true|false)([\s,\:\}\]\)])'), 2, QtGui.QColor(QtCore.Qt.magenta)),
(re.compile(r'([\s,\:\{\[\(])(true$|false$)'), 2, QtGui.QColor(QtCore.Qt.magenta)),
(re.compile(r'(^true|^false)([\s,\:\}\]\)])'), 1, QtGui.QColor(QtCore.Qt.magenta)),
(re.compile(r'(^true$|^false$)'), 1, QtGui.QColor(QtCore.Qt.magenta)),
# null values
(re.compile(r'([\s,\:\{\[\(])(null)([\s,\:\}\]\)])'), 2, QtGui.QColor(QtCore.Qt.gray)),
(re.compile(r'([\s,\:\{\[\(])(null$)'), 2, QtGui.QColor(QtCore.Qt.gray)),
(re.compile(r'(^null)([\s,\:\}\]\)])'), 1, QtGui.QColor(QtCore.Qt.gray)),
(re.compile(r'(^null$)'), 1, QtGui.QColor(QtCore.Qt.gray)),
# string values
(re.compile(r'([\s,\:\[\(])(\".*?\")'), 2, QtGui.QColor(QtCore.Qt.darkCyan)),
(re.compile(r'(^\".*?\")'), 1, QtGui.QColor(QtCore.Qt.darkCyan)),
# key names
(re.compile(r'(\".*?\")(\s*\:)'), 1, QtGui.QColor(QtCore.Qt.darkGreen))
]

Regex-based patterns and their corresponding color values.

Each record has 3 elements:

  1. Python regex object compiled regex pattern
  2. int group number in regex match results to highlight (0 = whole match, 1 = first expression in parentheses, etc...)
  3. QtGui.QColor color to apply to matched text

◆ sig_parse_error

pycross.utils.utils.JsonHiliter.sig_parse_error = QtCore.pyqtSignal(QtGui.QSyntaxHighlighter, str, str, int, int, int)
static

◆ sig_parse_success

pycross.utils.utils.JsonHiliter.sig_parse_success = QtCore.pyqtSignal(QtGui.QSyntaxHighlighter)
static

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