Qscintilla2自动完成和自动识别

2024-09-30 16:20:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我在我的项目中实现了这个类:

class ScriptEditorTextBox(QsciScintilla):

def __init__(self, parent):
    QsciScintilla.__init__(self)

    #Lexer
    lexer = QsciLexerPython()

    #AutoCompletion
    api = Qsci.QsciAPIs(lexer)
    api.add('aLongString')
    api.add('aLongerString')
    api.add('aDifferentString')
    api.add('sOmethingElse')
    api.prepare()

    self.setLexer(lexer)
    self.setAutoCompletionThreshold(1)
    self.setAutoCompletionSource(QsciScintilla.AcsAPIs)

    #LineHighlight
    self.setCaretLineVisible(True)
    self.setCaretLineBackgroundColor(QColor("gainsboro"))

    #AutoIndentation
    self.setAutoIndent(True)
    self.setIndentationGuides(True)
    self.setIndentationsUseTabs(True)
    self.setIndentationWidth(4)

    #Margins
    self.setMarginsBackgroundColor(QColor("gainsboro"))
    self.setMarginsFont(QFont("Consolas", 9, 87)) 
    self.setMarginLineNumbers(1, True)
    self.setMarginLineNumbers(2, False)
    self.setMarginWidth(1, QString().setNum(10))
    self.setMarginWidth(2, 10)
    self.connect(self, SIGNAL("linesChanged()"), self._linesChanged)

def _linesChanged(self):
    width = QString().setNum(self.lines() * 10)
    self.setMarginWidth(1, width)

一切都开始得很好,但是当我在之后按enter键时:它不会自动缩进。而且,也没有自动完成(但我甚至不知道它应该自动完成什么)。在

如有任何建议,我将不胜感激。在


Tags: selfaddapitrueinitdeflexerqstring