PyQt GUI and Python API design
-
wrote on 7 Feb 2022, 19:50 last edited by
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 :- GUI canvas (QMainWindow) showes the status of the system.
- 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. - 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. -
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 ?
-
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 ?
wrote on 7 Feb 2022, 20:19 last edited by@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.
-
How will you enter these objects in your QLineEdit ?
You are a bit vague about your issues with iPython.
-
wrote on 7 Feb 2022, 22:49 last edited by
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/5