From 1970235224602aa5e0c3b9cf26a87040c7064891 Mon Sep 17 00:00:00 2001 From: tsi-billypom Date: Mon, 14 Apr 2025 11:58:32 -0400 Subject: [PATCH] custom question box with details --- components/MusicTable.py | 18 +++++----- components/QuestionBoxDetails.py | 57 ++++++++++++++++++++++++++++++++ components/__init__.py | 1 + 3 files changed, 68 insertions(+), 8 deletions(-) create mode 100644 components/QuestionBoxDetails.py diff --git a/components/MusicTable.py b/components/MusicTable.py index 79d89cc..7b7ae8d 100644 --- a/components/MusicTable.py +++ b/components/MusicTable.py @@ -18,10 +18,12 @@ from PyQt5.QtWidgets import ( QAction, QHeaderView, QMenu, + QPlainTextEdit, QTableView, QShortcut, QMessageBox, QAbstractItemView, + QVBoxLayout, ) from PyQt5.QtCore import ( QItemSelectionModel, @@ -37,6 +39,7 @@ from components.ErrorDialog import ErrorDialog from components.LyricsWindow import LyricsWindow from components.AddToPlaylistWindow import AddToPlaylistWindow from components.MetadataWindow import MetadataWindow +from components.QuestionBoxDetails import QuestionBoxDetails from main import Worker from utils.batch_delete_filepaths_from_database import ( @@ -496,21 +499,20 @@ class MusicTable(QTableView): # FIXME: need to get indexes based on the proxy model selected_filepaths = self.get_selected_songs_filepaths() formatted_selected_filepaths = "\n".join(selected_filepaths) - reply = QMessageBox.question( - self, - "Confirmation", - f"Remove these songs from the library? (Files stay on your computer)\n{formatted_selected_filepaths}", - QMessageBox.Yes | QMessageBox.No, - QMessageBox.Yes, + question_dialog = QuestionBoxDetails( + title="Delete songs", + description="Remove these songs from the library?", + details=formatted_selected_filepaths, ) - if reply == QMessageBox.Yes: - pprint(selected_filepaths) + reply = question_dialog.execute() + if reply: worker = Worker(batch_delete_filepaths_from_database, selected_filepaths) worker.signals.signal_progress.connect(self.qapp.handle_progress) worker.signals.signal_finished.connect(self.delete_selected_row_indices) if self.qapp: threadpool = self.qapp.threadpool threadpool.start(worker) + return def delete_selected_row_indices(self): """ diff --git a/components/QuestionBoxDetails.py b/components/QuestionBoxDetails.py new file mode 100644 index 0000000..4f6e9f1 --- /dev/null +++ b/components/QuestionBoxDetails.py @@ -0,0 +1,57 @@ +from PyQt5.QtCore import pyqtSignal +from PyQt5.QtWidgets import ( + QDialog, + QHBoxLayout, + QPlainTextEdit, + QVBoxLayout, + QLabel, + QPushButton, +) +from PyQt5.QtGui import QFont +from components.ErrorDialog import ErrorDialog +from utils import set_id3_tag +from logging import debug + + +class QuestionBoxDetails(QDialog): + def __init__(self, title: str, description: str, details): + super(QuestionBoxDetails, self).__init__() + self.title: str = title + self.description: str = description + self.details: str = details + self.reply: bool = False + self.setWindowTitle(title) + self.setMinimumSize(400, 400) + layout = QVBoxLayout() + h_layout = QHBoxLayout() + + # Labels & input fields + label = QLabel(description) + layout.addWidget(label) + self.text_field = QPlainTextEdit(self.details) + layout.addWidget(self.text_field) + # cancel + cancel_button = QPushButton("cancel") + cancel_button.clicked.connect(self.cancel) + h_layout.addWidget(cancel_button) + # ok + ok_button = QPushButton("ok") + ok_button.clicked.connect(self.ok) + h_layout.addWidget(ok_button) + + layout.addLayout(h_layout) + self.setLayout(layout) + + ok_button.setFocus() + + def execute(self): + self.exec_() + return self.reply + + def cancel(self): + self.reply = False + self.close() + + def ok(self): + self.reply = True + self.close() diff --git a/components/__init__.py b/components/__init__.py index 57ba057..4c2672f 100644 --- a/components/__init__.py +++ b/components/__init__.py @@ -9,3 +9,4 @@ from .AddToPlaylistWindow import AddToPlaylistWindow from .CreatePlaylistWindow import CreatePlaylistWindow from .PlaylistsPane import PlaylistsPane from .ExportPlaylistWindow import ExportPlaylistWindow +from .QuestionBoxDetails import QuestionBoxDetails