Hide downloads progress bars until download starts, and improve the look of progress bar display

This commit is contained in:
Micah Lee 2016-12-22 15:15:37 -08:00
parent d765fe90ef
commit c6a5515082
2 changed files with 16 additions and 22 deletions

View file

@ -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.insertWidget(-1, 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,13 +102,12 @@ class OnionShareGui(QtWidgets.QMainWindow):
# downloads # downloads
self.downloads = Downloads() self.downloads = Downloads()
self.downloads_layout = QtWidgets.QGroupBox() self.downloads_container = QtWidgets.QScrollArea()
self.downloads_layout.setLayout(self.downloads) self.downloads_container.setWidget(self.downloads)
self.downloads_layout_container = QtWidgets.QScrollArea() self.downloads_container.setWidgetResizable(True)
self.downloads_layout_container.setWidget(self.downloads_layout) self.downloads_container.setMaximumHeight(200)
self.downloads_layout_container.setWidgetResizable(True) self.vbar = self.downloads_container.verticalScrollBar()
self.downloads_layout_container.setFixedHeight(80) self.downloads_container.hide() # downloads start out hidden
self.vbar = self.downloads_layout_container.verticalScrollBar()
self.new_download = False self.new_download = False
# options # options
@ -120,14 +119,14 @@ class OnionShareGui(QtWidgets.QMainWindow):
version_label = QtWidgets.QLabel('v{0:s}'.format(helpers.get_version())) version_label = QtWidgets.QLabel('v{0:s}'.format(helpers.get_version()))
version_label.setStyleSheet('color: #666666; padding: 0 10px;') version_label.setStyleSheet('color: #666666; padding: 0 10px;')
self.status_bar.addPermanentWidget(version_label) self.status_bar.addPermanentWidget(version_label)
self.setStatusBar(self.status_bar) self.setStatusBar(self.status_bar)
# main layout # main layout
self.layout = QtWidgets.QVBoxLayout() self.layout = QtWidgets.QVBoxLayout()
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.addWidget(self.downloads_layout_container) 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)
@ -229,7 +228,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
def check_for_requests(self): def check_for_requests(self):
""" """
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 # scroll to the bottom of the dl progress bar log pane
# if a new download has been added # if a new download has been added
@ -255,6 +254,7 @@ 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 self.new_download = True
@ -264,7 +264,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
elif event["type"] == web.REQUEST_PROGRESS: elif event["type"] == web.REQUEST_PROGRESS:
self.downloads.update_download(event["data"]["id"], event["data"]["bytes"]) self.downloads.update_download(event["data"]["id"], event["data"]["bytes"])
# is the download complete? # is the download complete?
if event["data"]["bytes"] == web.zip_filesize: if event["data"]["bytes"] == web.zip_filesize:
# close on finish? # close on finish?