mirror of
https://github.com/onionshare/onionshare.git
synced 2025-07-28 09:04:26 -04:00
added download progress bars to GUI, and made close automatically act as stop server automatically
This commit is contained in:
parent
5325b7b173
commit
fcdcfd7c39
6 changed files with 107 additions and 32 deletions
|
@ -8,19 +8,43 @@ class Downloads(QtGui.QVBoxLayout):
|
|||
super(Downloads, self).__init__()
|
||||
self.addSpacing(10)
|
||||
|
||||
self.progress_bars = {}
|
||||
|
||||
# downloads label
|
||||
self.downloads_label = QtGui.QLabel(strings._('gui_downloads'))
|
||||
"""progress_bar = QtGui.QProgressBar()
|
||||
progress_bar.setFormat("12.3 KiB, 17%")
|
||||
progress_bar.setTextVisible(True)
|
||||
progress_bar.setAlignment(QtCore.Qt.AlignHCenter)
|
||||
progress_bar.setMinimum(0)
|
||||
progress_bar.setMaximum(100)
|
||||
progress_bar.setValue(17)"""
|
||||
# hide downloads by default
|
||||
self.downloads_label.hide()
|
||||
|
||||
# add the widgets
|
||||
self.addWidget(self.downloads_label)
|
||||
#self.addWidget(progress_bar)
|
||||
|
||||
def add_download(self, download_id, total_bytes):
|
||||
self.downloads_label.show()
|
||||
|
||||
# make a new progress bar
|
||||
pb = QtGui.QProgressBar()
|
||||
pb.setTextVisible(True)
|
||||
pb.setAlignment(QtCore.Qt.AlignHCenter)
|
||||
pb.setMinimum(0)
|
||||
pb.setMaximum(total_bytes)
|
||||
pb.setValue(0)
|
||||
pb.setStyleSheet("QProgressBar::chunk { background-color: #05B8CC; }")
|
||||
pb.total_bytes = total_bytes
|
||||
|
||||
# add it to the list
|
||||
self.progress_bars[download_id] = pb
|
||||
self.addWidget(pb)
|
||||
|
||||
# start at 0
|
||||
self.update_download(download_id, total_bytes, 0)
|
||||
|
||||
def update_download(self, download_id, total_bytes, downloaded_bytes):
|
||||
if download_id not in self.progress_bars:
|
||||
self.add_download(download_id, total_bytes)
|
||||
|
||||
pb = self.progress_bars[download_id]
|
||||
pb.setValue(downloaded_bytes)
|
||||
if downloaded_bytes == pb.total_bytes:
|
||||
pb.setFormat("%p%")
|
||||
else:
|
||||
pb.setFormat("{0}, %p%".format(helpers.human_readable_filesize(downloaded_bytes)))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue