From d3313db6ab08433ddd2e2cd5a0038a1d789d8f98 Mon Sep 17 00:00:00 2001 From: billypom on debian Date: Wed, 16 Apr 2025 23:03:04 -0400 Subject: [PATCH] stuff --- components/MetadataWindow.py | 4 +-- components/MusicTable.py | 22 ++++++++------ components/QuestionBoxDetails.py | 51 +++++++++++++++++++++++++++----- main.py | 8 +++-- utils/add_files_to_database.py | 6 ++-- utils/delete_album_art.py | 3 +- utils/set_id3_tag.py | 4 +-- 7 files changed, 71 insertions(+), 27 deletions(-) diff --git a/components/MetadataWindow.py b/components/MetadataWindow.py index a13c5db..488ddb2 100644 --- a/components/MetadataWindow.py +++ b/components/MetadataWindow.py @@ -85,8 +85,8 @@ class MetadataWindow(QDialog): tag_sets[tag].append(song_data[tag].text[0]) except KeyError: pass - debug("tag sets:") - debug(tag_sets) + # debug("tag sets:") + # debug(tag_sets) # UI Creation current_layout = QHBoxLayout() diff --git a/components/MusicTable.py b/components/MusicTable.py index 368b6cb..11ce0bc 100644 --- a/components/MusicTable.py +++ b/components/MusicTable.py @@ -379,6 +379,8 @@ class MusicTable(QTableView): def on_header_resized(self, logicalIndex, oldSize, newSize): """Handles keeping headers inside the viewport""" + # FIXME: how resize good + # https://stackoverflow.com/questions/46775438/how-to-limit-qheaderview-size-when-resizing-sections col_count = self.model2.columnCount() qtableview_width = self.size().width() @@ -444,13 +446,16 @@ class MusicTable(QTableView): - data returned from the original worker process function are returned here as the first item in a tuple """ - # FIXME: - # TODO: make this prettier, show a table in a window instead of raw text probably _, details = args[0][:2] - details = dict(tuple(details)[0]) - if details: - window = DebugWindow(details) - window.exec_() + try: + details = dict(tuple(details)[0]) + if details: + window = DebugWindow(details) + window.exec_() + except IndexError: + pass + except Exception as e: + debug(f'on_add_files_to_database_finished() | Something went wrong: {e}') # ____________________ # | | @@ -498,7 +503,7 @@ class MusicTable(QTableView): question_dialog = QuestionBoxDetails( title="Delete songs", description="Remove these songs from the library?", - details=formatted_selected_filepaths, + data=selected_filepaths, ) reply = question_dialog.execute() if reply: @@ -734,8 +739,7 @@ class MusicTable(QTableView): Loads the header widths from the last application close. """ table_view_column_widths = str(self.config["table"]["column_widths"]).split(",") - if not isinstance(table_view_column_widths[0], int): - return + debug(f'loaded header widths: {table_view_column_widths}') if not isinstance(table_view_column_widths, list): for i in range(self.model2.columnCount() - 1): self.setColumnWidth(i, int(table_view_column_widths[i])) diff --git a/components/QuestionBoxDetails.py b/components/QuestionBoxDetails.py index fab3f21..bac6888 100644 --- a/components/QuestionBoxDetails.py +++ b/components/QuestionBoxDetails.py @@ -1,41 +1,76 @@ from PyQt5.QtCore import pyqtSignal from PyQt5.QtWidgets import ( + QAbstractScrollArea, QDialog, QHBoxLayout, + QHeaderView, QPlainTextEdit, + QTableWidget, + QTableWidgetItem, QVBoxLayout, QLabel, QPushButton, ) from PyQt5.QtGui import QFont from components.ErrorDialog import ErrorDialog -from utils import set_id3_tag -from logging import debug +from logging import debug, error +from pprint import pformat class QuestionBoxDetails(QDialog): - def __init__(self, title: str, description: str, details): + def __init__(self, title: str, description: str, data): super(QuestionBoxDetails, self).__init__() self.title: str = title self.description: str = description - self.details: str = details + self.data: str = data self.reply: bool = False self.setWindowTitle(title) self.setMinimumSize(400, 400) + self.setMaximumSize(600,1000) 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) + + if isinstance(self.data, str): + self.input_field = QPlainTextEdit(pformat(self.data)) + layout.addWidget(self.input_field) + else: + table: QTableWidget = QTableWidget() + table.setSizeAdjustPolicy(QAbstractScrollArea.SizeAdjustPolicy.AdjustToContents) + table.horizontalHeader().setStretchLastSection(True) + table.horizontalHeader().setSectionResizeMode(QHeaderView.Interactive) + if isinstance(self.data, list): + # big ol column + table.setRowCount(len(data)) + table.setColumnCount(1) + for i, item in enumerate(self.data): + table.setItem(i, 0, QTableWidgetItem(str(item))) + layout.addWidget(table) + elif isinstance(self.data, dict): + try: + # | TIT2 | title goes here | + # | TDRC | 2025-05-05 | + table.setRowCount(len(data.keys())) + table.setColumnCount(2) + table.setHorizontalHeaderLabels(['Tag', 'Value']) + for i, (k, v) in enumerate(data.items()): + table.setItem(i, 0, QTableWidgetItem(str(k))) + table.setItem(i, 1, QTableWidgetItem(str(v))) + layout.addWidget(table) + except Exception as e: + data = str(self.data) + self.input_field = QPlainTextEdit(pformat(data + "\n\n" + str(e))) + layout.addWidget(self.input_field) + error(f'Tried to load self.data as dict but could not. {e}') # ok - ok_button = QPushButton("ok") + ok_button = QPushButton("Confirm") ok_button.clicked.connect(self.ok) h_layout.addWidget(ok_button) # cancel - cancel_button = QPushButton("cancel") + cancel_button = QPushButton("no") cancel_button.clicked.connect(self.cancel) h_layout.addWidget(cancel_button) diff --git a/main.py b/main.py index 9b1d700..64f2d51 100644 --- a/main.py +++ b/main.py @@ -289,6 +289,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow): for i in range(self.tableView.model2.columnCount()): list_of_column_widths.append(str(self.tableView.columnWidth(i))) column_widths_as_string = ",".join(list_of_column_widths) + debug(f'saving column widths: {column_widths_as_string}') self.config["table"]["column_widths"] = column_widths_as_string self.config["settings"]["volume"] = str(self.current_volume) self.config["settings"]["window_size"] = ( @@ -296,8 +297,11 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow): ) # Save the config - with open(self.cfg_file, "w") as configfile: - self.config.write(configfile) + try: + with open(self.cfg_file, "w") as configfile: + self.config.write(configfile) + except Exception as e: + debug(f'wtf man {e}') if a0 is not None: super().closeEvent(a0) diff --git a/utils/add_files_to_database.py b/utils/add_files_to_database.py index 24d5fcd..3a4df72 100644 --- a/utils/add_files_to_database.py +++ b/utils/add_files_to_database.py @@ -34,9 +34,9 @@ def add_files_to_database(files, progress_callback=None): filename = filepath.split("/")[-1] audio, details = get_id3_tags(filepath) - print('got id3 tags') - print(type(audio)) - print(audio) + # print('got id3 tags') + # print(type(audio)) + # print(audio) if not isinstance(audio, ID3): failed_dict[filepath] = details continue diff --git a/utils/delete_album_art.py b/utils/delete_album_art.py index 41543c2..b8fe05b 100644 --- a/utils/delete_album_art.py +++ b/utils/delete_album_art.py @@ -14,11 +14,12 @@ def delete_album_art(file: str) -> bool: True on success, False on failure """ try: + debug("Deleting album art") audio = ID3(file) debug(audio) if "APIC:" in audio: del audio["APIC:"] - debug("Deleting album art") + debug("Deleting album art for real this time") audio.save() else: warning("delete_album_art_for_current_song() | no tag called APIC") diff --git a/utils/set_id3_tag.py b/utils/set_id3_tag.py index 4d225bb..49fafa0 100644 --- a/utils/set_id3_tag.py +++ b/utils/set_id3_tag.py @@ -92,7 +92,7 @@ def set_id3_tag(filepath: str, tag_name: str, value: str): Returns: True / False""" - debug(f"filepath: {filepath} | tag_name: {tag_name} | value: {value}") + # debug(f"filepath: {filepath} | tag_name: {tag_name} | value: {value}") try: try: # Load existing tags @@ -124,7 +124,7 @@ def set_id3_tag(filepath: str, tag_name: str, value: str): tag_name = id3_tag_mapping[tag_name] # Other if tag_name in mutagen_id3_tag_mapping: # Tag accounted for - debug(f"tag_name = {tag_name}") + # debug(f"tag_name = {tag_name}") tag_class = mutagen_id3_tag_mapping[tag_name] if issubclass(tag_class, Frame): frame = tag_class(encoding=3, text=[value])