Exemplo n.º 1
0
    def __init__(self, document, **options):
        Formatter.__init__(self, **options)

        self.document = document

        # Prepare format by styles
        self.styles = {}
        for token, style in self.style:
            format = QTextCharFormat()
            if style['color']:
                format.setForeground(QColor('#' + style['color']))
            if style['bold']:
                format.setFontWeight(QFont.Bold)
            if style['italic']:
                format.setFontItalic(True)
            if style['underline']:
                format.setFontUnderline(True)
            self.styles[token] = format
Exemplo n.º 2
0
    def updateRules(self):
        try:
            keywordFormat = QTextCharFormat()
            keywordFormat.setForeground(QColor("#000099"))
            keywordFormat.setFontWeight(QFont.Bold)
            keywordFormat.setFontUnderline(True)
            keywordFormat.setAnchor(True)

            dict_words = self._database.getAllDictWords()
            keywordPatterns = ["\\b" + word + "\\b" for word in dict_words]
            keywordPatterns.extend(
                ["\\b" + word.upper() + "\\b" for word in dict_words])
            keywordPatterns.extend(
                ["\\b" + word.lower() + "\\b" for word in dict_words])
            self.highlightingRules = [(QRegExp(pattern), keywordFormat)
                                      for pattern in keywordPatterns]

        except Exception as e:
            print("Failed to update the highlighting rules:", e)