Merge branch 'choltz95-wrap-progress-bar'

This commit is contained in:
Micah Lee 2016-12-22 15:15:50 -08:00
commit a67a037885
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
2 changed files with 21 additions and 13 deletions

View File

@ -56,7 +56,7 @@ class Download(object):
elapsed = time.time() - self.started
if elapsed < 10:
# Wait a couple of seconds for the download rate to stabilize.
# This prevents an "Windows copy dialog"-esque experience at
# This prevents a "Windows copy dialog"-esque experience at
# the beginning of the download.
pb_fmt = strings._('gui_download_progress_starting').format(
helpers.human_readable_filesize(downloaded_bytes))
@ -77,33 +77,27 @@ class Download(object):
self.started)
class Downloads(QtWidgets.QVBoxLayout):
class Downloads(QtWidgets.QWidget):
"""
The downloads chunk of the GUI. This lists all of the active download
progress bars.
"""
def __init__(self):
super(Downloads, self).__init__()
self.downloads = {}
# downloads label
self.downloads_label = QtWidgets.QLabel(strings._('gui_downloads', True))
self.downloads_label.hide()
# add the widgets
self.addWidget(self.downloads_label)
self.layout = QtWidgets.QVBoxLayout()
self.setLayout(self.layout)
def add_download(self, download_id, total_bytes):
"""
Add a new download progress bar.
"""
self.downloads_label.show()
self.parent().show()
# add it to the list
download = Download(download_id, total_bytes)
self.downloads[download_id] = download
self.addWidget(download.progress_bar)
self.layout.insertWidget(-1, download.progress_bar)
def update_download(self, download_id, downloaded_bytes):
"""

View File

@ -102,6 +102,13 @@ class OnionShareGui(QtWidgets.QMainWindow):
# downloads
self.downloads = Downloads()
self.downloads_container = QtWidgets.QScrollArea()
self.downloads_container.setWidget(self.downloads)
self.downloads_container.setWidgetResizable(True)
self.downloads_container.setMaximumHeight(200)
self.vbar = self.downloads_container.verticalScrollBar()
self.downloads_container.hide() # downloads start out hidden
self.new_download = False
# options
self.options = Options(web, self.app)
@ -119,7 +126,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
self.layout.addLayout(self.file_selection)
self.layout.addLayout(self.server_status)
self.layout.addWidget(self.filesize_warning)
self.layout.addLayout(self.downloads)
self.layout.addWidget(self.downloads_container)
self.layout.addLayout(self.options)
central_widget = QtWidgets.QWidget()
central_widget.setLayout(self.layout)
@ -223,6 +230,11 @@ class OnionShareGui(QtWidgets.QMainWindow):
Check for messages communicated from the web app, and update the GUI accordingly.
"""
self.update()
# scroll to the bottom of the dl progress bar log pane
# if a new download has been added
if self.new_download:
self.vbar.setValue(self.vbar.maximum())
self.new_download = False
# only check for requests if the server is running
if self.server_status.status != self.server_status.STATUS_STARTED:
return
@ -242,7 +254,9 @@ class OnionShareGui(QtWidgets.QMainWindow):
self.status_bar.showMessage(strings._('download_page_loaded', True))
elif event["type"] == web.REQUEST_DOWNLOAD:
self.downloads_container.show() # show the downloads layout
self.downloads.add_download(event["data"]["id"], web.zip_filesize)
self.new_download = True
elif event["type"] == web.REQUEST_RATE_LIMIT:
self.stop_server()