I've got a QGIS processing script which displays progress in the message bar, using the code in the PyQGIS cookbook.
It displays properly at the beginning of processing, but my code calls some other processing algorithms from Grass, which also push messages to the message bar and override my progress bar. Is it possible to either set the default duration of these messages to something small like a second, or block the message entirely?
I tried an approach that connects the widgetAdded slot to a function to re-add the progress bar, but it's causing QGIS to crash. Here is the code:
def putBarBack():
iface.messageBar().widgetAdded.disconnect()
iface.messageBar().pushWidget(progressMessageBar, iface.messageBar().INFO)
iface.messageBar().widgetAdded.connect(putBarBack)
def run():
#set up progress bar
global progressMessageBar
progressMessageBar = iface.messageBar().createMessage("Processing...")
bar = QtGui.QProgressBar()
bar.setRange(0,100)
bar.setAlignment(Qt.AlignLeft|Qt.AlignVCenter)
progressMessageBar.layout().addWidget(bar)
iface.messageBar().pushWidget(progressMessageBar, iface.messageBar().INFO)
iface.messageBar().widgetAdded.connect(putBarBack)
# do some more processing here...
bar.setValue(25)
processing.runalg(grass7:r.watershed)
bar.setValue(75)
#do some more processing
bar.setValue(100)
progressMessageBar, you could just change its text. Example: at the beginning you haveprogressMessageBar = iface.messageBar().createMessage("Processing..."); then when running some process, useprogressMessageBar.setText('Processing...Step 1'); then when running another process, useprogressMessageBar.setText('Processing...Step 2')etc. That way, there will always be oneprogressMessageBarand all you're doing is changing the text (or message). – Joseph Jan 31 '18 at 15:26processing.runalg(grass7:r.watershed, progress=None)as described in this post. – Joseph Jan 31 '18 at 15:41