Is there any equivelant of setCurrentBlockState of QSyntaxHighlighter in QsciScintilla?

47 Views Asked by At

Because the highlighting I want to use is needed to get the previous status of store in a variable in the previous line, and I can use it in the QSyntaxHighlighter by store it in setCurrentBlockState.

For example:

from PyQt5.Qsci import QsciScintilla

class QsciLexerCustom1(QsciLexerCustom):
    def styleText(self, start, end):
        editor = self.editor()
        SCI = editor.SendScintilla
        interline_status = 0
        for line in source:
            #(tokenizing the line)
        for token in tokenized_line:
             if token == "string1":
                 interline_status = 1
             if token == "string2":
                 interline_status = 2

However, the interline_status will be reset to 0 while processing to the next line. I have found the variable QsciScintilla.SCI_GETSTYLEAT which is similar to what I want like below:

pos = SCI(QsciScintilla.SCI_GETLINEENDPOSITION, index - 1)
interline_state = SCI(QsciScintilla.SCI_GETSTYLEAT, pos)

However, the result is unexpected. Maybe the status value I want to use is not at the end of the variable.

Is there any equivalent of setCurrentBlockState in QsciScintilla (in PyQt5)?

1

There are 1 best solutions below

0
Tan Kian-teng On

I have found the answer: using QsciScintilla.SCI_SETLINESTATE and QsciScintilla.SCI_GETLINESTATE:

from PyQt5.Qsci import QsciScintilla

class QsciLexerCustom1(QsciLexerCustom):
    def styleText(self, start, end):
        editor = self.editor()
        SCI = editor.SendScintilla
        index = 0 # current line indicator
        interline_status = 0

        # get the status of the prev. line
        if index > 0:
             interline_status = SCI(QsciScintilla.SCI_GETLINESTATE, index - 1)

        for line in source:
             #(tokenizing the line)

        for token in tokenized_line:
             if token == "string1":
                   interline_status = 1
             if token == "string2":
                   interline_status = 2

        # store the status of current line 
        SCI(QsciScintilla.SCI_SETLINESTATE, index, interline_status)