From efcae743820aa1ea1c3ba136bc1b8374e330a271 Mon Sep 17 00:00:00 2001 From: wobbl Date: Sun, 29 Dec 2024 18:55:55 +0100 Subject: [PATCH] Added indicator icon that shows on the currently playing track. --- wobuzz/gui_communication/gui_communication.py | 5 +++-- wobuzz/gui_communication/track_control.py | 9 ++++++--- wobuzz/library/library.py | 19 +++++++++++++++++++ wobuzz/player/player.py | 15 +++++++++++---- wobuzz/ui/playlist.py | 3 ++- 5 files changed, 41 insertions(+), 10 deletions(-) diff --git a/wobuzz/gui_communication/gui_communication.py b/wobuzz/gui_communication/gui_communication.py index 59d68b6..5ba88b2 100644 --- a/wobuzz/gui_communication/gui_communication.py +++ b/wobuzz/gui_communication/gui_communication.py @@ -19,8 +19,9 @@ class GUICommunication: self.settings.update_all() - def on_track_start(self): - self.track_control.on_track_start() + def on_track_change(self, previous_track=None, track=None): + self.track_control.on_track_change(previous_track, track) + self.app.library.on_track_change(previous_track, track) def on_playstate_update(self): self.track_control.on_playstate_update() diff --git a/wobuzz/gui_communication/track_control.py b/wobuzz/gui_communication/track_control.py index d66a24f..ccfc04c 100644 --- a/wobuzz/gui_communication/track_control.py +++ b/wobuzz/gui_communication/track_control.py @@ -26,7 +26,7 @@ class TrackControl: self.connect() - self.on_track_start() + self.on_track_change(None, None) def connect(self): self.track_control.previous_button.triggered.connect(self.previous_track) @@ -52,9 +52,12 @@ class TrackControl: if self.app.player.current_playlist.has_tracks(): self.app.player.seek(self.track_control.track_progress_slider.value()) - def on_track_start(self): + def on_track_change(self, previous_track, track): if self.app.player.playing: - duration = self.app.player.current_playlist.current_track.duration + duration = 0 + + if track: + duration = track.duration self.track_control.track_progress_slider.setRange( 0, diff --git a/wobuzz/library/library.py b/wobuzz/library/library.py index 18bd2f1..d3145c4 100644 --- a/wobuzz/library/library.py +++ b/wobuzz/library/library.py @@ -1,6 +1,7 @@ #!/usr/bin/python3 from PyQt6.QtCore import Qt +from PyQt6.QtGui import QIcon from PyQt6.QtWidgets import QTabWidget, QTreeWidgetItem, QAbstractItemView from player.playlist import Playlist from ui.library_dock import LibraryDock @@ -21,6 +22,8 @@ class Library: self.temporary_playlist = Playlist(self.app, "Temporary Playlist") self.playlists = [self.temporary_playlist] + self.play_icon = QIcon.fromTheme(QIcon.ThemeIcon.MediaPlaybackStart) + def create_playlist_views(self): for library_dock in self.library_docks: playlist_tabs: QTabWidget = library_dock.library.playlist_tabs @@ -66,3 +69,19 @@ class Library: index = item.treeWidget().indexOfTopLevelItem(item) self.app.player.play_track_in_playlist(index) + def get_track_tree_item(self, track): + index = self.app.player.current_playlist.tracks.index(track) + playlist_view = self.main_library_dock.library.playlist_tabs.playlists[self.app.player.current_playlist.title] + item = playlist_view.topLevelItem(index) + + return item + + def on_track_change(self, previous_track, track): + if previous_track: + item = self.get_track_tree_item(previous_track) + item.setIcon(0, QIcon(None)) + + if track: + item = self.get_track_tree_item(track) + item.setIcon(0, self.play_icon) + diff --git a/wobuzz/player/player.py b/wobuzz/player/player.py index f12a71a..7a437a3 100644 --- a/wobuzz/player/player.py +++ b/wobuzz/player/player.py @@ -37,11 +37,12 @@ class Player: def track_finished(self): if not self.current_playlist.on_last_track(): + previous_track = self.current_playlist.current_track self.current_sound, self.current_sound_duration = self.current_playlist.next_track() self.play() self.track_progress.start() - self.app.gui_communication.on_track_start() + self.app.gui_communication.on_track_change(previous_track, self.current_playlist.current_track) else: self.stop() @@ -52,17 +53,21 @@ class Player: self.play() self.track_progress.start() - self.app.gui_communication.on_track_start() + + self.app.gui_communication.on_track_change(None, self.current_playlist.current_track) + self.app.gui_communication.on_playstate_update() def play_track_in_playlist(self, track_index): self.stop() + previous_track = self.current_playlist.current_track + self.current_sound, self.current_sound_duration = self.current_playlist.set_track(track_index) self.play() self.track_progress.start() - self.app.gui_communication.on_track_start() + self.app.gui_communication.on_track_change(previous_track, self.current_playlist.current_track) def pause(self): self.music_channel.pause() @@ -90,6 +95,8 @@ class Player: if not self.current_playlist.on_first_track(): self.music_channel.stop() + last_track = self.current_playlist.current_track + self.current_sound, self.current_sound_duration = self.current_playlist.previous_track() self.track_progress.stop() @@ -97,7 +104,7 @@ class Player: self.play() self.track_progress.start() - self.app.gui_communication.on_track_start() + self.app.gui_communication.on_track_change(last_track, self.current_playlist.current_track) def stop(self): self.music_channel.stop() diff --git a/wobuzz/ui/playlist.py b/wobuzz/ui/playlist.py index 4ca1999..ce8a6d4 100644 --- a/wobuzz/ui/playlist.py +++ b/wobuzz/ui/playlist.py @@ -7,9 +7,10 @@ class PlaylistView(QTreeWidget): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self.setColumnCount(3) + self.setColumnCount(4) headers = [ + "", "#", "Title", "Artist",