QPlainTextEdit as a Python editor?
-
wrote on 5 Feb 2021, 19:25 last edited by lansing 2 May 2021, 20:20
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.
-
Take a look at Jedi
-
wrote on 5 Feb 2021, 22:19 last edited by
Also maybe its worth taking a look at QScintilla which has build in functionality for auto-completion, highlighting and those things.
Here a link to some overview and here to the download -
wrote on 6 Feb 2021, 00:29 last edited by
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.
-
wrote on 6 Feb 2021, 10:08 last edited by
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.
1/7