diff --git a/components/CreatePlaylistWindow.py b/components/CreatePlaylistWindow.py index 29cc715..b94ec7b 100644 --- a/components/CreatePlaylistWindow.py +++ b/components/CreatePlaylistWindow.py @@ -1,11 +1,13 @@ import logging from PyQt5.QtWidgets import QDialog, QHBoxLayout, QLineEdit, QPushButton, QVBoxLayout +from PyQt5.QtCore import pyqtSignal import DBA class CreatePlaylistWindow(QDialog): - def __init__(self): + def __init__(self, playlistCreatedSignal): super(CreatePlaylistWindow, self).__init__() + self.playlistCreatedSignal = playlistCreatedSignal self.setWindowTitle("Create new playlist") layout = QVBoxLayout() button_layout = QHBoxLayout() @@ -38,6 +40,7 @@ class CreatePlaylistWindow(QDialog): logging.error( f"CreatePlaylistWindow.py save() | Could not create playlist: {e}" ) + self.playlistCreatedSignal.emit() self.close() def cancel(self) -> None: diff --git a/components/MusicTable.py b/components/MusicTable.py index ce6d071..9121d30 100644 --- a/components/MusicTable.py +++ b/components/MusicTable.py @@ -179,7 +179,6 @@ class MusicTable(QTableView): Popen(["xdg-open", path]) def edit_selected_files_metadata(self): - # FIXME: """Opens a form with metadata from the selected audio files""" files = self.get_selected_songs_filepaths() song_ids = self.get_selected_songs_db_ids() diff --git a/components/PlaylistsPane.py b/components/PlaylistsPane.py index 0f69ab4..f455a08 100644 --- a/components/PlaylistsPane.py +++ b/components/PlaylistsPane.py @@ -20,16 +20,16 @@ class PlaylistsPane(QTreeWidget): all_songs_branch = QTreeWidgetItem(["All Songs"]) library_root.addChild(all_songs_branch) - playlists_root = QTreeWidgetItem(["Playlists"]) - self.addTopLevelItem(playlists_root) + self.playlists_root = QTreeWidgetItem(["Playlists"]) + self.addTopLevelItem(self.playlists_root) with DBA.DBAccess() as db: playlists = db.query("SELECT id, name FROM playlist;", ()) for playlist in playlists: branch = PlaylistWidgetItem(self, playlist[0], playlist[1]) - playlists_root.addChild(branch) + self.playlists_root.addChild(branch) library_root.setExpanded(True) - playlists_root.setExpanded(True) + self.playlists_root.setExpanded(True) self.currentItemChanged.connect(self.playlist_clicked) self.playlist_db_id_choice: int | None = None @@ -44,3 +44,11 @@ class PlaylistsPane(QTreeWidget): def all_songs_selected(self): self.allSongsSignal.emit() + + def add_latest_playlist_to_tree(self): + with DBA.DBAccess() as db: + playlist = db.query( + "SELECT id, name FROM playlist ORDER BY date_created DESC LIMIT 1;", () + )[0] + branch = PlaylistWidgetItem(self, playlist[0], playlist[1]) + self.playlists_root.addChild(branch) diff --git a/main.py b/main.py index 570d524..8932075 100644 --- a/main.py +++ b/main.py @@ -20,7 +20,7 @@ from PyQt5.QtWidgets import ( QGraphicsPixmapItem, QMessageBox, ) -from PyQt5.QtCore import QUrl, QTimer, Qt +from PyQt5.QtCore import QUrl, QTimer, Qt, pyqtSignal from PyQt5.QtMultimedia import QMediaPlayer, QMediaContent, QAudioProbe from PyQt5.QtGui import QCloseEvent, QPixmap from utils import scan_for_music, delete_and_create_library_database, initialize_db @@ -36,6 +36,8 @@ from components import ( class ApplicationWindow(QMainWindow, Ui_MainWindow): + playlistCreatedSignal = pyqtSignal() + def __init__(self, qapp): super(ApplicationWindow, self).__init__() global stopped @@ -79,7 +81,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow): self.PlotWidget.getAxis("left").setLabel("") # Remove y-axis label # Playlist left-pane - self.playlistTreeView + # self.playlistTreeView # Connections self.playbackSlider.sliderReleased.connect( @@ -357,8 +359,13 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow): def create_playlist(self) -> None: """Creates a database record for a playlist, given a name""" - create_playlist_window = CreatePlaylistWindow() - create_playlist_window.exec_() + window = CreatePlaylistWindow(self.playlistCreatedSignal) + window.playlistCreatedSignal.connect(self.add_latest_playlist_to_tree) + window.exec_() + + def add_latest_playlist_to_tree(self) -> None: + """Refreshes the playlist tree""" + self.playlistTreeView.add_latest_playlist_to_tree() def import_playlist(self) -> None: """