Added loading of playlists to the process-dock.
This commit is contained in:
parent
6786a3dcd8
commit
301896e12c
4 changed files with 48 additions and 19 deletions
|
@ -56,8 +56,8 @@ class GUI:
|
|||
view = self.app.player.current_playlist.views[dock_id]
|
||||
view.on_track_change(previous_track, track)
|
||||
|
||||
def on_background_job_start(self, job: str):
|
||||
self.process_dock.job_started_signal.emit(job)
|
||||
def on_background_job_start(self, job_name: str, description: str, steps: int=0, getter: any=None):
|
||||
self.process_dock.job_started_signal.emit(job_name, description, steps, getter)
|
||||
|
||||
def on_background_job_stop(self, job: str):
|
||||
self.process_dock.on_background_job_stop(job)
|
||||
|
|
|
@ -161,11 +161,14 @@ class Player:
|
|||
track = self.current_playlist.tracks[self.current_playlist.current_track_index + 1]
|
||||
|
||||
if not track.cached:
|
||||
self.app.gui.on_background_job_start("track_caching")
|
||||
self.app.gui.on_background_job_start(
|
||||
"Loading Track",
|
||||
"Loading next track in the background so it starts immediately."
|
||||
)
|
||||
|
||||
track.cache()
|
||||
|
||||
self.app.gui.on_background_job_stop("track_caching")
|
||||
self.app.gui.on_background_job_stop("Loading Track")
|
||||
|
||||
def cache_next_track(self):
|
||||
# function that creates a thread which will cache the next track
|
||||
|
|
|
@ -40,9 +40,20 @@ class Playlist:
|
|||
self.current_track = None
|
||||
|
||||
def load_from_paths(self, paths):
|
||||
num_tracks = len(paths)
|
||||
|
||||
i = 0
|
||||
|
||||
while i < len(paths):
|
||||
process_title = f'Loading Playlist "{self.title}"'
|
||||
|
||||
self.app.gui.on_background_job_start(
|
||||
process_title,
|
||||
f'Loading the tracks of "{self.title}".',
|
||||
num_tracks,
|
||||
lambda: i
|
||||
)
|
||||
|
||||
while i < num_tracks:
|
||||
path = paths[i]
|
||||
|
||||
if os.path.isfile(path):
|
||||
|
@ -52,6 +63,8 @@ class Playlist:
|
|||
|
||||
self.loaded = True
|
||||
|
||||
self.app.gui.on_background_job_stop(process_title)
|
||||
|
||||
def load(self):
|
||||
loading_thread = threading.Thread(target=self.loading_thread)
|
||||
loading_thread.start()
|
||||
|
@ -79,9 +92,19 @@ class Playlist:
|
|||
lines = m3u.split("\n") # m3u entries are separated by newlines
|
||||
lines = lines[:-1] # remove last entry because it is just an empty string
|
||||
|
||||
i = 0
|
||||
num_lines = len(lines)
|
||||
|
||||
i = 0
|
||||
|
||||
process_title = f'Loading Playlist "{self.title}"'
|
||||
|
||||
self.app.gui.on_background_job_start(
|
||||
process_title,
|
||||
f'Loading the tracks of "{self.title}".',
|
||||
num_lines,
|
||||
lambda: i
|
||||
)
|
||||
|
||||
while i < num_lines:
|
||||
line = lines[i]
|
||||
|
||||
|
@ -100,6 +123,8 @@ class Playlist:
|
|||
|
||||
self.loaded = True
|
||||
|
||||
self.app.gui.on_background_job_stop(process_title)
|
||||
|
||||
def load_from_wbz(self, path):
|
||||
self.load_from_m3u(path) # placeholder
|
||||
|
||||
|
|
|
@ -5,14 +5,14 @@ from PyQt6.QtWidgets import QWidget, QDockWidget, QScrollArea, QVBoxLayout
|
|||
|
||||
from .process import BackgroundProcess
|
||||
|
||||
PROGRESS_UPDATE_RATE = 30
|
||||
PROGRESS_UPDATE_RATE = 10
|
||||
PROGRESS_UPDATE_INTERVAL = 1000 // PROGRESS_UPDATE_RATE
|
||||
|
||||
|
||||
class ProcessDock(QDockWidget):
|
||||
# we need a signal for self.on_background_job_start() because PyQt6 doesn't allow some operations to be performed
|
||||
# from a different thread
|
||||
job_started_signal = pyqtSignal(str)
|
||||
job_started_signal = pyqtSignal(str, str, int, object)
|
||||
|
||||
def __init__(self, app, parent=None):
|
||||
super().__init__(parent)
|
||||
|
@ -54,17 +54,18 @@ class ProcessDock(QDockWidget):
|
|||
for process in self.processes.values():
|
||||
process.update_progress()
|
||||
|
||||
def on_background_job_start(self, job):
|
||||
match job:
|
||||
case "track_caching":
|
||||
self.add_process(
|
||||
job,
|
||||
BackgroundProcess(
|
||||
"Loading Track",
|
||||
self.process_container,
|
||||
"Loading next track in the background so it starts immediately."
|
||||
)
|
||||
)
|
||||
def on_background_job_start(self, job_title: str, description: str, steps: int, getter):
|
||||
process = BackgroundProcess(
|
||||
job_title,
|
||||
self.process_container,
|
||||
description,
|
||||
steps
|
||||
)
|
||||
|
||||
if getter is not None:
|
||||
process.get_progress = getter
|
||||
|
||||
self.add_process(job_title, process)
|
||||
|
||||
def on_background_job_stop(self, job):
|
||||
if job in self.processes:
|
||||
|
|
Loading…
Add table
Reference in a new issue