diff --git a/components/HeaderTags.py b/components/HeaderTags.py index fc450b9..43931cd 100644 --- a/components/HeaderTags.py +++ b/components/HeaderTags.py @@ -1,9 +1,28 @@ +from configparser import ConfigParser +from pathlib import Path +from appdirs import user_config_dir + + class HeaderTags: """ Utility class to converting between different "standards" for tags (headers, id3, etc) + + `db`: dict = "db name": "db name string" + `gui`: dict = "db name": "gui string" + `id3`: dict = "db name": "id3 tag string" + `id3_keys`: dict = "id3 tag string": "db name" + `editable_db_tags`: list = "list of db names that are user editable" + `user_headers`: list = "list of db headers that the user has chosen to see in gui" """ def __init__(self): + cfg_file = ( + Path(user_config_dir(appname="musicpom", appauthor="billypom")) + / "config.ini" + ) + self.config = ConfigParser() + self.config.read(cfg_file) + self.user_headers = str(self.config["table"]["columns"]).split(",") self.db: dict = { "title": "title", "artist": "artist", @@ -55,3 +74,11 @@ class HeaderTags: "genre", "album_date", ] + + def get_user_gui_headers(self) -> list: + """Returns a list of headers for the GUI""" + gui_headers = [] + for db, gui in self.gui.items(): + if db in self.user_headers: + gui_headers.append(gui) + return gui_headers diff --git a/components/MusicTable.py b/components/MusicTable.py index 65dfe8b..91b73b6 100644 --- a/components/MusicTable.py +++ b/components/MusicTable.py @@ -663,8 +663,8 @@ class MusicTable(QTableView): self.disconnect_layout_changed() self.vertical_scroll_position = self.verticalScrollBar().value() # type: ignore self.model2.clear() - self.model2.setHorizontalHeaderLabels(list(self.headers.gui.values())) - fields = ", ".join(list(self.headers.db.values())) + self.model2.setHorizontalHeaderLabels(self.headers.get_user_gui_headers()) + fields = ", ".join(self.headers.user_headers) if playlist_id: # Load a playlist # Fetch playlist data selected_playlist_id = playlist_id[0] diff --git a/sample_config.ini b/sample_config.ini index 5510880..d921014 100644 --- a/sample_config.ini +++ b/sample_config.ini @@ -17,7 +17,7 @@ volume = 100 window_size=1152,894 [table] -# Music table options +# Music table user options columns = title,artist,album,track_number,genre,codec,album_date,filepath column_widths = 181,116,222,76,74,72,287,150 # 0 = no sort, 1 = ascending, 2 = descending