Example #1
0
def load_style(style):
    styles = {}
    formatter = Formatter(style=style)

    for token, params in formatter.style:
        color = parse_hex_color(params["color"]) if params["color"] else None

        # Save style
        styles[token] = {"color": color}

    return styles
Example #2
0
def load_style(style):
    styles = {}
    formatter = Formatter(style=style)

    for token, params in formatter.style:
        color = parse_hex_color(params["color"]) if params["color"] else None
        # Italic and underline styles aren't supported, so just use bold for them
        bold = params["bold"] or params["italic"] or params["underline"]

        # Save style
        styles[token] = {"color": color, "bold": bold}

    return styles
Example #3
0
    def __init__(self, parent):
        QSyntaxHighlighter.__init__(self, parent)

        self.formatter = Formatter()
        self.lexer = PythonLexer()
        self.style = {}
        for token, style in self.formatter.style:
            char_format = QTextCharFormat()
            if style['color']:
                char_format.setForeground(QColor("#" + style['color']))
            if style['bgcolor']:
                char_format.setBackground(QColor("#" + style['bgcolor']))
            if style['bold']:
                char_format.setFontWeight(QFont.Bold)
            if style['italic']:
                char_format.setFontItalic(True)
            if style['underline']:
                char_format.setFontUnderline(True)

            char_format.setFontStyleHint(QFont.Monospace)
            self.style[token] = char_format