🛠️ Fixed GUI crashes. Root Cause: QProgressBar setValue() calls from download thread. Fixes #2.

This commit is contained in:
Robert Honz
2024-01-15 21:55:51 +01:00
parent acf2ff3adb
commit 1ca44af435
2 changed files with 18 additions and 13 deletions
+5 -6
View File
@@ -69,6 +69,7 @@ class Download:
progress_stdout: bool = True progress_stdout: bool = True
else: else:
progress_stdout: bool = False progress_stdout: bool = False
# Send signal to GUI with media name
progress_gui.item_name.emit(media_name) progress_gui.item_name.emit(media_name)
try: try:
@@ -113,8 +114,7 @@ class Download:
# To send the progress to the GUI, we need to emit the percentage. # To send the progress to the GUI, we need to emit the percentage.
if not progress_stdout: if not progress_stdout:
# progress_gui.item.emit(progress.tasks[p_task].percentage) progress_gui.item.emit(progress.tasks[p_task].percentage)
pass
except HTTPError as e: except HTTPError as e:
# TODO: Handle Exception... # TODO: Handle Exception...
fn_logger(e) fn_logger(e)
@@ -240,8 +240,8 @@ class Download:
release_date: str = ( release_date: str = (
track.album.release_date.strftime("%Y-%m-%d") if track.album and track.album.release_date else "" track.album.release_date.strftime("%Y-%m-%d") if track.album and track.album.release_date else ""
) )
copy_right: str = track.copyright if hasattr(track, "copyright") else "" copy_right: str = track.copyright if hasattr(track, "copyright") and track.copyright else ""
isrc: str = track.isrc if hasattr(track, "isrc") else "" isrc: str = track.isrc if hasattr(track, "isrc") and track.isrc else ""
lyrics: str = "" lyrics: str = ""
if self.settings.data.lyrics_save: if self.settings.data.lyrics_save:
@@ -341,8 +341,7 @@ class Download:
progress.advance(p_task1) progress.advance(p_task1)
if not progress_stdout: if not progress_stdout:
# progress_gui.list_item.emit(progress.tasks[p_task1].percentage) progress_gui.list_item.emit(progress.tasks[p_task1].percentage)
pass
# If a file was downloaded and the download delay is enabled, wait until the next download. # If a file was downloaded and the download delay is enabled, wait until the next download.
if download_delay and status_download: if download_delay and status_download:
+13 -7
View File
@@ -32,7 +32,7 @@ from tidal_dl_ng.worker import Worker
class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
settings: Settings = None settings: Settings = None
tidal: Tidal = None tidal: Tidal = None
download: Download = None dl: Download = None
threadpool: QtCore.QThreadPool = None threadpool: QtCore.QThreadPool = None
spinner: QtWaitingSpinner = None spinner: QtWaitingSpinner = None
spinner_start: QtCore.Signal = QtCore.Signal(QtWidgets.QWidget) spinner_start: QtCore.Signal = QtCore.Signal(QtWidgets.QWidget)
@@ -42,6 +42,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
s_item_name: QtCore.Signal = QtCore.Signal(str) s_item_name: QtCore.Signal = QtCore.Signal(str)
pb_list: QtWidgets.QProgressBar = None pb_list: QtWidgets.QProgressBar = None
s_list_advance: QtCore.Signal = QtCore.Signal(float) s_list_advance: QtCore.Signal = QtCore.Signal(float)
s_pb_reset: QtCore.Signal = QtCore.Signal()
def __init__(self, tidal: Tidal | None = None): def __init__(self, tidal: Tidal | None = None):
super().__init__() super().__init__()
@@ -93,7 +94,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
break break
if result: if result:
self.download = Download(self.tidal.session, self.tidal.settings.data.skip_existing) self.dl = Download(self.tidal.session, self.tidal.settings.data.skip_existing)
self.thread_it(self.populate_tree_lists, self.tidal) self.thread_it(self.populate_tree_lists, self.tidal)
@@ -230,7 +231,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
media = item.data(3, QtCore.Qt.ItemDataRole.UserRole) media = item.data(3, QtCore.Qt.ItemDataRole.UserRole)
# TODO: Implement disable download button etc. # TODO: Implement disable download button etc.
self.download_item(media, self.download) self.download(media, self.dl)
def search_populate_results(self, query: str, type_media: SearchTypes): def search_populate_results(self, query: str, type_media: SearchTypes):
self.tr_results.clear() self.tr_results.clear()
@@ -334,6 +335,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
self.s_item_advance.connect(self.progress_item) self.s_item_advance.connect(self.progress_item)
self.s_item_name.connect(self.progress_item_name) self.s_item_name.connect(self.progress_item_name)
self.s_list_advance.connect(self.progress_list) self.s_list_advance.connect(self.progress_list)
self.s_pb_reset.connect(self.progress_reset())
def progress_list(self, value: float): def progress_list(self, value: float):
self.pb_list.setValue(int(math.ceil(value))) self.pb_list.setValue(int(math.ceil(value)))
@@ -397,14 +399,14 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
for item in items: for item in items:
media: Track | Album | Playlist | Video = item.data(5, QtCore.Qt.ItemDataRole.UserRole) media: Track | Album | Playlist | Video = item.data(5, QtCore.Qt.ItemDataRole.UserRole)
self.download_item(media, self.download) self.download(media, self.dl)
self.b_download.setText("Download") self.b_download.setText("Download")
self.b_download.setEnabled(True) self.b_download.setEnabled(True)
def download_item(self, media: Track | Album | Playlist | Video | Mix, dl: Download) -> bool: def download(self, media: Track | Album | Playlist | Video | Mix, dl: Download) -> bool:
# TODO: Refactor this. Move this logic to `Download` class and provide a generic interface. # TODO: Refactor this. Move this logic to `Download` class and provide a generic interface.
self.progress_reset() self.s_pb_reset.emit()
self.statusbar.showMessage("Download started...") self.statusbar.showMessage("Download started...")
data_pb: ProgressBars = ProgressBars( data_pb: ProgressBars = ProgressBars(
@@ -428,7 +430,11 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
else: else:
logger_gui.info(f"Download skipped (file exists): {download_path_file}") logger_gui.info(f"Download skipped (file exists): {download_path_file}")
elif isinstance(media, Album | Playlist | Mix): elif isinstance(media, Album | Playlist | Mix):
progress_name = media.name if media.name else media.title if media.title else "List N/A" progress_name = (
media.name
if hasattr(media, "name") and media.name
else hasattr(media, "title") and media.title if media.title else "List N/A"
)
self.progress_list_name(progress_name) self.progress_list_name(progress_name)