diff --git a/components/AlbumArtGraphicsView.py b/components/AlbumArtGraphicsView.py index 35cea82..b7c1a9a 100644 --- a/components/AlbumArtGraphicsView.py +++ b/components/AlbumArtGraphicsView.py @@ -25,7 +25,7 @@ class AlbumArtGraphicsView(QGraphicsView): Displays the album art of the currently playing song """ - # drag&drop / copy&paste will update album art for selected songs + # drag&drop / copy&paste will update album art for all selected songs albumArtDropped = pyqtSignal(str) # delete will only delete album art for current song albumArtDeleted = pyqtSignal() @@ -81,23 +81,21 @@ class AlbumArtGraphicsView(QGraphicsView): def showContextMenu(self, position: QPoint): """Handles showing a context menu when right clicking the album art""" - contextMenu = QMenu(self) # Create the menu + menu = QMenu(self) # Create the menu - copyAction = QAction("Copy", self) # Add the actions - pasteAction = QAction("Paste", self) - deleteAction = QAction("Delete", self) + copy_action = QAction("Copy", self) # Add the actions + paste_action = QAction("Paste", self) + delete_action = QAction("Delete", self) - copyAction.triggered.connect( - self.copy_album_art_to_clipboard - ) # Add the signal triggers - pasteAction.triggered.connect(self.paste_album_art_from_clipboard) - deleteAction.triggered.connect(self.delete_album_art) + copy_action.triggered.connect(self.copy_album_art_to_clipboard) + paste_action.triggered.connect(self.paste_album_art_from_clipboard) + delete_action.triggered.connect(self.delete_album_art) - contextMenu.addAction(copyAction) # Add actions to the menu - contextMenu.addAction(pasteAction) - contextMenu.addAction(deleteAction) + menu.addAction(copy_action) # Add actions to the menu + menu.addAction(paste_action) + menu.addAction(delete_action) # DO - contextMenu.exec_(self.mapToGlobal(position)) # Show the menu + menu.exec_(self.mapToGlobal(position)) # Show the menu def load_album_art(self, album_art_data: bytes) -> None: """Displays the album art for the currently playing track in the GraphicsView""" diff --git a/components/MusicTable.py b/components/MusicTable.py index f4c5eb2..c8d1197 100644 --- a/components/MusicTable.py +++ b/components/MusicTable.py @@ -203,7 +203,7 @@ class MusicTable(QTableView): painter.drawRect(rect.adjusted(1, 1, -1, -1)) def contextMenuEvent(self, a0): - """Right-click context menu for rows in Music Table""" + """Right-click context menu""" menu = QMenu(self) add_to_playlist_action = QAction("Add to playlist", self) add_to_playlist_action.triggered.connect(self.add_selected_files_to_playlist) diff --git a/components/PlaylistsPane.py b/components/PlaylistsPane.py index a8161a1..885c74d 100644 --- a/components/PlaylistsPane.py +++ b/components/PlaylistsPane.py @@ -1,5 +1,5 @@ -from PyQt5.QtWidgets import QListWidget, QTreeWidget, QTreeWidgetItem -from PyQt5.QtCore import pyqtSignal +from PyQt5.QtWidgets import QAction, QListWidget, QMenu, QTreeWidget, QTreeWidgetItem +from PyQt5.QtCore import pyqtSignal, Qt, QPoint import DBA from logging import debug @@ -9,6 +9,10 @@ class PlaylistWidgetItem(QTreeWidgetItem): super().__init__([name], 0) self.id = id +# NOTE: ideas: +# auto sort list (alphabetical?) +# reorder list +# duplicate playlist class PlaylistsPane(QTreeWidget): playlistChoiceSignal = pyqtSignal(int) @@ -16,33 +20,57 @@ class PlaylistsPane(QTreeWidget): def __init__(self: QTreeWidget, parent=None): super().__init__(parent) - library_root = QTreeWidgetItem(["Library"]) - self.addTopLevelItem(library_root) + self._library_root = QTreeWidgetItem(["Library"]) + self.addTopLevelItem(self._library_root) # all_songs_branch = QTreeWidgetItem(["All Songs"]) # library_root.addChild(all_songs_branch) - self.playlists_root = QTreeWidgetItem(["Playlists"]) - self.addTopLevelItem(self.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]) - self.playlists_root.addChild(branch) - - library_root.setExpanded(True) - self.playlists_root.setExpanded(True) + self._playlists_root.addChild(branch) + # library_root.setExpanded(True) + self._playlists_root.setExpanded(True) + self.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) + self.customContextMenuRequested.connect(self.showContextMenu) self.currentItemChanged.connect(self.playlist_clicked) self.playlist_db_id_choice: int | None = None + def showContextMenu(self, position: QPoint): + """Right-click context menu""" + if self.playlist_db_id_choice is None: + return + # dont delete or rename the root nodes + menu = QMenu(self) + rename_action = QAction("Rename", self) + delete_action = QAction("Delete", self) + rename_action.triggered.connect(self.rename_playlist) + delete_action.triggered.connect(self.delete_playlist) + menu.addAction(rename_action) + menu.addAction(delete_action) + menu.exec_(self.mapToGlobal(position)) # Show the menu + + def rename_playlist(self, *args): + # TODO: implement this + pass + + def delete_playlist(self, *args): + # TODO: implement this + pass + def playlist_clicked(self, item): """Specific playlist index was clicked""" - if isinstance(item, PlaylistWidgetItem): + if item == self._playlists_root or item == self._library_root: + self.playlist_db_id_choice = None + self.all_songs_selected() + elif 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() == "library": - self.all_songs_selected() def all_songs_selected(self): """Emits a signal to display all songs in the library"""