playlist tree right click context menu
This commit is contained in:
parent
7feb69db7b
commit
e78fb918b5
@ -25,7 +25,7 @@ class AlbumArtGraphicsView(QGraphicsView):
|
|||||||
Displays the album art of the currently playing song
|
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)
|
albumArtDropped = pyqtSignal(str)
|
||||||
# delete will only delete album art for current song
|
# delete will only delete album art for current song
|
||||||
albumArtDeleted = pyqtSignal()
|
albumArtDeleted = pyqtSignal()
|
||||||
@ -81,23 +81,21 @@ class AlbumArtGraphicsView(QGraphicsView):
|
|||||||
|
|
||||||
def showContextMenu(self, position: QPoint):
|
def showContextMenu(self, position: QPoint):
|
||||||
"""Handles showing a context menu when right clicking the album art"""
|
"""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
|
copy_action = QAction("Copy", self) # Add the actions
|
||||||
pasteAction = QAction("Paste", self)
|
paste_action = QAction("Paste", self)
|
||||||
deleteAction = QAction("Delete", self)
|
delete_action = QAction("Delete", self)
|
||||||
|
|
||||||
copyAction.triggered.connect(
|
copy_action.triggered.connect(self.copy_album_art_to_clipboard)
|
||||||
self.copy_album_art_to_clipboard
|
paste_action.triggered.connect(self.paste_album_art_from_clipboard)
|
||||||
) # Add the signal triggers
|
delete_action.triggered.connect(self.delete_album_art)
|
||||||
pasteAction.triggered.connect(self.paste_album_art_from_clipboard)
|
|
||||||
deleteAction.triggered.connect(self.delete_album_art)
|
|
||||||
|
|
||||||
contextMenu.addAction(copyAction) # Add actions to the menu
|
menu.addAction(copy_action) # Add actions to the menu
|
||||||
contextMenu.addAction(pasteAction)
|
menu.addAction(paste_action)
|
||||||
contextMenu.addAction(deleteAction)
|
menu.addAction(delete_action)
|
||||||
# DO
|
# 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:
|
def load_album_art(self, album_art_data: bytes) -> None:
|
||||||
"""Displays the album art for the currently playing track in the GraphicsView"""
|
"""Displays the album art for the currently playing track in the GraphicsView"""
|
||||||
|
|||||||
@ -203,7 +203,7 @@ class MusicTable(QTableView):
|
|||||||
painter.drawRect(rect.adjusted(1, 1, -1, -1))
|
painter.drawRect(rect.adjusted(1, 1, -1, -1))
|
||||||
|
|
||||||
def contextMenuEvent(self, a0):
|
def contextMenuEvent(self, a0):
|
||||||
"""Right-click context menu for rows in Music Table"""
|
"""Right-click context menu"""
|
||||||
menu = QMenu(self)
|
menu = QMenu(self)
|
||||||
add_to_playlist_action = QAction("Add to playlist", self)
|
add_to_playlist_action = QAction("Add to playlist", self)
|
||||||
add_to_playlist_action.triggered.connect(self.add_selected_files_to_playlist)
|
add_to_playlist_action.triggered.connect(self.add_selected_files_to_playlist)
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from PyQt5.QtWidgets import QListWidget, QTreeWidget, QTreeWidgetItem
|
from PyQt5.QtWidgets import QAction, QListWidget, QMenu, QTreeWidget, QTreeWidgetItem
|
||||||
from PyQt5.QtCore import pyqtSignal
|
from PyQt5.QtCore import pyqtSignal, Qt, QPoint
|
||||||
import DBA
|
import DBA
|
||||||
from logging import debug
|
from logging import debug
|
||||||
|
|
||||||
@ -9,6 +9,10 @@ class PlaylistWidgetItem(QTreeWidgetItem):
|
|||||||
super().__init__([name], 0)
|
super().__init__([name], 0)
|
||||||
self.id = id
|
self.id = id
|
||||||
|
|
||||||
|
# NOTE: ideas:
|
||||||
|
# auto sort list (alphabetical?)
|
||||||
|
# reorder list
|
||||||
|
# duplicate playlist
|
||||||
|
|
||||||
class PlaylistsPane(QTreeWidget):
|
class PlaylistsPane(QTreeWidget):
|
||||||
playlistChoiceSignal = pyqtSignal(int)
|
playlistChoiceSignal = pyqtSignal(int)
|
||||||
@ -16,33 +20,57 @@ class PlaylistsPane(QTreeWidget):
|
|||||||
|
|
||||||
def __init__(self: QTreeWidget, parent=None):
|
def __init__(self: QTreeWidget, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
library_root = QTreeWidgetItem(["Library"])
|
self._library_root = QTreeWidgetItem(["Library"])
|
||||||
self.addTopLevelItem(library_root)
|
self.addTopLevelItem(self._library_root)
|
||||||
# all_songs_branch = QTreeWidgetItem(["All Songs"])
|
# all_songs_branch = QTreeWidgetItem(["All Songs"])
|
||||||
# library_root.addChild(all_songs_branch)
|
# library_root.addChild(all_songs_branch)
|
||||||
|
|
||||||
self.playlists_root = QTreeWidgetItem(["Playlists"])
|
self._playlists_root = QTreeWidgetItem(["Playlists"])
|
||||||
self.addTopLevelItem(self.playlists_root)
|
self.addTopLevelItem(self._playlists_root)
|
||||||
with DBA.DBAccess() as db:
|
with DBA.DBAccess() as db:
|
||||||
playlists = db.query("SELECT id, name FROM playlist;", ())
|
playlists = db.query("SELECT id, name FROM playlist;", ())
|
||||||
for playlist in playlists:
|
for playlist in playlists:
|
||||||
branch = PlaylistWidgetItem(self, playlist[0], playlist[1])
|
branch = PlaylistWidgetItem(self, playlist[0], playlist[1])
|
||||||
self.playlists_root.addChild(branch)
|
self._playlists_root.addChild(branch)
|
||||||
|
|
||||||
library_root.setExpanded(True)
|
|
||||||
self.playlists_root.setExpanded(True)
|
|
||||||
|
|
||||||
|
# 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.currentItemChanged.connect(self.playlist_clicked)
|
||||||
self.playlist_db_id_choice: int | None = None
|
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):
|
def playlist_clicked(self, item):
|
||||||
"""Specific playlist index was clicked"""
|
"""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)}")
|
debug(f"ID: {item.id}, name: {item.text(0)}")
|
||||||
self.playlist_db_id_choice = item.id
|
self.playlist_db_id_choice = item.id
|
||||||
self.playlistChoiceSignal.emit(int(item.id))
|
self.playlistChoiceSignal.emit(int(item.id))
|
||||||
elif item.text(0).lower() == "library":
|
|
||||||
self.all_songs_selected()
|
|
||||||
|
|
||||||
def all_songs_selected(self):
|
def all_songs_selected(self):
|
||||||
"""Emits a signal to display all songs in the library"""
|
"""Emits a signal to display all songs in the library"""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user