Question about mw.progress.start()
I'm trying to use mw.progress.start() while another window is loading/is opening which takes a couple of seconds, but it doesn't work. It only opens after the new window opened (and minimizes it). Here's the relevant code:
In __init__.py:
from .Main import start_main
def invoke_main():
mw.progress.start()
mw.Main = start_main()
#mw.progress.finish()
In Main.py:
from .forms import Main #pyuic generated file
class start_main(QDialog):
def __init__(self, parent=None):
self.parent = parent
QDialog.__init__(self, parent, Qt.Window)
self.dialog = Main.Ui_dialog()
self.dialog.setupUi(self)
self.setupUI()
def setupUI(self):
Can somebody explain to me why this is happening and how it could be fixed?
Posted Sep 21, 2020, 5:52 PM UTC · edited
36
Maybe
It used in the source code a few times and by default it'll be delayed a bit just in case if the operation is fast enough and there's no need to show the progress bar.
https://github.com/ankitects/anki/blob/49ebb193cf5d1220d37610e7e9de916e7f61540b/qt/aqt/progress.py#L83-L86
No, that doesn't work either. But thank you anyway.
In this case, maybe either try to add this line somewhere to your code.
Maybe it'll allow Anki to update UI and show the progress window as your code might be blocking the main thread.
Otherwise, maybe something like this to show it immediately as by default it'll still be delayed by 100 ms.
This opens the window, but its blank until the other thing loaded completely.
If it's not possible to periodically use to keep GUI updated and repsonsive
or move some non-gui part to QThread like in this example - https://nikolak.com/pyqt-threading-tutorial/ - maybe opening the window with a bit of delay using QTimer will help to make the progress dialog fully visible.