mirror of
https://github.com/onionshare/onionshare.git
synced 2025-02-11 20:29:15 -05:00
Switch Downloads from QListWidget to QScrollArea
This commit is contained in:
parent
aeda4da597
commit
b697e51d21
@ -23,8 +23,9 @@ from PyQt5 import QtCore, QtWidgets, QtGui
|
|||||||
from onionshare import strings
|
from onionshare import strings
|
||||||
|
|
||||||
|
|
||||||
class Download(object):
|
class Download(QtWidgets.QWidget):
|
||||||
def __init__(self, common, download_id, total_bytes):
|
def __init__(self, common, download_id, total_bytes):
|
||||||
|
super(Download, self).__init__()
|
||||||
self.common = common
|
self.common = common
|
||||||
|
|
||||||
self.download_id = download_id
|
self.download_id = download_id
|
||||||
@ -32,6 +33,8 @@ class Download(object):
|
|||||||
self.total_bytes = total_bytes
|
self.total_bytes = total_bytes
|
||||||
self.downloaded_bytes = 0
|
self.downloaded_bytes = 0
|
||||||
|
|
||||||
|
self.setStyleSheet('QWidget { border: 1px solid red; }')
|
||||||
|
|
||||||
# Progress bar
|
# Progress bar
|
||||||
self.progress_bar = QtWidgets.QProgressBar()
|
self.progress_bar = QtWidgets.QProgressBar()
|
||||||
self.progress_bar.setTextVisible(True)
|
self.progress_bar.setTextVisible(True)
|
||||||
@ -43,6 +46,11 @@ class Download(object):
|
|||||||
self.progress_bar.setStyleSheet(self.common.css['downloads_uploads_progress_bar'])
|
self.progress_bar.setStyleSheet(self.common.css['downloads_uploads_progress_bar'])
|
||||||
self.progress_bar.total_bytes = total_bytes
|
self.progress_bar.total_bytes = total_bytes
|
||||||
|
|
||||||
|
# Layout
|
||||||
|
layout = QtWidgets.QVBoxLayout()
|
||||||
|
layout.addWidget(self.progress_bar)
|
||||||
|
self.setLayout(layout)
|
||||||
|
|
||||||
# Start at 0
|
# Start at 0
|
||||||
self.update(0)
|
self.update(0)
|
||||||
|
|
||||||
@ -78,9 +86,9 @@ class Download(object):
|
|||||||
self.started)
|
self.started)
|
||||||
|
|
||||||
|
|
||||||
class DownloadList(QtWidgets.QListWidget):
|
class DownloadList(QtWidgets.QScrollArea):
|
||||||
"""
|
"""
|
||||||
List of download progess bars.
|
List of download progress bars.
|
||||||
"""
|
"""
|
||||||
def __init__(self, common):
|
def __init__(self, common):
|
||||||
super(DownloadList, self).__init__()
|
super(DownloadList, self).__init__()
|
||||||
@ -88,9 +96,20 @@ class DownloadList(QtWidgets.QListWidget):
|
|||||||
|
|
||||||
self.downloads = {}
|
self.downloads = {}
|
||||||
|
|
||||||
self.setMinimumHeight(205)
|
self.downloads_layout = QtWidgets.QVBoxLayout()
|
||||||
self.setSelectionMode(QtWidgets.QAbstractItemView.NoSelection)
|
self.downloads_layout.setSizeConstraint(QtWidgets.QLayout.SetMinAndMaxSize)
|
||||||
self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
|
widget = QtWidgets.QWidget()
|
||||||
|
widget.setLayout(self.downloads_layout)
|
||||||
|
self.setWidget(widget)
|
||||||
|
|
||||||
|
self.setBackgroundRole(QtGui.QPalette.Light)
|
||||||
|
self.verticalScrollBar().rangeChanged.connect(self.resizeScroll)
|
||||||
|
|
||||||
|
def resizeScroll(self, minimum, maximum):
|
||||||
|
"""
|
||||||
|
Scroll to the bottom of the window when the range changes.
|
||||||
|
"""
|
||||||
|
self.verticalScrollBar().setValue(maximum)
|
||||||
|
|
||||||
def add(self, download_id, content_length):
|
def add(self, download_id, content_length):
|
||||||
"""
|
"""
|
||||||
@ -98,10 +117,7 @@ class DownloadList(QtWidgets.QListWidget):
|
|||||||
"""
|
"""
|
||||||
download = Download(self.common, download_id, content_length)
|
download = Download(self.common, download_id, content_length)
|
||||||
self.downloads[download_id] = download
|
self.downloads[download_id] = download
|
||||||
|
self.downloads_layout.addWidget(download)
|
||||||
item = QtWidgets.QListWidgetItem()
|
|
||||||
self.addItem(item)
|
|
||||||
self.setItemWidget(item, download.progress_bar)
|
|
||||||
|
|
||||||
def update(self, download_id, downloaded_bytes):
|
def update(self, download_id, downloaded_bytes):
|
||||||
"""
|
"""
|
||||||
@ -119,14 +135,8 @@ class DownloadList(QtWidgets.QListWidget):
|
|||||||
"""
|
"""
|
||||||
Reset the downloads back to zero
|
Reset the downloads back to zero
|
||||||
"""
|
"""
|
||||||
# Remove all items from list
|
|
||||||
while True:
|
|
||||||
item = self.takeItem(0)
|
|
||||||
if not item:
|
|
||||||
break
|
|
||||||
|
|
||||||
# Close all progress bars
|
|
||||||
for download in self.downloads.values():
|
for download in self.downloads.values():
|
||||||
|
self.downloads_layout.removeWidget(download.progress_bar)
|
||||||
download.progress_bar.close()
|
download.progress_bar.close()
|
||||||
self.downloads = {}
|
self.downloads = {}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user