Skip to content

Commit

Permalink
Improve progress notification during download
Browse files Browse the repository at this point in the history
 * Set progress bar to 50% when download size unknown

 * Show total number of bytes to be downloaded when known
  • Loading branch information
ejn committed Apr 20, 2020
1 parent 6330bb3 commit 3512041
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions inspireatomclientdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ def cancelDownload(self):
self.qnam.abort()
self.close()

self.progressBar.setMaximum(1)
self.progressBar.setMaximum(100)
self.progressBar.setValue(0)
self.reset_ui_download()

Expand All @@ -838,13 +838,13 @@ def httpRequestFinished(self):
self.outFile.flush()
self.outFile.close()

self.progressBar.setMaximum(1)
self.progressBar.setValue(1)
self.progressBar.setMaximum(100)
self.progressBar.setValue(100)

self.lblMessage.setText("")
self.downloadedfiles.append(str(self.outFile.fileName()))
self.download_next()
self.progressBar.setMaximum(1)
self.progressBar.setMaximum(100)
self.progressBar.setValue(0)


Expand All @@ -859,9 +859,17 @@ def readResponseHeader(self, responseHeader):
def updateDataReadProgress(self, bytesRead, totalBytes):
if self.httpRequestAborted:
return
self.progressBar.setMaximum(totalBytes)
if totalBytes > 0:
self.progressBar.setMaximum(totalBytes)
content_length = str(totalBytes)
else:
# server did not send a content-length header - let's assume 50% finished
self.progressBar.setMaximum(bytesRead * 2)
content_length = '???'

self.progressBar.setValue(bytesRead)
self.lblMessage.setText("Please wait while downloading - {0} Bytes downloaded!".format(str(bytesRead)))
self.lblMessage.setText("Please wait while downloading - {0} / {1} Bytes downloaded!".format(str(bytesRead),
content_length))


class MessageHandler(QtXmlPatterns.QAbstractMessageHandler):
Expand Down

0 comments on commit 3512041

Please sign in to comment.