Implemented editing of playlist.

(Changes aren't persistent.)
This commit is contained in:
The Wobbler 2025-01-25 18:04:46 +01:00
parent f0969d013d
commit cba4fd67fa
5 changed files with 37 additions and 12 deletions

View file

@ -34,8 +34,7 @@ class Player:
self.app.gui.track_control.on_playstate_update()
# cache next track so it immediately starts when the current track finishes
caching_thread = threading.Thread(target=self.cache_next_track)
caching_thread.start()
self.cache_next_track()
def track_finished(self):
if not self.current_playlist.on_last_track():
@ -127,7 +126,7 @@ class Player:
self.play()
self.track_progress.start()
def cache_next_track(self):
def caching_thread_function(self):
# cache the next track
# (usually run in separate thread)
if self.current_playlist.on_last_track():
@ -138,3 +137,7 @@ class Player:
if not track.cached:
track.cache()
def cache_next_track(self):
# function that creates a thread which will cache the next track
caching_thread = threading.Thread(target=self.caching_thread_function)
caching_thread.start()

View file

@ -22,7 +22,7 @@ class Playlist:
path = paths[i]
if os.path.isfile(path):
self.tracks.append(Track(self.app, i, path, cache=i==0)) # first track is cached
self.tracks.append(Track(self.app, path, cache=i==0)) # first track is cached
i += 1
@ -48,7 +48,7 @@ class Playlist:
continue
self.tracks.append(Track(self.app, i, line, cache=i==0)) # first track is cached
self.tracks.append(Track(self.app, line, cache=i==0)) # first track is cached
i += 1

View file

@ -18,9 +18,8 @@ class Track:
Class containing data for a track like file path, raw data...
"""
def __init__(self, app, index: int, path: str, property_string: str=None, cache: bool=False):
def __init__(self, app, path: str, property_string: str=None, cache: bool=False):
self.app = app
self.index_custom_sort = index
self.path = path
self.property_string = property_string

View file

@ -39,8 +39,23 @@ class PlaylistView(QTreeWidget):
self.itemActivated.connect(self.on_track_activation)
def update_track_numbers(self):
pass
def on_user_sort(self):
num_tracks = self.topLevelItemCount()
i = 0
while i < num_tracks:
track_item = self.topLevelItem(i)
track = track_item.track
track_item.index_user_sort = i
track_item.setText(5, str(i + 1))
self.playlist.tracks[i] = track
i += 1
self.app.player.cache_next_track()
def dropEvent(self, event: QDropEvent):
items = self.selectedItems() # dragged items are always selected items
@ -49,11 +64,17 @@ class PlaylistView(QTreeWidget):
super().dropEvent(event)
self.on_user_sort()
event.accept()
def load_tracks(self):
i = 0
for track in self.playlist.tracks:
track_item = TrackItem(track, self)
track_item = TrackItem(track, i, self)
i += 1
def on_track_activation(self, item, column):
index = self.indexOfTopLevelItem(item)

View file

@ -5,10 +5,12 @@ from PyQt6.QtWidgets import QTreeWidgetItem
class TrackItem(QTreeWidgetItem):
def __init__(self, track, parent=None):
def __init__(self, track, index, parent=None):
super().__init__(parent)
self.track = track
self.index_user_sort = index
track.item = self
self.setFlags(
@ -20,5 +22,5 @@ class TrackItem(QTreeWidgetItem):
self.setText(2, track.tags.title)
self.setText(3, track.tags.artist)
self.setText(4, track.tags.album)
self.setText(5, str(track.index_custom_sort + 1))
self.setText(5, str(self.index_user_sort + 1))