本文整理汇总了Python中PyQt4.QtGui.QSyntaxHighlighter.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python QSyntaxHighlighter.__init__方法的具体用法?Python QSyntaxHighlighter.__init__怎么用?Python QSyntaxHighlighter.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QSyntaxHighlighter
的用法示例。
在下文中一共展示了QSyntaxHighlighter.__init__方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from PyQt4.QtGui import QSyntaxHighlighter [as 别名]
# 或者: from PyQt4.QtGui.QSyntaxHighlighter import __init__ [as 别名]
def __init__(self, parent = None, theme = None, prefix = ''):
QSyntaxHighlighter.__init__(self, parent)
self.rules = []
self.prefix = prefix
kwFormat = QTextCharFormat()
kwFormat.setForeground( Qt.blue )
#kwFormat.setFontWeight( QFont.Bold )
quoteFormat = QTextCharFormat()
quoteFormat.setForeground( Qt.red )
commentFormat = QTextCharFormat()
commentFormat.setForeground( Qt.darkGray )
keywords = ["and", "del", "for", "is", "raise",
"assert", "elif", "from", "lambda",
"break", "else", "global", "not", "try",
"class", "except", "if", "or", "while",
"continue", "exec", "import", "pass", "yield",
"def", "finally", "in", "print", "self"
]
for kw in keywords:
self.rules.append( (QRegExp("\\b" + kw + "\\b"), kwFormat) )
self.rules.append( (QRegExp(r'"(?:[^"\\]|\\.)*"'), quoteFormat) )
self.rules.append( (QRegExp(r"'(?:[^\']+|\.)*'"), quoteFormat) )
self.rules.append( (QRegExp(r"#.*$"), commentFormat) )
示例2: __init__
# 需要导入模块: from PyQt4.QtGui import QSyntaxHighlighter [as 别名]
# 或者: from PyQt4.QtGui.QSyntaxHighlighter import __init__ [as 别名]
def __init__(self, parent=None):
QSyntaxHighlighter.__init__(self, parent)
self.parent = parent
sqlKeyword = QTextCharFormat()
sqlOperator = QTextCharFormat()
self.highlightingRules = []
# Keywords
sqlKeyword.setFontWeight(QFont.Bold)
sqlKeyword.setForeground(Qt.blue)
sqlKeywords = ["AND", "OR", "LIKE"]
for word in sqlKeywords:
regExp = QRegExp("\\b" + word + "\\b", Qt.CaseInsensitive)
rule = HighlightingRule(regExp, sqlKeyword)
self.highlightingRules.append(rule)
# Comparison Operators
sqlOperator.setForeground(Qt.magenta)
sqlOperators = ["<", ">", "="]
for operator in sqlOperators:
regExp = QRegExp("\\W" + operator + "\\W", Qt.CaseInsensitive)
rule = HighlightingRule(regExp, sqlOperator)
self.highlightingRules.append(rule)
示例3: __init__
# 需要导入模块: from PyQt4.QtGui import QSyntaxHighlighter [as 别名]
# 或者: from PyQt4.QtGui.QSyntaxHighlighter import __init__ [as 别名]
def __init__(self, document, lang):
QSyntaxHighlighter.__init__(self, document)
langSyntax = loader.syntax[lang]
Highlighter.keywords = langSyntax.get('keywords', [])
Highlighter.braces = langSyntax.get('brace', [])
Highlighter.operators = langSyntax.get('operators', [])
rules = []
# Keyword, operator, and brace rules
rules += [(r'\b%s\b' % w, 0, STYLES['keyword'])
for w in Highlighter.keywords]
rules += [(r'%s' % o, 0, STYLES['operator'])
for o in Highlighter.operators]
rules += [(r'%s' % b, 0, STYLES['brace'])
for b in Highlighter.braces]
# All other rules
proper = langSyntax.get('properObject', None)
if proper is not None:
proper = '\\b' + str(proper[0]) + '\\b'
rules += [
# 'self'
(proper, 0, STYLES['properObject'])]
rules.append((r'__\w+__', 0, STYLES['properObject']))
definition = langSyntax.get('definition', [])
for de in definition:
expr = '\\b' + de + '\\b\\s*(\\w+)'
rules.append((expr, 1, STYLES['definition']))
rules += [
# 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']),
]
stringChar = langSyntax.get('string', [])
for sc in stringChar:
expr = r'"[^"\\]*(\\.[^"\\]*)*"' if sc == '"' else r"'[^'\\]*(\\.[^'\\]*)*'"
rules.append((expr, 0, STYLES['string']))
# 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']) #"""
comments = langSyntax.get('comment', [])
for co in comments:
expr = co + '[^\\n]*'
rules.append((expr, 0, STYLES['comment']))
rules.append(('\s+', 0, STYLES['spaces']))
# Build a QRegExp for each pattern
self.rules = [(QRegExp(pat), index, fmt)
for (pat, index, fmt) in rules]
示例4: __init__
# 需要导入模块: from PyQt4.QtGui import QSyntaxHighlighter [as 别名]
# 或者: from PyQt4.QtGui.QSyntaxHighlighter import __init__ [as 别名]
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 = ""
示例5: __init__
# 需要导入模块: from PyQt4.QtGui import QSyntaxHighlighter [as 别名]
# 或者: from PyQt4.QtGui.QSyntaxHighlighter import __init__ [as 别名]
def __init__(self, document):
QSyntaxHighlighter.__init__(self, document)
rules = []
rules += [(r'%s' % p, 0, 'phpBlock')
for p in self.phpBlock]
rules += [(r'%s' % k, 0, 'keywords')
for k in self.keywords]
rules += [(r'%s' % f, 0, 'functions')
for f in self.functions]
# $variables
rules += [(r'\$[\w]*', 0, 'variables')]
# comments
rules += [(r'#[^\n]*', 0, 'comments')]
rules += [(r'//[^\n]*', 0, 'comments')]
rules += [(r'/\*+.*\*+/', 0, 'comments')]
# strings
rules += [(r'".*"', 0, 'strings')]
rules += [(r"'.*'", 0, 'strings')]
self.rules = [(QRegExp(pat), index, format)
for(pat, index, format) in rules]
示例6: __init__
# 需要导入模块: from PyQt4.QtGui import QSyntaxHighlighter [as 别名]
# 或者: from PyQt4.QtGui.QSyntaxHighlighter import __init__ [as 别名]
def __init__(self, document):
QSyntaxHighlighter.__init__(self, document)
rules = []
# LaTeX in-line math brace
rules += [(r'%s' % b, 0, STYLES['brace'])
for b in LaTeXHighlighter.braces]
# LaTeX in-line math brace
rules += [(r'%s' % mb, 0, STYLES['mathbrace'])
for mb in LaTeXHighlighter.mathbrace]
# All other rules
rules += [
# \ "something" ends with { or [ or white space - for environments and others
# e.g. \begin{}, \something[]{} \texbf etc
(r'[\\](?:(?![ \{ | \[ | \s ]).)*', 0, STYLES['environment']),
(r'\\end', 0, STYLES['environment']),
# LaTeX in-line math braces
(r'\\\[', 0, STYLES['mathbrace']),
(r'\\\]', 0, STYLES['mathbrace']),
(r'\\\(', 0, STYLES['mathbrace']),
(r'\\\)', 0, STYLES['mathbrace']),
# From '%' until a newline - Commment
(r'\%[^\n]*', 0, STYLES['comment']),
]
# Build a QRegExp for each pattern
self.rules = [(QRegExp(pat), index, fmt)
for (pat, index, fmt) in rules]
示例7: __init__
# 需要导入模块: from PyQt4.QtGui import QSyntaxHighlighter [as 别名]
# 或者: from PyQt4.QtGui.QSyntaxHighlighter import __init__ [as 别名]
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 = []
rules += [(r'\b%s\b' % w, 0, STYLES['keyword'])
for w in Python.keywords]
rules += [(r'%s' % o, 0, STYLES['operator'])
for o in Python.operators]
rules += [(r'%s' % b, 0, STYLES['brace'])
for b in Python.braces]
rules += [
# 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']),
]
# Build a QRegExp for each pattern
self.rules = [(QRegExp(pat), index, fmt)
for (pat, index, fmt) in rules]
示例8: __init__
# 需要导入模块: from PyQt4.QtGui import QSyntaxHighlighter [as 别名]
# 或者: from PyQt4.QtGui.QSyntaxHighlighter import __init__ [as 别名]
def __init__(self, document, lang=None, scheme=None,
errors=None, pep8=None):
QSyntaxHighlighter.__init__(self, document)
self.errors = errors
self.pep8 = pep8
if lang is not None:
self.apply_highlight(lang, scheme)
示例9: __init__
# 需要导入模块: from PyQt4.QtGui import QSyntaxHighlighter [as 别名]
# 或者: from PyQt4.QtGui.QSyntaxHighlighter import __init__ [as 别名]
def __init__(self, doc, *args, **kwargs):
QSyntaxHighlighter.__init__(self, doc)
for attr, val in default_colors.items():
setattr(self, attr, val)
self._rules = []
self.enabled = True
self.generate_rules()
示例10: __init__
# 需要导入模块: from PyQt4.QtGui import QSyntaxHighlighter [as 别名]
# 或者: from PyQt4.QtGui.QSyntaxHighlighter import __init__ [as 别名]
def __init__(self, document):
QSyntaxHighlighter.__init__(self, document)
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]
rules += [
(r'\bself\b', 0, STYLES['self']),
(r'"[^"\\]*(\\.[^"\\]*)*"', 0, STYLES['string']),
(r"'[^'\\]*(\\.[^'\\]*)*'", 0, STYLES['string']),
(r'\bdef\b\s*(\w+)', 1, STYLES['defclass']),
(r'\bclass\b\s*(\w+)', 1, STYLES['defclass']),
(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']),
]
self.rules = [(QRegExp(pat), index, fmt)
for (pat, index, fmt) in rules]
示例11: __init__
# 需要导入模块: from PyQt4.QtGui import QSyntaxHighlighter [as 别名]
# 或者: from PyQt4.QtGui.QSyntaxHighlighter import __init__ [as 别名]
def __init__(self, parent=None):
self.keywordFormat = text_format(Qt.blue, QFont.Bold)
self.stringFormat = text_format(Qt.darkGreen)
self.defFormat = text_format(Qt.black, QFont.Bold)
self.commentFormat = text_format(Qt.lightGray)
self.decoratorFormat = text_format(Qt.darkGray)
self.keywords = list(keyword.kwlist)
self.rules = [(QRegExp(r"\b%s\b" % kwd), self.keywordFormat)
for kwd in self.keywords] + \
[(QRegExp(r"\bdef\s+([A-Za-z_]+[A-Za-z0-9_]+)\s*\("),
self.defFormat),
(QRegExp(r"\bclass\s+([A-Za-z_]+[A-Za-z0-9_]+)\s*\("),
self.defFormat),
(QRegExp(r"'.*'"), self.stringFormat),
(QRegExp(r'".*"'), self.stringFormat),
(QRegExp(r"#.*"), self.commentFormat),
(QRegExp(r"@[A-Za-z_]+[A-Za-z0-9_]+"),
self.decoratorFormat)]
self.multilineStart = QRegExp(r"(''')|" + r'(""")')
self.multilineEnd = QRegExp(r"(''')|" + r'(""")')
QSyntaxHighlighter.__init__(self, parent)
示例12: __init__
# 需要导入模块: from PyQt4.QtGui import QSyntaxHighlighter [as 别名]
# 或者: from PyQt4.QtGui.QSyntaxHighlighter import __init__ [as 别名]
def __init__(self, document):
QSyntaxHighlighter.__init__(self, document)
self._fridge = ly.lex.Fridge()
app.settingsChanged.connect(self.rehighlight)
self._highlighting = metainfo.info(document).highlighting
document.loaded.connect(self._resetHighlighting)
self._mode = documentinfo.mode(document, False)
variables.manager(document).changed.connect(self._variablesChange)
示例13: __init__
# 需要导入模块: from PyQt4.QtGui import QSyntaxHighlighter [as 别名]
# 或者: from PyQt4.QtGui.QSyntaxHighlighter import __init__ [as 别名]
def __init__(self, document):
QSyntaxHighlighter.__init__(self, document)
self._fridge = ly.lex.Fridge()
app.settingsChanged.connect(self.rehighlight)
self._initialState = None
self._highlighting = True
self._mode = None
self.initializeDocument()
示例14: __init__
# 需要导入模块: from PyQt4.QtGui import QSyntaxHighlighter [as 别名]
# 或者: from PyQt4.QtGui.QSyntaxHighlighter import __init__ [as 别名]
def __init__(self, document, lang=None, scheme=None, errors=None, pep8=None):
QSyntaxHighlighter.__init__(self, document)
self.highlight_function = self.realtime_highlight
self.errors = errors
self.pep8 = pep8
self.selected_word_lines = []
self.visible_limits = (0, 50)
if lang is not None:
self.apply_highlight(lang, scheme)
示例15: __init__
# 需要导入模块: from PyQt4.QtGui import QSyntaxHighlighter [as 别名]
# 或者: from PyQt4.QtGui.QSyntaxHighlighter import __init__ [as 别名]
def __init__(self, widget):
QSyntaxHighlighter.__init__(self, widget)
self.regex = None
# create format type
self.odd_format = QTextCharFormat()
self.odd_format.setFontWeight(QFont.Bold)
self.odd_format.setForeground(Qt.darkBlue)
self.even_format = QTextCharFormat()
self.even_format.setFontWeight(QFont.Bold)
self.even_format.setForeground(Qt.darkMagenta)