Skip to content

Commit

Permalink
Progress bar is updated more smoothly.
Browse files Browse the repository at this point in the history
Issue #1019
 Changes to be committed:
	modified:   persepolis/gui/progress_ui.py
	modified:   persepolis/gui/video_finder_progress_ui.py
	modified:   persepolis/scripts/mainwindow.py
	modified:   persepolis/scripts/progress.py
	modified:   persepolis/scripts/video_finder_progress.py
  • Loading branch information
alireza-amirsamimi committed Sep 23, 2024
1 parent e20906f commit 4e8eab3
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 11 deletions.
56 changes: 51 additions & 5 deletions persepolis/gui/progress_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,65 @@

try:
from PySide6.QtWidgets import QDial, QCheckBox, QProgressBar, QFrame, QComboBox, QWidget, QTabWidget, QVBoxLayout, QHBoxLayout, QPushButton, QLabel
from PySide6.QtCore import Qt, QTranslator, QCoreApplication, QLocale, QSize
from PySide6.QtCore import Qt, QTranslator, QCoreApplication, QLocale, QSize, QThread, Signal
from PySide6.QtGui import QIcon
except:
from PyQt5.QtWidgets import QDial, QCheckBox, QProgressBar, QFrame, QComboBox, QWidget, QTabWidget, QVBoxLayout, QHBoxLayout, QPushButton, QLabel
from PyQt5.QtCore import Qt, QTranslator, QCoreApplication, QLocale, QSize
from PyQt5.QtCore import Qt, QTranslator, QCoreApplication, QLocale, QSize, QThread
from PyQt5.QtCore import pyqtSignal as Signal
from PyQt5.QtGui import QIcon

from persepolis.gui import resources
import time


class UpdateProgressBarThread(QThread):
UPDATEPROGRESSBAR = Signal(int)

def __init__(self, parent, new_value):
QThread.__init__(self)
self.new_value = new_value
self.parent = parent

def run(self):
dif = self.new_value - self.parent.value()
while self.parent.value() != self.new_value and not (self.parent.finished):
if dif < 0:
self.UPDATEPROGRESSBAR.emit((self.parent.value() - 1))

time.sleep(0.5 / (dif * -1))
elif dif > 0:
self.UPDATEPROGRESSBAR.emit((self.parent.value() + 1))
time.sleep(0.5 / dif)

self.parent.update_lock = False


# This widget updated more smoothly than QProgressBar
class MyProgressBar(QProgressBar):
def __init__(self, main_window):
super().__init__()
self.setValue(0)
self.setMaximum(100)
self.update_lock = False
self.main_window = main_window
self.finished = False

def setValueSmoothly(self, new_value):
if self.update_lock:
return
self.update_lock = True
update_progress_bar = UpdateProgressBarThread(self, new_value)
update_progress_bar.UPDATEPROGRESSBAR.connect(self.setValueSmoothly2)
self.main_window.threadPool.append(update_progress_bar)
self.main_window.threadPool[-1].start()

def setValueSmoothly2(self, value):
self.setValue(value)


class ProgressWindow_Ui(QWidget):
def __init__(self, persepolis_setting):
def __init__(self, persepolis_setting, parent):
super().__init__()
self.persepolis_setting = persepolis_setting
icons = ':/' + str(persepolis_setting.value('settings/icons')) + '/'
Expand Down Expand Up @@ -163,9 +210,8 @@ def __init__(self, persepolis_setting):

verticalLayout.addWidget(self.progress_tabWidget)


# download_progressBar
self.download_progressBar = QProgressBar(self)
self.download_progressBar = MyProgressBar(parent)
verticalLayout.addWidget(self.download_progressBar)
self.download_progressBar.setTextVisible(True)
# changing the alignment of progress bar
Expand Down
4 changes: 2 additions & 2 deletions persepolis/gui/video_finder_progress_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@


class VideoFinderProgressWindow_Ui(ProgressWindow_Ui):
def __init__(self, persepolis_setting):
super().__init__(persepolis_setting)
def __init__(self, persepolis_setting, parent):
super().__init__(persepolis_setting, parent)

# status_tab
self.status_tab = QWidget()
Expand Down
8 changes: 6 additions & 2 deletions persepolis/scripts/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1917,7 +1917,7 @@ def checkDownloadInfo(self, list):
value = int(value[:-1])
except:
value = 0
progress_window.download_progressBar.setValue(value)
progress_window.download_progressBar.setValueSmoothly(value)

# status
progress_window.status = str(download_status_dict['status'])
Expand Down Expand Up @@ -5416,7 +5416,11 @@ def addLinkSpiderCallBack(self, spider_dict, child):

if file_size:
file_size = 'Size: ' + str(file_size)
child.size_label.setText(file_size)
if child.size_label.text() == 'None' or child.size_label.text() == '':
child.size_label.setText(file_size)
else:
# It's updated before! dont change it.
return

if file_name and not (child.change_name_checkBox.isChecked()):
child.change_name_lineEdit.setText(file_name)
Expand Down
2 changes: 1 addition & 1 deletion persepolis/scripts/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def run(self):

class ProgressWindow(ProgressWindow_Ui):
def __init__(self, parent, gid, persepolis_setting):
super().__init__(persepolis_setting)
super().__init__(persepolis_setting, parent)
self.persepolis_setting = persepolis_setting
self.main_window = parent
self.gid = gid
Expand Down
2 changes: 1 addition & 1 deletion persepolis/scripts/video_finder_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def run(self):

class VideoFinderProgressWindow(VideoFinderProgressWindow_Ui):
def __init__(self, parent, gid_list, persepolis_setting):
super().__init__(persepolis_setting)
super().__init__(persepolis_setting, parent)
self.persepolis_setting = persepolis_setting
self.main_window = parent

Expand Down

0 comments on commit 4e8eab3

Please sign in to comment.