I would like to provide the user of a plugin with progress status using messages and a progress bar.
My plugin processes several files using memory files, processing, writing to disk etc. It all works well, but takes 10 to 90 seconds run. In QGIS 2.18 it ran for about 5 seconds displaying progress text in the status bar, then the Windows wait icon displays and QGIS is unresponsive until complete - status bar hangs and QGIS looks frozen. In version 3.0, (the same plugin after updating the code), QGIS appears to freezes immediately (although the code is working properly), and status text does not display at all until after the routine has finished.
I am using Windows 10 and QGIS 3.4.2. My code takes long enough to require a status bar, but my attempts to display any information only occurs after the code has finished. I have looked into tasks and running code in the background, but there appear to be bugs yet to be resolved (QgsTask and task manager cause crash when used in function scope). Is there any way in QGIS 3.0 to show progress during the processing steps?
Update: I have had some success with a progress bar as a widget in the message bar. By adding
self.iface.mainWindow().repaint() after setting the bar value (
setValue) the bar will display properly. If the code takes more than 5 seconds the screen freezes and no updates to QGIS until the code has run. If I add
time.sleep(0.1) before and after setting value and repainting, the status bar works properly.
Is it normal to have to repaint the screen every time the status bar is to increment? Is the only workaround to "jiggle" the screen with the sleep-timer so it won't freeze?
The above solution came from Unresponsive MessageBar in QGIS 3