From 82c2bd470f37b3d8e836d868ebbddc86c16175ff Mon Sep 17 00:00:00 2001 From: billypom on debian Date: Mon, 24 Mar 2025 20:44:09 -0400 Subject: [PATCH] cleanup --- components/CreatePlaylistWindow.py | 5 ++--- components/DebugWindow.py | 8 ++------ components/MusicTable.py | 11 +++++++---- components/PlaylistsPane.py | 11 ++++++++--- components/PreferencesWindow.py | 3 ++- main.py | 2 +- 6 files changed, 22 insertions(+), 18 deletions(-) diff --git a/components/CreatePlaylistWindow.py b/components/CreatePlaylistWindow.py index b94ec7b..04c62e4 100644 --- a/components/CreatePlaylistWindow.py +++ b/components/CreatePlaylistWindow.py @@ -1,6 +1,5 @@ -import logging +from logging import error from PyQt5.QtWidgets import QDialog, QHBoxLayout, QLineEdit, QPushButton, QVBoxLayout -from PyQt5.QtCore import pyqtSignal import DBA @@ -37,7 +36,7 @@ class CreatePlaylistWindow(QDialog): with DBA.DBAccess() as db: db.execute("INSERT INTO playlist (name) VALUES (?);", (value,)) except Exception as e: - logging.error( + error( f"CreatePlaylistWindow.py save() | Could not create playlist: {e}" ) self.playlistCreatedSignal.emit() diff --git a/components/DebugWindow.py b/components/DebugWindow.py index a57af9b..c70586c 100644 --- a/components/DebugWindow.py +++ b/components/DebugWindow.py @@ -2,12 +2,8 @@ from PyQt5.QtWidgets import ( QDialog, QPlainTextEdit, QVBoxLayout, - QLabel, - QPushButton, ) -from PyQt5.QtGui import QFont -from components.ErrorDialog import ErrorDialog -from utils import set_id3_tag +from pprint import pformat class DebugWindow(QDialog): @@ -20,7 +16,7 @@ class DebugWindow(QDialog): layout = QVBoxLayout() # Labels & input fields - self.input_field = QPlainTextEdit(self.text) + self.input_field = QPlainTextEdit(pformat(self.text)) layout.addWidget(self.input_field) self.setLayout(layout) diff --git a/components/MusicTable.py b/components/MusicTable.py index 56e86e4..1dab89d 100644 --- a/components/MusicTable.py +++ b/components/MusicTable.py @@ -1,4 +1,5 @@ from mutagen.id3 import ID3 +from json import load as jsonload import DBA from PyQt5.QtGui import ( QDragMoveEvent, @@ -195,8 +196,10 @@ class MusicTable(QTableView): col_count = self.model2.columnCount() qtableview_width = self.size().width() sum_of_cols = self.horizontal_header.length() + debug(f'qtable_width: {qtableview_width}') + debug(f'sum of cols: {sum_of_cols}') - if sum != qtableview_width: + if sum_of_cols <= qtableview_width: # if not the last header if logicalIndex < (col_count): next_header_size = self.horizontal_header.sectionSize(logicalIndex + 1) @@ -544,12 +547,11 @@ class MusicTable(QTableView): self.set_current_song_filepath() self.playPauseSignal.emit() - def add_files(self, files) -> None: - """Thread handles adding songs to library + def add_files(self, files: list[str]) -> None: + """Spawns a worker thread - adds a list of filepaths to the library - Drag & Drop song(s) on tableView - File > Open > List of song(s) """ - debug(f"add files, files: {files}") worker = Worker(add_files_to_library, files) worker.signals.signal_progress.connect(self.qapp.handle_progress) worker.signals.signal_finished.connect(self.load_music_table) @@ -695,6 +697,7 @@ class MusicTable(QTableView): def set_current_song_filepath(self) -> None: """Sets the filepath of the currently playing song""" + # NOTE: # Setting the current song filepath automatically plays that song # self.tableView listens to this function and plays the audio file located at self.current_song_filepath self.current_song_filepath = ( diff --git a/components/PlaylistsPane.py b/components/PlaylistsPane.py index f7b1631..a8161a1 100644 --- a/components/PlaylistsPane.py +++ b/components/PlaylistsPane.py @@ -18,8 +18,8 @@ class PlaylistsPane(QTreeWidget): super().__init__(parent) library_root = QTreeWidgetItem(["Library"]) self.addTopLevelItem(library_root) - all_songs_branch = QTreeWidgetItem(["All Songs"]) - library_root.addChild(all_songs_branch) + # all_songs_branch = QTreeWidgetItem(["All Songs"]) + # library_root.addChild(all_songs_branch) self.playlists_root = QTreeWidgetItem(["Playlists"]) self.addTopLevelItem(self.playlists_root) @@ -36,17 +36,22 @@ class PlaylistsPane(QTreeWidget): self.playlist_db_id_choice: int | None = None def playlist_clicked(self, item): + """Specific playlist index was clicked""" if isinstance(item, PlaylistWidgetItem): debug(f"ID: {item.id}, name: {item.text(0)}") self.playlist_db_id_choice = item.id self.playlistChoiceSignal.emit(int(item.id)) - elif item.text(0).lower() == "all songs": + elif item.text(0).lower() == "library": self.all_songs_selected() def all_songs_selected(self): + """Emits a signal to display all songs in the library""" + # I have no idea why this has to be in its own function, but it does + # or else it doesn't work self.allSongsSignal.emit() def add_latest_playlist_to_tree(self): + """Adds the most recently created playlist to the pane""" with DBA.DBAccess() as db: playlist = db.query( "SELECT id, name FROM playlist ORDER BY date_created DESC LIMIT 1;", () diff --git a/components/PreferencesWindow.py b/components/PreferencesWindow.py index f81b6b4..c5290ea 100644 --- a/components/PreferencesWindow.py +++ b/components/PreferencesWindow.py @@ -93,7 +93,8 @@ class PreferencesWindow(QDialog): child.widget().deleteLater() def save_preferences(self): - info("im saving") + # FIXME: this isnt working? at least not for database + # Upcate the config fields for key in self.input_fields: for category in self.config.sections(): diff --git a/main.py b/main.py index 2991140..20142cd 100644 --- a/main.py +++ b/main.py @@ -492,7 +492,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow): def create_playlist(self) -> None: """Creates a database record for a playlist, given a name""" window = CreatePlaylistWindow(self.playlistCreatedSignal) - window.playlistCreatedSignal.connect(self.add_latest_playlist_to_tree) + window.playlistCreatedSignal.connect(self.add_latest_playlist_to_tree) # type: ignore window.exec_() def import_playlist(self) -> None: