示例#1
0
def get_syntax_format(color=None, style=''):
    """
    Returns a QTextCharFormat with the given attributes.
    """

    _color = None

    if type(color) == str:
        _color = QColor()
        _color.setNamedColor(color)
    if type(color) == list:
        _color = QColor(*color)

    if color == 'green':
        _color = Qt.green

    _format = QTextCharFormat()

    if _color:
        _format.setForeground(_color)
    if 'bold' in style:
        _format.setFontWeight(QFont.Bold)
    if 'italic' in style:
        _format.setFontItalic(True)

    return _format
示例#2
0
    def get_style(self, color, bold=False):
        brush = QBrush(QColor(*color))
        f = QTextCharFormat()
        if bold:
            f.setFontWeight(QFont.Bold)
        f.setForeground(brush)

        return f
示例#3
0
def format(color, style=''):
    """Return a QTextCharFormat with the given attributes.
    """
    _color = QColor()
    _color.setNamedColor(color)

    _format = QTextCharFormat()
    _format.setForeground(_color)
    if 'bold' in style:
        _format.setFontWeight(QFont.Bold)
    if 'italic' in style:
        _format.setFontItalic(True)

    return _format
示例#4
0
    def lookup(self, key):
        """Return a QTextCharFormat with the given attributes.
        """
        color, style = self.styles[key]

        _color = QColor()
        _color.setNamedColor(color)

        _format = QTextCharFormat()
        _format.setForeground(_color)
        if style:
            if 'bold' in style:
                _format.setFontWeight(QFont.Bold)
            if 'italic' in style:
                _format.setFontItalic(True)

        return _format
示例#5
0
    def _keywordFormat(self):
        '''set up keyword format'''
        # mel keyword
        melKeywords = [
            'false', 'float', 'int', 'matrix', 'off', 'on', 'string', 'true',
            'vector', 'yes', 'alias', 'case', 'catch', 'break', 'case',
            'continue', 'default', 'do', 'else', 'for', 'if', 'in', 'while',
            'alias', 'case', 'catch', 'global', 'proc', 'return', 'source',
            'switch'
        ]
        # python keyword
        pyKeywords = keyword.kwlist + ['False', 'True', 'None']

        keywords = {}.fromkeys(melKeywords)
        keywords.update({}.fromkeys(pyKeywords))
        # keyword format
        keywordFormat = QTextCharFormat()
        keywordFormat.setForeground(self._keywordColor)
        keywordFormat.setFontWeight(QFont.Bold)
        kwtext = '\\b(' + "|".join(keywords) + ')\\b'
        self.__rules.append((re.compile(kwtext), keywordFormat))
示例#6
0
    def initialize(self):

        # numeric color
        self._numericFormat.setForeground(QColor('#9ACD32'))

        # mel command options started with -
        melOpsFormat = QTextCharFormat()
        melOpsFormat.setForeground(QColor('#B8860B'))
        self.__rules.append((re.compile('-[a-zA-Z]+\\b'), melOpsFormat))

        # keywords color
        self._keywordColor = QColor(0, 128, 255)

        self._numeric()
        self._keywordFormat()
        self._cmdsFunctionFormat()

        # maya api format
        mapiFormat = QTextCharFormat()
        mapiFormat.setForeground(self._keywordColor)
        self.__rules.append((re.compile('\\bM\\w+\\b'), mapiFormat))
        # Qt
        self.__rules.append((re.compile('\\bQ\\w+\\b'), mapiFormat))

        # quotation
        self._quotationFormat.setForeground(Qt.green)
        # quote: ""
        self.__rules.append((re.compile('".*"'), self._quotationFormat))
        # single quotes for python: ''
        self.__rules.append((re.compile("'.*'"), self._quotationFormat))

        # sing line comment
        # orange red
        self._commentFormat.setForeground(QColor(255, 128, 64))
        # // mel comment
        self.__rules.append((re.compile('//[^\n]*'), self._commentFormat))
        # # python comment
        self.__rules.append((re.compile('#[^\n]*'), self._commentFormat))

        # function and class format
        funcFormat = QTextCharFormat()
        funcFormat.setFontWeight(QFont.Bold)
        self.__rules.append((re.compile('\\b(\\w+)\(.*\):'), funcFormat))

        # mel warning
        warningFormat = QTextCharFormat()
        warningFormat.setForeground(QColor('#FF9ACD32'))
        warningFormat.setBackground(Qt.yellow)
        warningFormat.setFontWeight(QFont.Bold)
        self.__rules.append((re.compile('// Warning:[^\n]*//'), warningFormat))

        # mel error
        errorFormat = QTextCharFormat()
        errorFormat.setForeground(QColor('#FF9ACD32'))
        errorFormat.setBackground(Qt.red)
        errorFormat.setFontWeight(QFont.Bold)
        self.__rules.append((re.compile('// Error:[^\n]*//'), errorFormat))

        self.setDocument(self.parent.document())
示例#7
0
import re
from Qt.QtCore import Qt
from Qt.QtGui import QSyntaxHighlighter, QTextCharFormat, QFont

COMMENT_RE = re.compile(r"/\*.+\*/")
COMMENT_FORMAT = QTextCharFormat()
COMMENT_FORMAT.setFontItalic(True)
COMMENT_FORMAT.setForeground(Qt.darkGray)

JINJA_RE = re.compile(r"{{.+}}")
JINJA_FORMAT = QTextCharFormat()
JINJA_FORMAT.setFontWeight(QFont.Bold)
JINJA_FORMAT.setForeground(Qt.darkMagenta)

QCLASS_RE = re.compile(r"Q[\w]+")
QCLASS_FORMAT = QTextCharFormat()
QCLASS_FORMAT.setFontWeight(QFont.Bold)
QCLASS_FORMAT.setForeground(Qt.darkGreen)

QSUBELEMENT_RE = re.compile(r"::([\w-]+)")
QSUBELEMENT_FORMAT = QTextCharFormat()
QSUBELEMENT_FORMAT.setFontWeight(QFont.Bold)
QSUBELEMENT_FORMAT.setForeground(Qt.darkBlue)

PROPERTY_RE = re.compile(r"\[[^=]+=[^\]]+]")
PROPERTY_FORMAT = QTextCharFormat()
PROPERTY_FORMAT.setFontItalic(True)
PROPERTY_FORMAT.setForeground(Qt.darkGreen)


class TemplateHighlighter(QSyntaxHighlighter):
示例#8
0
import re
from Qt.QtCore import Qt
from Qt.QtGui import QSyntaxHighlighter, QTextCharFormat, QFont


LINE_FILE_RE = re.compile(r"^\s\s\S.+")
LINE_FILE_FORMAT = QTextCharFormat()
LINE_FILE_FORMAT.setForeground(Qt.lightGray)

LINE_CODE_RE = re.compile(r"^\s\s\s\s\S.+")
LINE_CODE_FORMAT = QTextCharFormat()
LINE_CODE_FORMAT.setFontWeight(QFont.Bold)

FILE_RE = re.compile(r"\"[^\"]+\"")
FILE_FORMAT = QTextCharFormat()
FILE_FORMAT.setFontItalic(True)
FILE_FORMAT.setForeground(Qt.black)

CALL_RE = re.compile(r", in ([^$]+)$")
CALL_FORMAT = QTextCharFormat()
CALL_FORMAT.setFontWeight(QFont.Bold)
CALL_FORMAT.setForeground(Qt.magenta)

LINE_RE = re.compile(r"line \d+")
LINE_FORMAT = QTextCharFormat()
LINE_FORMAT.setForeground(Qt.green)


class TracebackHighlighter(QSyntaxHighlighter):
    RULES = {
        LINE_FILE_RE: LINE_FILE_FORMAT,