2024-12-28 20:41:18 +01:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
2024-12-29 14:49:19 +01:00
|
|
|
from PyQt6.QtCore import Qt
|
|
|
|
from PyQt6.QtWidgets import QTabWidget, QTreeWidgetItem, QAbstractItemView
|
2024-12-28 20:41:18 +01:00
|
|
|
from player.playlist import Playlist
|
|
|
|
from ui.library_dock import LibraryDock
|
|
|
|
from ui.playlist import PlaylistView
|
|
|
|
|
|
|
|
|
|
|
|
class Library:
|
|
|
|
"""
|
|
|
|
Class that manages and syncs the library and library gui dock widgets.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, app):
|
|
|
|
self.app = app
|
|
|
|
|
|
|
|
self.main_library_dock = LibraryDock()
|
|
|
|
self.library_docks = [self.main_library_dock]
|
|
|
|
|
|
|
|
self.temporary_playlist = Playlist(self.app, "Temporary Playlist")
|
|
|
|
self.playlists = [self.temporary_playlist]
|
|
|
|
|
|
|
|
def create_playlist_views(self):
|
|
|
|
for library_dock in self.library_docks:
|
|
|
|
playlist_tabs: QTabWidget = library_dock.library.playlist_tabs
|
|
|
|
|
|
|
|
playlist_tabs.playlists = {}
|
|
|
|
|
|
|
|
for playlist in self.playlists:
|
|
|
|
playlist_view = self.create_playlist_view(playlist)
|
|
|
|
playlist_tabs.playlists[playlist.title] = playlist_view
|
|
|
|
playlist_tabs.addTab(playlist_view, playlist.title)
|
2024-12-29 14:31:21 +01:00
|
|
|
playlist_view.itemDoubleClicked.connect(self.on_track_doubleclick)
|
2024-12-28 20:41:18 +01:00
|
|
|
|
|
|
|
def create_playlist_view(self, playlist: Playlist):
|
|
|
|
view = PlaylistView()
|
2024-12-29 14:49:19 +01:00
|
|
|
view.setDragDropMode(QAbstractItemView.DragDropMode.InternalMove)
|
2024-12-28 20:41:18 +01:00
|
|
|
|
|
|
|
for track in playlist.tracks:
|
|
|
|
track_item = QTreeWidgetItem(view)
|
2024-12-29 14:49:19 +01:00
|
|
|
|
|
|
|
track_item.setFlags(
|
|
|
|
Qt.ItemFlag.ItemIsEnabled |
|
|
|
|
Qt.ItemFlag.ItemIsSelectable |
|
|
|
|
Qt.ItemFlag.ItemIsDragEnabled
|
|
|
|
)
|
|
|
|
|
2024-12-29 14:31:21 +01:00
|
|
|
track_item.track = track
|
2024-12-29 13:50:19 +01:00
|
|
|
track_item.setText(1, track.tags.title)
|
|
|
|
track_item.setText(2, track.tags.artist)
|
|
|
|
track_item.setText(3, track.tags.album)
|
2024-12-28 20:41:18 +01:00
|
|
|
|
|
|
|
return view
|
|
|
|
|
2024-12-29 14:31:21 +01:00
|
|
|
def on_track_doubleclick(self, item, column):
|
|
|
|
index = item.treeWidget().indexOfTopLevelItem(item)
|
|
|
|
self.app.player.play_track_in_playlist(index)
|
|
|
|
|