This commit is contained in:
billypom on debian 2024-09-15 21:17:11 -04:00
parent eb0eda1dda
commit 00d1c01e9f
2 changed files with 12 additions and 10 deletions

View File

@ -165,12 +165,13 @@ class MusicTable(QTableView):
if reply: if reply:
try: try:
self.model.dataChanged.disconnect(self.on_cell_data_changed) self.model.dataChanged.disconnect(self.on_cell_data_changed)
except Exception as e: except Exception:
pass pass
selected_filepaths = self.get_selected_songs_filepaths() selected_filepaths = self.get_selected_songs_filepaths()
selected_indices = self.get_selected_rows() selected_indices = self.get_selected_rows()
# FIXME: this should be batch delete with a worker thread # FIXME: this should be batch delete with a worker thread
# probably pass selected_filepaths to a worker thread # probably pass selected_filepaths to a worker thread
for file in selected_filepaths: for file in selected_filepaths:
with DBA.DBAccess() as db: with DBA.DBAccess() as db:
song_id = db.query( song_id = db.query(
@ -276,7 +277,8 @@ class MusicTable(QTableView):
print(f"files: {files}") print(f"files: {files}")
if directories: if directories:
worker = Worker(self.get_audio_files_recursively, directories) worker = Worker(self.get_audio_files_recursively, directories)
worker.signals.signal_progress.connect(self.handle_progress) # worker.signals.signal_progress.connect(self.handle_progress)
worker.signals.signal_progress.connect(self.qapp.handle_progress)
worker.signals.signal_result.connect(self.on_recursive_search_finished) worker.signals.signal_result.connect(self.on_recursive_search_finished)
worker.signals.signal_finished.connect(self.load_music_table) worker.signals.signal_finished.connect(self.load_music_table)
if self.qapp: if self.qapp:
@ -292,9 +294,9 @@ class MusicTable(QTableView):
if result: if result:
self.add_files(result) self.add_files(result)
def handle_progress(self, data): # def handle_progress(self, data):
"""Emits data to main""" # """Emits data to main"""
self.handleProgressSignal.emit(data) # self.handleProgressSignal.emit(data)
def keyPressEvent(self, e): def keyPressEvent(self, e):
"""Press a key. Do a thing""" """Press a key. Do a thing"""
@ -417,7 +419,7 @@ class MusicTable(QTableView):
""" """
logging.info(f"add files, files: {files}") logging.info(f"add files, files: {files}")
worker = Worker(add_files_to_library, files) worker = Worker(add_files_to_library, files)
worker.signals.signal_progress.connect(self.handle_progress) worker.signals.signal_progress.connect(self.qapp.handle_progress)
worker.signals.signal_finished.connect(self.load_music_table) worker.signals.signal_finished.connect(self.load_music_table)
if self.qapp: if self.qapp:
threadpool = self.qapp.threadpool threadpool = self.qapp.threadpool
@ -512,7 +514,7 @@ class MusicTable(QTableView):
if any(file.lower().endswith(ext) for ext in extensions): if any(file.lower().endswith(ext) for ext in extensions):
audio_files.append(os.path.join(root, file)) audio_files.append(os.path.join(root, file))
if progress_callback: if progress_callback:
progress_callback.emit(file) progress_callback.emit(f"Scanning {file}")
return audio_files return audio_files
def get_selected_rows(self) -> list[int]: def get_selected_rows(self) -> list[int]:

View File

@ -133,7 +133,7 @@ class Worker(QRunnable):
class ApplicationWindow(QMainWindow, Ui_MainWindow): class ApplicationWindow(QMainWindow, Ui_MainWindow):
playlistCreatedSignal = pyqtSignal() playlistCreatedSignal = pyqtSignal()
def __init__(self, qapp): def __init__(self):
super(ApplicationWindow, self).__init__() super(ApplicationWindow, self).__init__()
global stopped global stopped
stopped = False stopped = False
@ -156,7 +156,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
self.probe: QAudioProbe = QAudioProbe() # Gets audio data self.probe: QAudioProbe = QAudioProbe() # Gets audio data
self.audio_visualizer: AudioVisualizer = AudioVisualizer(self.player) self.audio_visualizer: AudioVisualizer = AudioVisualizer(self.player)
self.current_volume: int = 50 self.current_volume: int = 50
self.qapp = qapp # self.qapp = qapp
self.tableView.load_qapp(self) self.tableView.load_qapp(self)
self.albumGraphicsView.load_qapp(self) self.albumGraphicsView.load_qapp(self)
self.config.read("config.ini") self.config.read("config.ini")
@ -629,6 +629,6 @@ if __name__ == "__main__":
# Dark theme >:3 # Dark theme >:3
qdarktheme.setup_theme() qdarktheme.setup_theme()
# Show the UI # Show the UI
ui = ApplicationWindow(app) ui = ApplicationWindow()
ui.show() ui.show()
sys.exit(app.exec_()) sys.exit(app.exec_())