Python Forum

Full Version: How can I measure progress and display it in the progress bar in the interface?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello. I created a graphic interface using QtDesigner, which, when you press the OK button, runs a script that sequentially runs many programs.
The script is run by the command and contains many of these commands that execute all scripts from the project in sequence. The time it takes to execute all commands is long (about 20min), therefore you need a command bar in the interface. How can I measure the progress of scripting and how can I pass that progress to the progress bar in the interface?
Is there any to know your total progress as it's running? Like, when it completes one script and moves to the next?

If so, my first thought is to draw a rectangle as your progress bar and when it goes from one script to the next have a line that modifies the "width" of rectangle to the value that reflects where in the sequence it is. It won't move smoothly, but I've never seen one that did anyway. lol
First and foremost the fact that you are using the Designer to create your Gui is just going to be fraught with much development pain continuously. This if for 2 reasons (1) Its black-box untouchable code and this should be avoided as much as possible in a coding situation and only when absolutely necessary and never self-inflicted which is what you do when you use the Designer (2) The process of learning to use the Designer correctly actually takes more time than learning to use Python-Qt correctly (be it PyQt5, PySide2 or any other flavor) (3) Once you learn how to use Python-Qt as it was meant to be used it is nearly as fast initially as the Designer and definitely a lot faster later on -- when you go to make changes and such.

Okay that being said as @michael1789 eludes to you will need to be able to denote to your parent (that handles the progress bar) the status of its child (or children) as to their current state. I would suggest perhaps looking into QThreading the sub-processes and having the Signal back to the Parent at specific intervals as I think that might be the most straight-forward and perhaps best way to handle this -- not I am not saying its the easiest because unless you have played with QThreads before you might have them a bit tricky especially since the how to in the Qt Documentation is wrong (old Python-Qt4 docos vs current Python-Qt5) which is to say you do not, and let me repeat you do not -- sub-class a QThread in Python-Qt5

If you need more help on this and/or want help on how to learn proper Python-Qt just shoot out another question I have no problems helping teach others how to properly use Python-Qt and I, in fact, run a free Discord classroom for this very purpose.