def _get_format_from_style(self, token, style):
        """ Returns a QTextCharFormat for token by reading a Pygments style.
        """
        result = QtGui.QTextCharFormat()
        items = list(style.style_for_token(token).items())
        for key, value in items:
            if value is None and key == 'color':
                # make sure to use a default visible color for the foreground
                # brush
                value = drift_color(self.background, 1000).name()
            if value:
                if key == 'color':
                    result.setForeground(self._get_brush(value))
                elif key == 'bgcolor':
                    result.setBackground(self._get_brush(value))
                elif key == 'bold':
                    result.setFontWeight(QtGui.QFont.Bold)
                elif key == 'italic':
                    result.setFontItalic(value)
                elif key == 'underline':
                    result.setUnderlineStyle(
                        QtGui.QTextCharFormat.SingleUnderline)
                elif key == 'sans':
                    result.setFontStyleHint(QtGui.QFont.SansSerif)
                elif key == 'roman':
                    result.setFontStyleHint(QtGui.QFont.Times)
                elif key == 'mono':
                    result.setFontStyleHint(QtGui.QFont.TypeWriter)
        if token in [Token.Literal.String, Token.Literal.String.Doc,
                     Token.Comment]:
            # mark strings, comments and docstrings regions for further queries
            result.setObjectType(result.UserObject)
        return result
def _get_format_from_style ( self , token , style ) : result = QtGui . QTextCharFormat ( ) items = list ( style . style_for_token ( token ) . items ( ) ) for key , value in items : if value is None and key == 'color' : value = drift_color ( self . background , 1000 ) . name ( ) if value : if key == 'color' : result . setForeground ( self . _get_brush ( value ) ) elif key == 'bgcolor' : result . setBackground ( self . _get_brush ( value ) ) elif key == 'bold' : result . setFontWeight ( QtGui . QFont . Bold ) elif key == 'italic' : result . setFontItalic ( value ) elif key == 'underline' : result . setUnderlineStyle ( QtGui . QTextCharFormat . SingleUnderline ) elif key == 'sans' : result . setFontStyleHint ( QtGui . QFont . SansSerif ) elif key == 'roman' : result . setFontStyleHint ( QtGui . QFont . Times ) elif key == 'mono' : result . setFontStyleHint ( QtGui . QFont . TypeWriter ) if token in [ Token . Literal . String , Token . Literal . String . Doc , Token . Comment ] : result . setObjectType ( result . UserObject ) return result
Returns a QTextCharFormat for token by reading a Pygments style.