From 3bd2c539cfc5c0991391c69dc3577a7da827690f Mon Sep 17 00:00:00 2001 From: billypom on debian Date: Thu, 5 Sep 2024 22:55:58 -0400 Subject: [PATCH] a --- components/MusicTable.py | 56 ++++++++++++++++++++++++++++++---------- main.py | 2 +- 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/components/MusicTable.py b/components/MusicTable.py index 3e6db0c..82ebca4 100644 --- a/components/MusicTable.py +++ b/components/MusicTable.py @@ -16,12 +16,21 @@ from PyQt5.QtWidgets import ( QMessageBox, QAbstractItemView, ) -from PyQt5.QtCore import QAbstractItemModel, QModelIndex, Qt, pyqtSignal, QTimer +from PyQt5.QtCore import ( + QAbstractItemModel, + QModelIndex, + QThread, + Qt, + pyqtSignal, + QTimer, +) from components.DebugWindow import DebugWindow from components.ErrorDialog import ErrorDialog from components.LyricsWindow import LyricsWindow from components.AddToPlaylistWindow import AddToPlaylistWindow from components.MetadataWindow import MetadataWindow + +# from main import WorkerThread from utils.delete_song_id_from_database import delete_song_id_from_database from utils.add_files_to_library import add_files_to_library from utils.get_reorganize_vars import get_reorganize_vars @@ -36,6 +45,29 @@ import os import shutil +class DropAddFilesThread(QThread): + signalStarted = pyqtSignal() + signalProgress = pyqtSignal(str) + signalFinished = pyqtSignal() + + def __init__(self, files, parent=None): + QThread.__init__(self, parent) + self.files = files + + def run(self) -> None: + self.add_files() + return + + def add_files(self) -> None: + """When song(s) added to the library, update the tableview model + - Drag & Drop song(s) on tableView + - File > Open > List of song(s) + """ + add_files_to_library(self.files) + self.signalFinished.emit() + return + + class MusicTable(QTableView): playPauseSignal = pyqtSignal() enterKey = pyqtSignal() @@ -237,8 +269,13 @@ class MusicTable(QTableView): for url in data.urls(): if url.isLocalFile(): files.append(url.path()) - self.add_files(files) e.accept() + self.worker = DropAddFilesThread(files=files) + # self.model.dataChanged.disconnect(self.on_cell_data_changed) + # self.model.dataChanged.connect(self.on_cell_data_changed) + self.worker.signalFinished.connect(self.load_music_table) + self.worker.start() + # self.add_files(files) else: e.ignore() @@ -310,6 +347,8 @@ class MusicTable(QTableView): # Get target directory target_dir = str(self.config["directories"]["reorganize_destination"]) for filepath in filepaths: + if str(filepath).startswith((target_dir)): + continue try: # Read file metadata artist, album = get_reorganize_vars(filepath) @@ -344,7 +383,7 @@ class MusicTable(QTableView): ) def toggle_play_pause(self): - """Toggles the currently playing song by emitting a signal""" + """Toggles the currently playing song by emitting a Signal""" if not self.current_song_filepath: self.set_current_song_filepath() self.playPauseSignal.emit() @@ -425,17 +464,6 @@ class MusicTable(QTableView): lambda: self.verticalScrollBar().setValue(self.vertical_scroll_position), ) - def add_files(self, files) -> None: - """When song(s) added to the library, update the tableview model - - Drag & Drop song(s) on tableView - - File > Open > List of song(s) - """ - number_of_files_added = add_files_to_library(files) - if number_of_files_added: - self.model.dataChanged.disconnect(self.on_cell_data_changed) - self.load_music_table() - self.model.dataChanged.connect(self.on_cell_data_changed) - def get_selected_rows(self) -> list[int]: """Returns a list of indexes for every selected row""" selection_model = self.selectionModel() diff --git a/main.py b/main.py index 3a92834..22d6fa1 100644 --- a/main.py +++ b/main.py @@ -102,7 +102,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow): global stopped stopped = False # Multithreading stuff... - self.workers = dict[UUID, WorkerThread] = {} + # self.workers = dict[UUID, WorkerThread] = {} self.threadpool = QThreadPool() # UI self.setupUi(self)