Create and colorize new designs on existing Scintilla vocabulary

All,

I use QScintilla for syntax - highlight your domain language (DSL).

Since my DSL is python based, I am using the existing Python Lexer for QScintilla. I manage to create new keywords as follows:

self.text = Qscintilla(self)
pythonLexer = QsciLexerPython(self.text)
self.text.setLexer(pythonLexer)
self.text.SendScintilla(QsciScintilla.SCI_SETKEYWORDS,1,bytes('WARNING', 'utf-8'))

Now, how to choose a color to highlight my newly created keywords?

Thank you so much!

+3
source share
2 answers

QsciLexerPythonpretty limited when it comes to highlighting sets of keywords, as it gives you only two options. This restriction is imposed by the Python Lexer class from the core library Scintilla, so this cannot be done (unless you want to create a patch).

, , QsciLexerPython :

class CustomLexer(QsciLexerPython):
    def keywords(self, keyset):
        if keyset == QsciLexerPython.HighlightedIdentifier:
            return b'WARNING'
        return QsciLexerPython.keywords(self, keyset)

, .. :

    pythonLexer = CustomLexer(self.text)
    pythonLexer.setColor(
        QColor('purple'), QsciLexerPython.HighlightedIdentifier)
    ...

(PS: , 0-255)

0

, , QsciLexerPython. - .

QScintilla QsciLexerCustom . :

class MyLexer(QsciLexerCustom):

    def __init__(self, parent):
        super(MyLexer, self).__init__(parent)
        [...]
    ''''''

    def language(self):
        [...]
    ''''''

    def description(self, style):
        [...]
    ''''''

    def styleText(self, start, end):
        # Called everytime the editors text has changed
        [...]
    ''''''

'''--- end class ---'''

:

  • __init__(self, parent): .

  • language(self): . , .

  • description(self, style_nr): .

  • styleText(self, start, end): , . !

-: https://qscintilla.com/subclass-qscilexercustom/

0

All Articles