Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. PyQt GUI and Python API design
Forum Updated to NodeBB v4.3 + New Features

PyQt GUI and Python API design

Scheduled Pinned Locked Moved Unsolved Qt for Python
5 Posts 2 Posters 1.1k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    sed1565
    wrote on 7 Feb 2022, 19:50 last edited by
    #1

    Hello,
    I have existing python backend code done. I want to build a gui, and python custom API, on top of it using PyQt.
    What I imagined is below :

    1. GUI canvas (QMainWindow) showes the status of the system.
    2. one line (QLineEdit) to emulate user interactive "Python Custom API". (Not a must, a general console will be difficult. Seems ipython is an option. I haven't tried but seems not stable, or has serious limitations).
      If user interactive command is difficult, echo latest custom API is also okay.
    3. A readOnly textbrowser to show the history of the user actions (a set of the Python custom API) --- key point.

    #3 is the keypoint for me. My purpose is to copy paste those history APIs, so I can just run those APIs in a python shell, and still obtain the same effect as the GUI.

    In Short : what I imagined is : GUI emit a custom python API, and run the API in backend will yield the final results.

    The problem is : how to do this, if there is a tiny similar example, it will be great!

    BTW, I have developed a C++/Qt gui applications, and build a C++ Tcl extension on custom API support. Tcl_Obj can map TCL datastructure to C++ datastructure.
    Since for this goal, API is python, and gui is also Python. Not sure how to do.

    07285972-cd80-436b-a1b4-ad1f266b8435-image.png

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

      Hi and welcome to devnet,

      #3 is pretty simple. Each time you emit a string from your QLineEdit, you just need to append it to your text browser.

      For the console part, were you thinking about iPython's Qt console project ?

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

      S 1 Reply Last reply 7 Feb 2022, 20:19
      0
      • S SGaist
        7 Feb 2022, 20:07

        Hi and welcome to devnet,

        #3 is pretty simple. Each time you emit a string from your QLineEdit, you just need to append it to your text browser.

        For the console part, were you thinking about iPython's Qt console project ?

        S Offline
        S Offline
        sed1565
        wrote on 7 Feb 2022, 20:19 last edited by
        #3

        @SGaist , Maybe I don't state clearly.

        My goal of the GUI/API example:

        API :
        def my_api_function(key1:str, key2:ClassObj);

        GUI :
        on_useraction_triggered():
        my_api =my_api_function(key1="str1", key2="Class Obj Instance2")
        emit(my_api) # to console/history, how? Since some argument is not simple string.
        exec(my_api) # have to exec in the same process as GUI and Backend Python code. IPython console seems the goal, but my understand is not mature right now.

        Then how can I let GUI emit an object. Since some arguments/parameters have to be object type, not just simple string.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 7 Feb 2022, 20:52 last edited by
          #4

          How will you enter these objects in your QLineEdit ?

          You are a bit vague about your issues with iPython.

          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
          0
          • S Offline
            S Offline
            sed1565
            wrote on 7 Feb 2022, 22:49 last edited by
            #5

            The object is from another gui event. Verbose example

            GUI event 1:
               on_useraction1_triggered():
                   api_return_1 = my_api_func_1(key='str1')     
            
            GUI event 2:
                on_useraction2_triggered():
                     api_return_2 = my_api_func_2(k1="str2",  k2=api_return1)
            
            API:
                def my_api_func_1(key:str) -> MyClass
                def my_api_func_2(k1:str,  k2:MyClass); 
            

            Then two user gui activities will result script like:

            ret1 = my_api_func_1(key="str1")
            my_api_func_2(k1="str2",  k2=ret1)
            

            My ultimate goal is to have corresponding script recorded, when user finished gui operations. By just running the script recorded, I will have same effect as data model changed.

            1 Reply Last reply
            0

            1/5

            7 Feb 2022, 19:50

            • Login

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