metadata window custom subclass for only updating fields that have changed
This commit is contained in:
parent
63c54f9de7
commit
9f534830ee
@ -17,6 +17,18 @@ from utils.update_song_in_database import update_song_in_database
|
|||||||
from utils.id3_tag_mapping import id3_tag_mapping
|
from utils.id3_tag_mapping import id3_tag_mapping
|
||||||
|
|
||||||
|
|
||||||
|
class ID3LineEdit(QLineEdit):
|
||||||
|
def __init__(self, text: str, tag: str):
|
||||||
|
""" """
|
||||||
|
super(ID3LineEdit, self).__init__()
|
||||||
|
self.setText(text)
|
||||||
|
self._original_text = text
|
||||||
|
self.tag = tag
|
||||||
|
|
||||||
|
def has_changed(self) -> bool:
|
||||||
|
return self.text() != self._original_text
|
||||||
|
|
||||||
|
|
||||||
class MetadataWindow(QDialog):
|
class MetadataWindow(QDialog):
|
||||||
refreshMusicTableSignal = pyqtSignal()
|
refreshMusicTableSignal = pyqtSignal()
|
||||||
|
|
||||||
@ -80,7 +92,7 @@ class MetadataWindow(QDialog):
|
|||||||
field_text = str(value[0]) if value else ""
|
field_text = str(value[0]) if value else ""
|
||||||
# Normal field
|
# Normal field
|
||||||
label = QLabel(str(self.id3_tag_mapping[tag]))
|
label = QLabel(str(self.id3_tag_mapping[tag]))
|
||||||
input_field = QLineEdit(field_text)
|
input_field = ID3LineEdit(field_text, tag)
|
||||||
input_field.setStyleSheet(None)
|
input_field.setStyleSheet(None)
|
||||||
else:
|
else:
|
||||||
# Danger field
|
# Danger field
|
||||||
@ -88,7 +100,7 @@ class MetadataWindow(QDialog):
|
|||||||
# so be careful...dangerous
|
# so be careful...dangerous
|
||||||
field_text = str(value[0]) if value else ""
|
field_text = str(value[0]) if value else ""
|
||||||
label = QLabel(str(self.id3_tag_mapping[tag]))
|
label = QLabel(str(self.id3_tag_mapping[tag]))
|
||||||
input_field = QLineEdit(field_text)
|
input_field = ID3LineEdit(field_text, tag)
|
||||||
input_field.setStyleSheet("border: 1px solid red")
|
input_field.setStyleSheet("border: 1px solid red")
|
||||||
# Save each input field to our dict for saving
|
# Save each input field to our dict for saving
|
||||||
self.input_fields[tag] = input_field
|
self.input_fields[tag] = input_field
|
||||||
@ -106,7 +118,9 @@ class MetadataWindow(QDialog):
|
|||||||
for song in self.songs:
|
for song in self.songs:
|
||||||
for tag, field in self.input_fields.items():
|
for tag, field in self.input_fields.items():
|
||||||
if field.text() is not None and field.text() != "":
|
if field.text() is not None and field.text() != "":
|
||||||
# Update the ID3 tag if not blank
|
if field.has_changed():
|
||||||
|
# Update the ID3 tag if the tag is not blank,
|
||||||
|
# and has been edited
|
||||||
success = set_id3_tag(
|
success = set_id3_tag(
|
||||||
filepath=song[0], tag_name=tag, value=field.text()
|
filepath=song[0], tag_name=tag, value=field.text()
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user