当前位置: 首页>>代码示例>>Python>>正文


Python QtGui.QSyntaxHighlighter类代码示例

本文整理汇总了Python中PyQt4.QtGui.QSyntaxHighlighter的典型用法代码示例。如果您正苦于以下问题:Python QSyntaxHighlighter类的具体用法?Python QSyntaxHighlighter怎么用?Python QSyntaxHighlighter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了QSyntaxHighlighter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

	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) )
开发者ID:marad,项目名称:deadline-framework,代码行数:30,代码来源:widgets.py

示例2: __init__

    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)
开发者ID:olivierdalang,项目名称:stdm,代码行数:25,代码来源:highlighter.py

示例3: __init__

    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]
开发者ID:calpe20,项目名称:PYTHONIZANDO,代码行数:60,代码来源:highlighter.py

示例4: __init__

    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 = ""
开发者ID:berland,项目名称:ert,代码行数:26,代码来源:highlighter.py

示例5: __init__

    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]
开发者ID:robertbasic,项目名称:ape,代码行数:27,代码来源:syntaxer.py

示例6: __init__

    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]
开发者ID:rfwebster,项目名称:Newt,代码行数:35,代码来源:syntax.py

示例7: __init__

    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]
开发者ID:DoctorMalboro,项目名称:prymatex,代码行数:32,代码来源:syntax.py

示例8: __init__

 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)
开发者ID:b250783,项目名称:ninja-ide,代码行数:7,代码来源:highlighter.py

示例9: __init__

 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()
开发者ID:StanAngeloff,项目名称:git-cola,代码行数:7,代码来源:qt.py

示例10: __init__

    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]
开发者ID:TheTaz,项目名称:RK_TK_PythonEditor,代码行数:34,代码来源:highlight.py

示例11: __init__

    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)
开发者ID:AutumnLight,项目名称:orange,代码行数:26,代码来源:OWPythonScript.py

示例12: __init__

 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)
开发者ID:mbsrz1972,项目名称:frescobaldi,代码行数:8,代码来源:highlighter.py

示例13: __init__

 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()
开发者ID:brownian,项目名称:frescobaldi,代码行数:8,代码来源:highlighter.py

示例14: __init__

 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)
开发者ID:netantho,项目名称:ninja-ide,代码行数:9,代码来源:highlighter.py

示例15: __init__

 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)
开发者ID:benosment,项目名称:regex-tool-pyqt4,代码行数:10,代码来源:regexhighlighter.py


注:本文中的PyQt4.QtGui.QSyntaxHighlighter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。