I have some python PyQT code where a user will click a button and a process kicks off to download some data from a website. While this is happening I want a message to appear in list window to say "please wait" so they know that something is happening.
However the timing is off and the message appears after the processing has finished even though I've added the code for the message status at the start of the class function for the button click to start the process. This is a brief version of the code I have:
self.statusfeed.addItem("Please Wait....Updating database from the web")
update_db()
self.statusfeed.addItem("Database updated")
The function update_db() runs the downloading.
This is the main part of the update function other than a dictonary of weblinks to get the files from:
for filename, weblink in web_links:
netfile = urllib2.urlopen(weblink)
out_fp = open(os.path.join(root, filename), 'w')
out_fp.write(netfile.read())
out_fp.close
However the please wait status is not updating until after the downloading is done. How can I force it to wait and update the status in the order that I've show above?
Add QtGui.qApp.processEvents()
before the call to update_db()
. This will give the UI to update itself according to the events that are pending.