QPlainTextEdit as a Python editor?
-
I'm don't really know what I should be looking for so I some help. I have a
QPlainTextEdit
that I want it to act as a Python editor. The main usage for it is to catch errors, warnings and print command when I run the script. I would also like it to be aware of the variable's type in the script so to provide the corresponded attributes and methods as autocompleter.For example, when I define
a
as astring
, entering.
after will trigger the autocompleter for all of its methods.a = "hello" a.lower()
Where do I need to look?
-
Hi,
You can check the QSyntaxHighlighter example but this will require a QTextEdit.
However, from the looks of your description, you seem to want to have support for a language server.
-
Hi,
You can check the QSyntaxHighlighter example but this will require a QTextEdit.
However, from the looks of your description, you seem to want to have support for a language server.
-
After testing out some Python codes in Visual Studio Code (it has Python language server implemented), I don't really like what I see. Some methods from my imported modules has a return type(class) and the autocompleter was not able to feed me the attributes and methods under that type. For example, the method
myModule.getNewClass()
will return a variable with typeNewClass
. AndNewClass
has a method calledgetName()
,output = myModule.getNewClass()
But then when I went like
output.
, the autocompleter, instead of giving megetName()
as the choice, it fed me all the methods from all the import modules.So this route is a no go for me.
-
If the auto-completer is not working the reason might be, that its the wrong format. There are different ways to define doc strings and how they are stored, e.g. in VIM it uses Jedi but cannot see the docstrings in c-extensions, however you can make them available via stub files e.g. in pybind11 and so on...
TLDR: its a bit complicated and not only depends on your autocompleter but also on how you add the docstrings to your python module.