1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
import sys
from PyQt4.QtGui import QApplication
from PyQt4 import QtCore, QtGui, Qsci
from PyQt4.Qsci import QsciScintilla, QsciScintillaBase, QsciLexerPython
if __name__ == "__main__":
app = QApplication(sys.argv)
editor = QsciScintilla()
## Choose a lexer
## This can be any Scintilla lexer, but the original example used Python
lexer = QsciLexerPython()
## Create an API for us to populate with our autocomplete terms
api = Qsci.QsciAPIs(lexer)
editor.setBraceMatching(QsciScintilla.StrictBraceMatch)
## Add autocompletion strings
api.add("aLongString")
api.add("aLongerString")
api.add("aDifferentString")
api.add("sOmethingElse")
api.add("\\clef")
api.add("\\harmonicsOn")
api.add("<test>")
api.add("sOmethingElse")
## Compile the api for use in the lexer
api.prepare()
editor.setLexer(lexer)
## Set the length of the string before the editor tries to autocomplete
## In practise this would be higher than 1
## But its set lower here to make the autocompletion more obvious
editor.setAutoCompletionThreshold(1)
## Tell the editor we are using a QsciAPI for the autocompletion
editor.setAutoCompletionSource(QsciScintilla.AcsAPIs)
## Render on screen
editor.show()
## Show this file in the editor
#~ editor.setText(open("qt4_sci_ac_test.py").read())
sys.exit(app.exec_()) |
Partager