【问题标题】:Is there any equivelant of setCurrentBlockState of QSyntaxHighlighter in QsciScintilla?QsciScintilla 中的 QSyntaxHighlighter 的 setCurrentBlockState 是否有任何等价物?
【发布时间】:2021-05-30 15:05:00
【问题描述】:

因为我想要使用的突出显示需要在上一行的变量中获取存储的先前状态,我可以通过将其存储在 setCurrentBlockState 中来在 QSyntaxHighlighter 中使用它。

例如:

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

但是,interline_status 将在处理到下一行时重置为 0。我找到了变量QsciScintilla.SCI_GETSTYLEAT,它类似于我想要的如下:

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

但是,结果出乎意料。也许我要使用的状态值不在变量的末尾。

QsciScintilla(在 PyQt5 中)中是否存在与 setCurrentBlockState 等效的内容?

【问题讨论】:

    标签: python pyqt scintilla


    【解决方案1】:

    我找到了答案:使用QsciScintilla.SCI_SETLINESTATEQsciScintilla.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) 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-19
      • 1970-01-01
      • 2011-07-14
      • 2018-07-06
      • 2014-02-26
      • 1970-01-01
      • 1970-01-01
      • 2020-07-10
      相关资源
      最近更新 更多