def __init__(self, document): QSyntaxHighlighter.__init__(self, document) self.clb = ConfigurationLineBuilder(ErtKeywords()) self.comment_format = QTextCharFormat() self.comment_format.setForeground(QColor(0, 128, 0)) self.comment_format.setFontItalic(True) self.keyword_format = QTextCharFormat() self.keyword_format.setForeground(QColor(200, 100, 0)) # self.keyword_format.setFontWeight(QFont.Bold) self.error_format = QTextCharFormat() # self.error_format.setForeground(QColor(255, 0, 0)) self.error_format.setUnderlineStyle(QTextCharFormat.WaveUnderline) self.error_format.setUnderlineColor(QColor(255, 0, 0)) self.search_format = QTextCharFormat() self.search_format.setBackground(QColor(220, 220, 220)) self.builtin_format = QTextCharFormat() self.builtin_format.setForeground(QColor(0, 170, 227)) self.search_string = ""
def __init__(self, *args): keywords = r"\bimport\b|\bas\b|\bfor\b|\bdef\b|\bpass\b" keywords += r"|\bclass\b|\bfrom\b|\bif\b|\bthen\b|\belse\b" keywords += r"|\belif\b|\btry\b|\bexcept\b|\bfinally\b|\braise\b" keywords += r"|\bprint\b|\bin\b|\bnot\b|\band\b|\bor\b|\bcontinue\b" keywords += r"|\bwhile\b|\breturn\b|\blambda\b|\bwith\b|\del\b" keywords += r"|\bglobal\b|\byield\b|\bexec\b|\bassert\b|\break\b" constants = r"\bNone\b|\bTrue\b|\bFalse\b|\bself\b" autovars = r"\bNODE\b|\bNAME\b|\bVALUE\b|\bSIDSTYPE\b|\bCHILDREN\b" autovars += r"|\bTREE\b|\bPATH\b|\bRESULT\b|\bARGS\b|\bPARENT\b" autovars += r"|\bLINKS\b|\bSKIPS\b" numbers = r'[-+]?\d+' + '|[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?' comment = r'\#.*$' textstring = r'"[^"]*?"|\'[^\']*?\'' self.f_keywords = QTextCharFormat() self.f_keywords.setFontWeight(QFont.Bold) self.f_keywords.setForeground(QColor('Blue')) self.f_comment = QTextCharFormat() self.f_comment.setFontWeight(QFont.Light) self.f_comment.setForeground(QColor('Red')) self.f_constants = QTextCharFormat() self.f_constants.setFontWeight(QFont.Light) self.f_constants.setForeground(QColor('Navy')) self.f_autovars = QTextCharFormat() self.f_autovars.setFontWeight(QFont.Bold) self.f_autovars.setForeground(QColor('Green')) self.f_textstring = QTextCharFormat() self.f_textstring.setFontWeight(QFont.Bold) self.f_textstring.setForeground(QColor('Coral')) self.f_numbers = QTextCharFormat() self.f_numbers.setFontWeight(QFont.Light) self.f_numbers.setForeground(QColor('Gray')) self.r_keywords = re.compile(keywords) self.r_numbers = re.compile(numbers) self.r_comment = re.compile(comment) self.r_constants = re.compile(constants) self.r_autovars = re.compile(autovars) self.r_textstring = re.compile(textstring) self.in_comment = False self.in_string = False self.r_syntax = [] self.r_syntax.append((self.r_keywords, self.f_keywords)) self.r_syntax.append((self.r_numbers, self.f_numbers)) self.r_syntax.append((self.r_autovars, self.f_autovars)) self.r_syntax.append((self.r_constants, self.f_constants)) self.r_syntax.append((self.r_comment, self.f_comment)) self.r_syntax.append((self.r_textstring, self.f_textstring)) QSyntaxHighlighter.__init__(self, *args)
def __init__(self, document): QSyntaxHighlighter.__init__(self, document) # Multi-line strings (expression, flag, style) # FIXME: The triple-quotes in these two lines will mess up the # syntax highlighting from this point onward self.tri_single = (QRegExp("'''"), 1, STYLES['string2']) self.tri_double = (QRegExp('"""'), 2, STYLES['string2']) rules = [] # Keyword, operator, and brace rules rules += [(r'\b%s\b' % w, 0, STYLES['keyword']) for w in PythonHighlighter.keywords] rules += [(r'%s' % o, 0, STYLES['operator']) for o in PythonHighlighter.operators] rules += [(r'%s' % b, 0, STYLES['brace']) for b in PythonHighlighter.braces] # All other rules rules += [ # 'self' (r'\bself\b', 0, STYLES['self']), # Double-quoted string, possibly containing escape sequences (r'"[^"\\]*(\\.[^"\\]*)*"', 0, STYLES['string']), # Single-quoted string, possibly containing escape sequences (r"'[^'\\]*(\\.[^'\\]*)*'", 0, STYLES['string']), # 'def' followed by an identifier (r'\bdef\b\s*(\w+)', 1, STYLES['defclass']), # 'class' followed by an identifier (r'\bclass\b\s*(\w+)', 1, STYLES['defclass']), # From '#' until a newline (r'#[^\n]*', 0, STYLES['comment']), # Numeric literals (r'\b[+-]?[0-9]+[lL]?\b', 0, STYLES['numbers']), (r'\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b', 0, STYLES['numbers']), (r'\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b', 0, STYLES['numbers']), ] # Build a QRegExp for each pattern self.rules = [(QRegExp(pat), index, fmt) for (pat, index, fmt) in rules]
def __init__(self, doc, spellcheck_widget): QSyntaxHighlighter.__init__(self, doc) self.spellcheck = spellcheck_widget self.enabled = False
def __init__(self, doc, spellcheck): QSyntaxHighlighter.__init__(self, doc) self.spellcheck = spellcheck self.enabled = False
def rehighlight(self): QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) QSyntaxHighlighter.rehighlight(self) QApplication.restoreOverrideCursor()