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

View File

@ -102,6 +102,13 @@ class OnionShareGui(QtWidgets.QMainWindow):
# downloads # downloads
self.downloads = 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 # options
self.options = Options(web, self.app) self.options = Options(web, self.app)
@ -119,7 +126,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
self.layout.addLayout(self.file_selection) self.layout.addLayout(self.file_selection)
self.layout.addLayout(self.server_status) self.layout.addLayout(self.server_status)
self.layout.addWidget(self.filesize_warning) self.layout.addWidget(self.filesize_warning)
self.layout.addLayout(self.downloads) self.layout.addWidget(self.downloads_container)
self.layout.addLayout(self.options) self.layout.addLayout(self.options)
central_widget = QtWidgets.QWidget() central_widget = QtWidgets.QWidget()
central_widget.setLayout(self.layout) 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. Check for messages communicated from the web app, and update the GUI accordingly.
""" """
self.update() 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 # only check for requests if the server is running
if self.server_status.status != self.server_status.STATUS_STARTED: if self.server_status.status != self.server_status.STATUS_STARTED:
return return
@ -242,7 +254,9 @@ class OnionShareGui(QtWidgets.QMainWindow):
self.status_bar.showMessage(strings._('download_page_loaded', True)) self.status_bar.showMessage(strings._('download_page_loaded', True))
elif event["type"] == web.REQUEST_DOWNLOAD: 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.downloads.add_download(event["data"]["id"], web.zip_filesize)
self.new_download = True
elif event["type"] == web.REQUEST_RATE_LIMIT: elif event["type"] == web.REQUEST_RATE_LIMIT:
self.stop_server() self.stop_server()