#!/usr/bin/python3 from PyQt6.QtWidgets import QTabWidget, QTreeWidgetItem 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) playlist_view.itemDoubleClicked.connect(self.on_track_doubleclick) def create_playlist_view(self, playlist: Playlist): view = PlaylistView() for track in playlist.tracks: track_item = QTreeWidgetItem(view) track_item.track = track track_item.setText(1, track.tags.title) track_item.setText(2, track.tags.artist) track_item.setText(3, track.tags.album) return view def on_track_doubleclick(self, item, column): index = item.treeWidget().indexOfTopLevelItem(item) self.app.player.play_track_in_playlist(index)