When a function is called - a file is tested for existence. This checksum pushes a messageBar() object for both circumstances (True/False), yet the actual bar does not display in MapCanvas until after the subsequent exec_() is called and finished running.

def callUtherPendragonsSon(self):
    holyGrailFile = 'C:\ALongWayFrom\camelot.csv'
    if os.path.exists(holyGrailFile):
        self.iface.messageBar().pushMessage("Notice", "You will need many coconuts...",\
                                            level=QgsMessageBar.INFO, duration=3)
        beginTheJourney = gatherProvisionsAndMen()
        self.iface.messageBar().pushMessage("Warning", "There is no grail :( ",\
                                            level=QgsMessageBar.CRITICAL, duration=3)

Is there a means to assure the message bar is pushed prior to calling the exec_() ?


As it turns out, a command in the external Ui gatherProvisionsAndMen()'s init is causing the trouble. It is a data-thirsty function call, and seems to supersede the messagebar (even though it is executed thereafter). The messageBar itself is intended to preliminarily notify the user of this nested 'lengthy process' - but it seems such a notice needs to take place in another manner...

Perhaps I hold a misunderstanding in the logistics of programming but,

wouldn't the call to push a QgsMessageBar() need to complete before moving forward and executing the external Ui?

  • Do you mean you only see the bar after you've closed the dialog? Cannot replicate the issue. – Germán Carrillo Feb 17 '15 at 18:42
  • The bar is only displayed after the external Ui-dialog has passed the *.show() command. e.g.-both the messageBar and Ui appear simultaneously, rather then (as intended) the former before the later. – Katalpa Feb 17 '15 at 18:44
  • Still cannot replicate it. In my test plugin, I added a for loop in between to delay the show() call, however, the message appears immediately after it's called. – Germán Carrillo Feb 17 '15 at 18:47
  • I cannot seem to find the success you mention. Is it possible that my QgisVer (2.7-Dev) is @ cause? – Katalpa Feb 17 '15 at 18:52
  • 1
    That could be the case. Perhaps you could try with a simple version and see if it gets better, i.e., try to isolate the problem. – Germán Carrillo Feb 17 '15 at 19:05

Just put dummy print 'xxx' statement immediately after self.iface.messageBar().pushMessage call.

  • I have found that if the Python plugin console is not open during such scripted prints - errors arise. Maybe due to the version I have implemented? – Katalpa Apr 24 '15 at 17:19
  • Describe an error message please. – Artur Lill Apr 25 '15 at 9:38
  • " File "C:/PROGRA~1/QGISWI~1/apps/qgis/./python/plugins\GraphicGroundwater\loadParticleTracks.py", line 265, in constructShapefile print newPathGroups IOError: [Errno 9] Bad file descriptor" – Katalpa Apr 25 '15 at 18:06
  • You are right about Python plugin console: my solution works only if this console is open. – Artur Lill Apr 27 '15 at 14:00
  • To debug an error just try to disable/enable installed plugin again... not sure what is the real cause of this error. – Artur Lill Apr 27 '15 at 14:08

To solve this problem, just say to the main window to repaint itself after pushing your message with the repaint function :

 self.iface.messageBar().pushMessage("Please wait...", level=QgsMessageBar.INFO, duration=0)
 # Do something that takes time

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.