Implemented editing of playlist.
(Changes aren't persistent.)
This commit is contained in:
parent
f0969d013d
commit
cba4fd67fa
5 changed files with 37 additions and 12 deletions
|
@ -34,8 +34,7 @@ class Player:
|
||||||
self.app.gui.track_control.on_playstate_update()
|
self.app.gui.track_control.on_playstate_update()
|
||||||
|
|
||||||
# cache next track so it immediately starts when the current track finishes
|
# cache next track so it immediately starts when the current track finishes
|
||||||
caching_thread = threading.Thread(target=self.cache_next_track)
|
self.cache_next_track()
|
||||||
caching_thread.start()
|
|
||||||
|
|
||||||
def track_finished(self):
|
def track_finished(self):
|
||||||
if not self.current_playlist.on_last_track():
|
if not self.current_playlist.on_last_track():
|
||||||
|
@ -127,7 +126,7 @@ class Player:
|
||||||
self.play()
|
self.play()
|
||||||
self.track_progress.start()
|
self.track_progress.start()
|
||||||
|
|
||||||
def cache_next_track(self):
|
def caching_thread_function(self):
|
||||||
# cache the next track
|
# cache the next track
|
||||||
# (usually run in separate thread)
|
# (usually run in separate thread)
|
||||||
if self.current_playlist.on_last_track():
|
if self.current_playlist.on_last_track():
|
||||||
|
@ -138,3 +137,7 @@ class Player:
|
||||||
if not track.cached:
|
if not track.cached:
|
||||||
track.cache()
|
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()
|
||||||
|
|
|
@ -22,7 +22,7 @@ class Playlist:
|
||||||
path = paths[i]
|
path = paths[i]
|
||||||
|
|
||||||
if os.path.isfile(path):
|
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
|
i += 1
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ class Playlist:
|
||||||
|
|
||||||
continue
|
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
|
i += 1
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,8 @@ class Track:
|
||||||
Class containing data for a track like file path, raw data...
|
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.app = app
|
||||||
self.index_custom_sort = index
|
|
||||||
self.path = path
|
self.path = path
|
||||||
self.property_string = property_string
|
self.property_string = property_string
|
||||||
|
|
||||||
|
|
|
@ -39,8 +39,23 @@ class PlaylistView(QTreeWidget):
|
||||||
|
|
||||||
self.itemActivated.connect(self.on_track_activation)
|
self.itemActivated.connect(self.on_track_activation)
|
||||||
|
|
||||||
def update_track_numbers(self):
|
def on_user_sort(self):
|
||||||
pass
|
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):
|
def dropEvent(self, event: QDropEvent):
|
||||||
items = self.selectedItems() # dragged items are always selected items
|
items = self.selectedItems() # dragged items are always selected items
|
||||||
|
@ -49,11 +64,17 @@ class PlaylistView(QTreeWidget):
|
||||||
|
|
||||||
super().dropEvent(event)
|
super().dropEvent(event)
|
||||||
|
|
||||||
|
self.on_user_sort()
|
||||||
|
|
||||||
event.accept()
|
event.accept()
|
||||||
|
|
||||||
def load_tracks(self):
|
def load_tracks(self):
|
||||||
|
i = 0
|
||||||
|
|
||||||
for track in self.playlist.tracks:
|
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):
|
def on_track_activation(self, item, column):
|
||||||
index = self.indexOfTopLevelItem(item)
|
index = self.indexOfTopLevelItem(item)
|
||||||
|
|
|
@ -5,10 +5,12 @@ from PyQt6.QtWidgets import QTreeWidgetItem
|
||||||
|
|
||||||
|
|
||||||
class TrackItem(QTreeWidgetItem):
|
class TrackItem(QTreeWidgetItem):
|
||||||
def __init__(self, track, parent=None):
|
def __init__(self, track, index, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
|
||||||
self.track = track
|
self.track = track
|
||||||
|
self.index_user_sort = index
|
||||||
|
|
||||||
track.item = self
|
track.item = self
|
||||||
|
|
||||||
self.setFlags(
|
self.setFlags(
|
||||||
|
@ -20,5 +22,5 @@ class TrackItem(QTreeWidgetItem):
|
||||||
self.setText(2, track.tags.title)
|
self.setText(2, track.tags.title)
|
||||||
self.setText(3, track.tags.artist)
|
self.setText(3, track.tags.artist)
|
||||||
self.setText(4, track.tags.album)
|
self.setText(4, track.tags.album)
|
||||||
self.setText(5, str(track.index_custom_sort + 1))
|
self.setText(5, str(self.index_user_sort + 1))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue