This commit is contained in:
billypom on debian 2025-04-16 23:03:04 -04:00
parent 2693973975
commit d3313db6ab
7 changed files with 71 additions and 27 deletions

View File

@ -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()

View File

@ -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]))

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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")

View File

@ -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])