コード例 #1
0
    def _add_table(self, tab, cursor):
        fmt = QTextCharFormat()
        fmt.setFont(QFont(self.factory.font_name))
        fmt.setFontPointSize(self.factory.font_size)
        bc = QColor(self.factory.bg_color) if self.factory.bg_color else None
        ec, oc, hc = bc, bc, bc
        if self.factory.even_color:
            ec = QColor(self.factory.even_color)
        if self.factory.odd_color:
            oc = QColor(self.factory.odd_color)
        if self.factory.header_color:
            hc = QColor(self.factory.header_color)

        with edit_block(cursor):
            for i, row in enumerate(tab.items):
                cell = row.cells[0]
                if cell.bold:
                    fmt.setFontWeight(QFont.Bold)
                else:
                    fmt.setFontWeight(QFont.Normal)

                if i == 0 and hc:
                    c = hc
                elif (i - 1) % 2 == 0:
                    c = ec
                else:
                    c = oc

                if c:
                    fmt.setBackground(c)

                txt = ''.join([u'{{:<{}s}}'.format(cell.width).format(cell.text)
                              for cell in row.cells
                              ])
                cursor.insertText(txt + '\n', fmt)
コード例 #2
0
ファイル: syntaxhlighter.py プロジェクト: uchuugaka/editor
    def formatConverterFunction(format):
        if format == qutepart.syntax.TextFormat():
            return None  # Do not apply default format. Performance optimization

        qtFormat = QTextCharFormat()
        qtFormat.setForeground(QBrush(QColor(format.color)))
        qtFormat.setBackground(QBrush(QColor(format.background)))
        qtFormat.setFontItalic(format.italic)
        qtFormat.setFontWeight(QFont.Bold if format.bold else QFont.Normal)
        qtFormat.setFontUnderline(format.underline)
        qtFormat.setFontStrikeOut(format.strikeOut)

        return qtFormat
コード例 #3
0
ファイル: syntaxhlighter.py プロジェクト: Darriall/editor
    def formatConverterFunction(format):
        if format == qutepart.syntax.TextFormat():
            return None  # Do not apply default format. Performance optimization
        
        qtFormat = QTextCharFormat()
        qtFormat.setForeground(QBrush(QColor(format.color)))
        qtFormat.setBackground(QBrush(QColor(format.background)))
        qtFormat.setFontItalic(format.italic)
        qtFormat.setFontWeight(QFont.Bold if format.bold else QFont.Normal)
        qtFormat.setFontUnderline(format.underline)
        qtFormat.setFontStrikeOut(format.strikeOut)

        return qtFormat
コード例 #4
0
    def _add_table(self, tab, cursor):
        fmt = QTextCharFormat()
        fmt.setFont(QFont(self.factory.font_name))
        fmt.setFontPointSize(self.factory.font_size)
        bc = QColor(self.factory.bg_color) if self.factory.bg_color else None
        ec, oc, hc = bc, bc, bc
        if self.factory.even_color:
            ec = QColor(self.factory.even_color)
        if self.factory.odd_color:
            oc = QColor(self.factory.odd_color)
        if self.factory.header_color:
            hc = QColor(self.factory.header_color)

        with edit_block(cursor):
            for i, row in enumerate(tab.items):
                cell = row.cells[0]
                if cell.bold:
                    fmt.setFontWeight(QFont.Bold)
                else:
                    fmt.setFontWeight(QFont.Normal)

                if i == 0 and hc:
                    c = hc
                elif (i - 1) % 2 == 0:
                    c = ec
                else:
                    c = oc

                if c:
                    fmt.setBackground(c)

                txt = ''.join([
                    u'{{:<{}s}}'.format(cell.width).format(cell.text)
                    for cell in row.cells
                ])
                cursor.insertText(txt + '\n', fmt)
コード例 #5
0
ファイル: lang.py プロジェクト: MasouShizuka/VNR-Core
  def __init__(self, parent=None):
    """
    @param  parent  QObject or QTextDocument or QTextEdit or None
    """
    super(PyHighlighter, self).__init__(parent)

    keywordFormat = QTextCharFormat()
    keywordFormat.setForeground(HLS_KEYWORD_COLOR)
    keywordFormat.setFontWeight(QFont.Bold)
    self.highlightingRules = [(QRegExp(pattern), keywordFormat)
        for pattern in self.KEYWORD_PATTERNS]

    typeFormat = QTextCharFormat()
    typeFormat.setForeground(HLS_TYPE_COLOR)
    typeFormat.setFontWeight(QFont.Bold)
    self.highlightingRules.extend([(QRegExp(pattern), typeFormat)
        for pattern in self.TYPE_PATTERNS])

    constantFormat = QTextCharFormat()
    constantFormat.setForeground(HLS_LITERAL_COLOR)
    self.highlightingRules.extend([(QRegExp(pattern), constantFormat)
        for pattern in self.CONSTANT_PATTERNS])

    classFormat = QTextCharFormat()
    classFormat.setFontWeight(QFont.Bold)
    classFormat.setForeground(HLS_CLASS_COLOR)
    self.highlightingRules.append((QRegExp(r"\bQ[A-Za-z]+\b"),
        classFormat))

    functionFormat = QTextCharFormat()
    functionFormat.setFontItalic(True)
    functionFormat.setForeground(HLS_FUNCTION_COLOR)
    self.highlightingRules.append((QRegExp(r"\b[A-Za-z0-9_]+(?=\()"),
        functionFormat))

    quotationFormat = QTextCharFormat()
    quotationFormat.setForeground(HLS_LITERAL_COLOR)
    self.highlightingRules.append((QRegExp(r'"[^"]*"'), quotationFormat))
    self.highlightingRules.append((QRegExp(r'u"[^"]*"'), quotationFormat))
    self.highlightingRules.append((QRegExp(r"'[^']*'"), quotationFormat))
    self.highlightingRules.append((QRegExp(r"u'[^']*'"), quotationFormat))

    singleLineCommentFormat = QTextCharFormat()
    singleLineCommentFormat.setForeground(HLS_COMMENT_COLOR)
    self.highlightingRules.append((QRegExp("#[^\n]*"), singleLineCommentFormat))

    self.multiLineCommentFormat = QTextCharFormat()
    self.multiLineCommentFormat.setForeground(HLS_COMMENT_COLOR)

    self.commentStartExpression = QRegExp(r'"""')
    self.commentEndExpression = QRegExp(r'"""')

    todoFormat = QTextCharFormat()
    todoFormat.setBackground(HLS_TODO_COLOR)
    self.postHighlightingRules = [(QRegExp(pattern), todoFormat)
        for pattern in HLS_TODO_PATTERNS]

    doxyFormat = QTextCharFormat()
    doxyFormat.setForeground(HLS_COMMENT_COLOR)
    doxyFormat.setFontWeight(QFont.Bold)
    self.postHighlightingRules.extend([(QRegExp(pattern), doxyFormat)
        for pattern in HLS_DOXY_PATTERNS])