def update_char_format( baseformat: QTextCharFormat, color: Optional[_Color] = None, background: Optional[_Color] = None, weight: Optional[int] = None, italic: Optional[bool] = None, underline: Optional[bool] = None, font: Optional[QFont] = None ) -> QTextCharFormat: """ Return a copy of `baseformat` :class:`QTextCharFormat` with updated color, weight, background and font properties. """ charformat = QTextCharFormat(baseformat) if color is not None: charformat.setForeground(color) if background is not None: charformat.setBackground(background) if font is not None: assert weight is None and italic is None and underline is None charformat.setFont(font) else: if weight is not None: charformat.setFontWeight(weight) if italic is not None: charformat.setFontItalic(italic) if underline is not None: charformat.setFontUnderline(underline) return charformat
def createOperators(self): operatorFormat = QTextCharFormat() operatorFormat.setForeground(QColor(148, 99, 233)) operatorFormat.setFontWeight(QFont.Bold) operators = [ '\\+', '-', '/', '\\*', '=', '==', '!=', '<=', '>=', '<', '>' ] self.highlightingRules.extend([(QRegExp(pattern), operatorFormat) for pattern in operators])
def createKeywords(self): keywordFormat = QTextCharFormat() keywordFormat.setForeground(Qt.darkBlue) keywordFormat.setFontWeight(QFont.Bold) keywords = [ '\\band\\b', '\\bdel\\b', '\\bfor\\b', '\\bas\\b', '\\bassert\\b', '\\bbreak\\b', '\\bclass\\b', '\\bcontinue\\b', '\\bdef\\b', '\\belif\\b', '\\belse\\b', '\\bexcept\\b', '\\bexec\\b', '\\bFalse\\b', '\\bfinally\\b', '\\bfrom\\b', '\\bglobal\\b', '\\bif\\b', '\\bimport\\b', '\\bin\\b', '\\bis\\b', '\\blambda\\b', '\\bNone\\b', '\\bnonlocal\\b', '\\bnot\\b', '\bor\b', '\\bpass\\b', '\\bprint\\b', '\\braise\\b', '\\breturn\\b', '\\bTrue\\b', '\\btry\\b', '\\bwhile\\b', '\\bwith\\b', '\\byield\\b', '<', '<=', '>', '>=', '==', '!=' ] self.highlightingRules = [(QRegExp(pattern), keywordFormat) for pattern in keywords]
def text_format(foreground=Qt.black, weight=QFont.Normal): fmt = QTextCharFormat() fmt.setForeground(QBrush(foreground)) fmt.setFontWeight(weight) return fmt
def text_format(foreground=Qt.black, weight=QFont.Normal): fmt = QTextCharFormat() fmt.setForeground(QBrush(foreground)) fmt.setFontWeight(weight) return fmt