populate edit metadata window functional for real this time

This commit is contained in:
tsi-billypom 2024-08-12 11:30:00 -04:00
parent d41963b376
commit e3b93aa6b3

View File

@ -1,6 +1,7 @@
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QDialog, QDialog,
QFrame, QFrame,
QHBoxLayout,
QVBoxLayout, QVBoxLayout,
QLabel, QLabel,
QLineEdit, QLineEdit,
@ -28,52 +29,68 @@ class MetadataWindow(QDialog):
"TCOP": "copyright", "TCOP": "copyright",
} }
self.setWindowTitle("Edit metadata") self.setWindowTitle("Edit metadata")
self.setMinimumSize(600, 800) # self.setMinimumSize(600, 800)
layout = QVBoxLayout() layout = QVBoxLayout()
h_separator = QFrame() # h_separator = QFrame()
h_separator.setFrameShape(QFrame.HLine) # h_separator.setFrameShape(QFrame.HLine)
# Labels and categories and stuff # Labels and categories and stuff
# category_label = QLabel("Edit metadata") # category_label = QLabel("Edit metadata")
# category_label.setFont(QFont("Sans", weight=QFont.Bold)) # bold category # category_label.setFont(QFont("Sans", weight=QFont.Bold)) # bold category
# category_label.setStyleSheet("text-transform:uppercase;") # uppercase category # category_label.setStyleSheet("text-transform:uppercase;") # uppercase category
layout.addWidget(h_separator) # layout.addWidget(category_label)
# layout.addWidget(h_separator)
# FIXME: dynamically load fields and stuf
# Dict of sets
# {
# "TIT2": ["song_title1", "song_title2"],
# ...
# }
tag_sets: dict = {}
# List of dictionaries of ID3 tags for each song
# songs_id3_data: list = []
for song in songs:
# songs_id3_data.append(get_id3_tags(song))
song_data = get_id3_tags(song)
for tag in self.id3_tag_mapping:
try:
tag_sets[tag] = song_data[tag]
except KeyError:
tag_sets[tag] = ""
for tag, value in tag_sets.items():
if value == set(value):
# Normal field
label = QLabel(str(self.id3_tag_mapping[tag]))
input_field = QLineEdit(str(value))
else:
# Danger field
label = QLabel(str(self.id3_tag_mapping[tag]))
input_field = QLineEdit(str(value))
layout.addWidget(label)
layout.addWidget(input_field)
# Editable fields # Editable fields
# label = QLabel("Title") tag_sets: dict = {}
# input_field = QLineEdit({songs["TPE1"]}) # { "TIT2": ["song_title1", "song_title2"], ... }
# layout.addWidget(label) for song in songs:
# layout.addWidget(input_field) song_data = get_id3_tags(song)
print("song_data")
print(song_data)
for tag in self.id3_tag_mapping:
# See if the tag exists in the dict
# else, create it
try:
_ = tag_sets[tag]
except KeyError:
tag_sets[tag] = []
try:
tag_sets[tag].append(song_data[tag].text[0])
except KeyError:
pass
print(f"tag sets: {tag_sets}")
current_layout = QHBoxLayout()
for idx, (tag, value) in enumerate(tag_sets.items()):
# Layout creation
if idx == 0:
pass
elif idx % 2 == 0:
# Make a new horizontal layout for every 2 items
layout.addLayout(current_layout)
current_layout = QHBoxLayout()
print(f"type: {type(value)} | value: {value}")
# Field Creation
if value == list(set(value)):
field_text = str(value[0]) if value else ""
# Normal field
label = QLabel(str(self.id3_tag_mapping[tag]))
input_field = QLineEdit(field_text)
input_field.setStyleSheet(None)
else:
# Danger field
# this means the metadata differs between the selected items for this tag
field_text = str(value[0]) if value else ""
label = QLabel(str(self.id3_tag_mapping[tag]))
input_field = QLineEdit(field_text)
input_field.setStyleSheet("border: 1px solid red")
current_layout.addWidget(label)
current_layout.addWidget(input_field)
# Save button # Save button
save_button = QPushButton("Save") save_button = QPushButton("Save")
@ -83,5 +100,4 @@ class MetadataWindow(QDialog):
def save(self): def save(self):
"""Save changes made to metadata for each song in dict""" """Save changes made to metadata for each song in dict"""
pass
self.close() self.close()