Make downloads window scrollable again. Reset to original size when starting a fresh share

This commit is contained in:
Miguel Jacq 2018-02-28 09:48:23 +11:00
parent fffc420cb1
commit fa9e5748a3
No known key found for this signature in database
GPG Key ID: EEA4341C6D97A0B6
2 changed files with 18 additions and 7 deletions

View File

@ -98,24 +98,32 @@ class Downloads(QtWidgets.QWidget):
def __init__(self):
super(Downloads, self).__init__()
self.downloads = {}
self.downloads_container = QtWidgets.QScrollArea()
self.downloads_container.setWidget(self)
self.downloads_container.setWindowTitle(strings._('gui_downloads', True))
self.downloads_container.setWidgetResizable(True)
self.downloads_container.setMaximumHeight(600)
self.downloads_container.setMinimumHeight(150)
self.downloads_container.setMinimumWidth(350)
self.downloads_container.setWindowIcon(QtGui.QIcon(common.get_resource_path('images/logo.png')))
self.downloads_container.setWindowFlags(QtCore.Qt.Sheet | QtCore.Qt.WindowTitleHint | QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.CustomizeWindowHint)
self.downloads_container.vbar = self.downloads_container.verticalScrollBar()
self.downloads_label = QtWidgets.QLabel(strings._('gui_downloads', True))
self.downloads_label.setStyleSheet('QLabel { font-weight: bold; font-size 14px; text-align: center; }')
self.no_downloads_label = QtWidgets.QLabel(strings._('gui_no_downloads', True))
self.layout = QtWidgets.QVBoxLayout()
self.layout.addWidget(self.downloads_label)
self.layout.addWidget(self.no_downloads_label)
self.setLayout(self.layout)
self.setWindowTitle(strings._('gui_downloads', True))
self.setMinimumWidth(350)
self.setWindowIcon(QtGui.QIcon(common.get_resource_path('images/logo.png')))
self.setWindowFlags(QtCore.Qt.Sheet | QtCore.Qt.WindowTitleHint | QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.CustomizeWindowHint)
def add_download(self, download_id, total_bytes):
"""
Add a new download progress bar.
"""
# add it to the list
self.no_downloads_label.hide()
download = Download(download_id, total_bytes)
self.downloads[download_id] = download
self.layout.addWidget(download.progress_bar)

View File

@ -560,6 +560,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
# scroll to the bottom of the dl progress bar log pane
# if a new download has been added
if self.new_download:
self.downloads.downloads_container.vbar.setValue(self.downloads.downloads_container.vbar.maximum())
self.new_download = False
events = []
@ -577,6 +578,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
self.status_bar.showMessage(strings._('download_page_loaded', True))
elif event["type"] == web.REQUEST_DOWNLOAD:
self.downloads.no_downloads_label.hide()
self.downloads.add_download(event["data"]["id"], web.zip_filesize)
self.new_download = True
self.downloads_in_progress += 1
@ -649,9 +651,9 @@ class OnionShareGui(QtWidgets.QMainWindow):
"""
common.log('OnionShareGui', 'toggle_downloads')
if checked:
self.downloads.show()
self.downloads.downloads_container.show()
else:
self.downloads.hide()
self.downloads.downloads_container.hide()
def copy_url(self):
"""
@ -695,6 +697,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
self.update_downloads_in_progress(0)
self.info_show_downloads.setIcon(QtGui.QIcon(common.get_resource_path('images/download_window_gray.png')))
self.downloads.no_downloads_label.show()
self.downloads.downloads_container.resize(self.downloads.downloads_container.sizeHint())
def update_downloads_completed(self, count):
"""