Did some memory optimisation, moved some files and created a completely not tested gui class that will list an artist's tracks.
Made tracks return an already existing object when they get created with a path of an already existing track object.
This commit is contained in:
parent
9ae1704e4a
commit
7edaebc3c3
7 changed files with 77 additions and 4 deletions
|
@ -2,9 +2,10 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from PyQt6.QtWidgets import QTabWidget, QAbstractItemView
|
from PyQt6.QtWidgets import QTabWidget, QAbstractItemView
|
||||||
|
|
||||||
from ..player.playlist import Playlist
|
from ..player.playlist import Playlist
|
||||||
from ..ui.library import LibraryWidget
|
from ..ui.library.library import LibraryWidget
|
||||||
from ..ui.playlist import PlaylistView
|
from ..ui.playlist_view import PlaylistView
|
||||||
|
|
||||||
|
|
||||||
class Library:
|
class Library:
|
||||||
|
@ -18,9 +19,13 @@ class Library:
|
||||||
self.main_library_widget = LibraryWidget(self)
|
self.main_library_widget = LibraryWidget(self)
|
||||||
self.library_widgets = [self.main_library_widget]
|
self.library_widgets = [self.main_library_widget]
|
||||||
|
|
||||||
|
self.loaded_tracks = {} # dict of {track path: track}
|
||||||
|
|
||||||
self.playlists = []
|
self.playlists = []
|
||||||
self.temporary_playlist = None
|
self.temporary_playlist = None
|
||||||
|
|
||||||
|
self.artist_playlists = []
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
self.load_playlists()
|
self.load_playlists()
|
||||||
|
|
||||||
|
@ -77,6 +82,8 @@ class Library:
|
||||||
if self.app.player.current_playlist is not None:
|
if self.app.player.current_playlist is not None:
|
||||||
self.app.settings.latest_playlist = self.app.player.current_playlist.path
|
self.app.settings.latest_playlist = self.app.player.current_playlist.path
|
||||||
|
|
||||||
|
print(self.loaded_tracks)
|
||||||
|
|
||||||
def new_playlist(self):
|
def new_playlist(self):
|
||||||
playlist = Playlist(self.app, self.app.utils.unique_name("New Playlist"))
|
playlist = Playlist(self.app, self.app.utils.unique_name("New Playlist"))
|
||||||
playlist.loaded = True
|
playlist.loaded = True
|
||||||
|
@ -121,3 +128,11 @@ class Library:
|
||||||
def import_playlist(self, playlist_path: str):
|
def import_playlist(self, playlist_path: str):
|
||||||
self.open_playlist(playlist_path)
|
self.open_playlist(playlist_path)
|
||||||
|
|
||||||
|
def loaded_track(self, track_path: str):
|
||||||
|
"""
|
||||||
|
Returns either a loaded track with the given path or None if there is none.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if track_path in self.loaded_tracks:
|
||||||
|
return self.loaded_tracks[track_path]
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,9 @@ class Track:
|
||||||
self.app = app
|
self.app = app
|
||||||
self.path = path
|
self.path = path
|
||||||
|
|
||||||
|
# add self to loaded tracks to make sure that no other track object is created for this track
|
||||||
|
app.library.loaded_tracks[self.path] = self
|
||||||
|
|
||||||
if metadata is None:
|
if metadata is None:
|
||||||
# load metadata from audio file
|
# load metadata from audio file
|
||||||
tags = TinyTag.get(path, ignore_errors=True, duration=False)
|
tags = TinyTag.get(path, ignore_errors=True, duration=False)
|
||||||
|
@ -66,6 +69,18 @@ class Track:
|
||||||
if cache:
|
if cache:
|
||||||
self.cache()
|
self.cache()
|
||||||
|
|
||||||
|
def __new__(cls, app, path: str, cache: bool=False, metadata: TrackMetadata=None):
|
||||||
|
loaded_track = app.library.loaded_track(path)
|
||||||
|
|
||||||
|
if loaded_track is not None:
|
||||||
|
if cache:
|
||||||
|
loaded_track.cache()
|
||||||
|
|
||||||
|
return loaded_track
|
||||||
|
|
||||||
|
else:
|
||||||
|
return super().__new__(cls)
|
||||||
|
|
||||||
def set_occurrences(self):
|
def set_occurrences(self):
|
||||||
# set track item for every occurrence of track in a playlist
|
# set track item for every occurrence of track in a playlist
|
||||||
|
|
||||||
|
|
1
wobuzz/ui/library/__init__.py
Normal file
1
wobuzz/ui/library/__init__.py
Normal file
|
@ -0,0 +1 @@
|
||||||
|
#!/usr/bin/python3
|
42
wobuzz/ui/library/artist_view.py
Normal file
42
wobuzz/ui/library/artist_view.py
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
from PyQt6.QtWidgets import QTreeWidget, QAbstractItemView
|
||||||
|
|
||||||
|
from ..playlist_view import PlaylistView
|
||||||
|
|
||||||
|
|
||||||
|
class ArtistView(PlaylistView):
|
||||||
|
def __init__(self, playlist, library_widget, parent=None):
|
||||||
|
QTreeWidget.__init__(self, parent)
|
||||||
|
|
||||||
|
self.playlist = playlist
|
||||||
|
self.library_widget = library_widget
|
||||||
|
|
||||||
|
self.app = playlist.app
|
||||||
|
|
||||||
|
self.header = self.header()
|
||||||
|
self.header.setSectionsClickable(True)
|
||||||
|
self.header.setSortIndicatorShown(True)
|
||||||
|
|
||||||
|
playlist.views[id(self.library_widget)] = self # let the playlist know that this view exists
|
||||||
|
|
||||||
|
self.setSelectionMode(QAbstractItemView.SelectionMode.ExtendedSelection)
|
||||||
|
|
||||||
|
self.setColumnCount(3)
|
||||||
|
|
||||||
|
headers = [
|
||||||
|
"#",
|
||||||
|
"Title",
|
||||||
|
"Artist",
|
||||||
|
"Album",
|
||||||
|
]
|
||||||
|
|
||||||
|
self.setHeaderLabels(headers)
|
||||||
|
|
||||||
|
self.itemActivated.connect(self.on_track_activation)
|
||||||
|
self.header.sectionClicked.connect(self.on_header_click)
|
||||||
|
self.sort_signal.connect(self.sortItems)
|
||||||
|
|
||||||
|
def setDragDropMode(self, behavior):
|
||||||
|
pass # user should not be able to sort the playlist manually
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
from PyQt6.QtGui import QIcon
|
from PyQt6.QtGui import QIcon
|
||||||
from PyQt6.QtWidgets import QToolBox, QLabel, QToolButton
|
from PyQt6.QtWidgets import QToolBox, QLabel, QToolButton
|
||||||
from .playlist_tabs import PlaylistTabs
|
from wobuzz.ui.playlist_tabs import PlaylistTabs
|
||||||
|
|
||||||
|
|
||||||
class LibraryWidget(QToolBox):
|
class LibraryWidget(QToolBox):
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
from PyQt6.QtWidgets import QDockWidget
|
from PyQt6.QtWidgets import QDockWidget
|
||||||
from .library import LibraryWidget
|
from wobuzz.ui.library import LibraryWidget
|
||||||
|
|
||||||
|
|
||||||
class LibraryDock(QDockWidget):
|
class LibraryDock(QDockWidget):
|
Loading…
Add table
Reference in a new issue