From 3512041d205149bbf6a57cd8f8019f4ab3206887 Mon Sep 17 00:00:00 2001 From: Edward Nash Date: Mon, 20 Apr 2020 09:54:34 +0200 Subject: [PATCH] Improve progress notification during download * Set progress bar to 50% when download size unknown * Show total number of bytes to be downloaded when known --- inspireatomclientdialog.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/inspireatomclientdialog.py b/inspireatomclientdialog.py index a57f8e8..66dad00 100644 --- a/inspireatomclientdialog.py +++ b/inspireatomclientdialog.py @@ -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() @@ -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) @@ -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):