Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPlainTextEdit as a Python editor?

QPlainTextEdit as a Python editor?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 537 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lansing
    wrote on 5 Feb 2021, 19:25 last edited by lansing 2 May 2021, 20:20
    #1

    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 a string, entering . after will trigger the autocompleter for all of its methods.

    a = "hello"
    a.lower()
    

    Where do I need to look?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 5 Feb 2021, 20:07 last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      L 1 Reply Last reply 5 Feb 2021, 21:11
      1
      • S SGaist
        5 Feb 2021, 20:07

        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.

        L Offline
        L Offline
        lansing
        wrote on 5 Feb 2021, 21:11 last edited by
        #3

        @SGaist
        Thanks, I checked out the Python language server by Microsoft, looks like it's the right path. But what about catching errors and warnings? What do I use?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 5 Feb 2021, 22:10 last edited by
          #4

          Take a look at Jedi

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • G Offline
            G Offline
            gde23
            wrote on 5 Feb 2021, 22:19 last edited by
            #5

            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

            1 Reply Last reply
            2
            • L Offline
              L Offline
              lansing
              wrote on 6 Feb 2021, 00:29 last edited by
              #6

              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 type NewClass. And NewClass has a method called getName(),

              output = myModule.getNewClass()
              

              But then when I went like output., the autocompleter, instead of giving me getName() as the choice, it fed me all the methods from all the import modules.

              So this route is a no go for me.

              1 Reply Last reply
              0
              • G Offline
                G Offline
                gde23
                wrote on 6 Feb 2021, 10:08 last edited by
                #7

                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 Reply Last reply
                0

                1/7

                5 Feb 2021, 19:25

                • Login

                • Login or register to search.
                1 out of 7
                • First post
                  1/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved