[PyQt] dynamic code completion
oliver
oliver.schoenborn at gmail.com
Thu Sep 10 05:25:54 BST 2015
I'd like to have a way to dynamically define the code completion API based
on context. Overriding updateAutoCompletionList seems logical place to do
this, but the following doesn't work:
from PyQt5 import Qsci, QtWidgets
class MyScriptApi(Qsci.QsciAPIs):
def updateAutoCompletionList(self, context: [str], options: [str]):
super().updateAutoCompletionList(context, options)
options.append('abcdefg')
class Window(Qsci.QsciScintilla):
def __init__(self):
Qsci.QsciScintilla.__init__(self)
lexer = Qsci.QsciLexerPython(self)
api = MyScriptApi(lexer)
api.add('aLongString')
api.add('aLongString.abcd')
api.add('aLongerString')
api.add('aDifferentString')
api.add('sOmethingElse')
api.prepare()
self.setAutoCompletionThreshold(1)
self.setAutoCompletionSource(Qsci.QsciScintilla.AcsAPIs)
self.setLexer(lexer)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
window = Window()
window.show()
app.exec_()
If the updateAutoCompletionList is not defined (the class body is just
"pass"), typing "a" shows several matches in the popup, but if the method
is as shown above, no matches get shown, eventhough the base class method
is called by the derived class. A breakpoint via debugger shows that base
class method does not put anything in the options list, nor does the base
class method return anything.
--
Oliver
Author of these Open Source: PyPubSub <http://pubsub.sf.net>, Lua-iCxx
<http://lua-icxx.sf.net>, iof <http://iof.sf.net>
Regular contributor on StackOverflow
<http://stackoverflow.com/users/869951/schollii>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150910/de9a64e2/attachment.html>
More information about the PyQt
mailing list