Added indicator icon that shows on the currently playing track.

This commit is contained in:
The Wobbler 2024-12-29 18:55:55 +01:00
parent 29cc80feae
commit efcae74382
5 changed files with 41 additions and 10 deletions

View file

@ -19,8 +19,9 @@ class GUICommunication:
self.settings.update_all() self.settings.update_all()
def on_track_start(self): def on_track_change(self, previous_track=None, track=None):
self.track_control.on_track_start() self.track_control.on_track_change(previous_track, track)
self.app.library.on_track_change(previous_track, track)
def on_playstate_update(self): def on_playstate_update(self):
self.track_control.on_playstate_update() self.track_control.on_playstate_update()

View file

@ -26,7 +26,7 @@ class TrackControl:
self.connect() self.connect()
self.on_track_start() self.on_track_change(None, None)
def connect(self): def connect(self):
self.track_control.previous_button.triggered.connect(self.previous_track) self.track_control.previous_button.triggered.connect(self.previous_track)
@ -52,9 +52,12 @@ class TrackControl:
if self.app.player.current_playlist.has_tracks(): if self.app.player.current_playlist.has_tracks():
self.app.player.seek(self.track_control.track_progress_slider.value()) 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: 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( self.track_control.track_progress_slider.setRange(
0, 0,

View file

@ -1,6 +1,7 @@
#!/usr/bin/python3 #!/usr/bin/python3
from PyQt6.QtCore import Qt from PyQt6.QtCore import Qt
from PyQt6.QtGui import QIcon
from PyQt6.QtWidgets import QTabWidget, QTreeWidgetItem, QAbstractItemView from PyQt6.QtWidgets import QTabWidget, QTreeWidgetItem, QAbstractItemView
from player.playlist import Playlist from player.playlist import Playlist
from ui.library_dock import LibraryDock from ui.library_dock import LibraryDock
@ -21,6 +22,8 @@ class Library:
self.temporary_playlist = Playlist(self.app, "Temporary Playlist") self.temporary_playlist = Playlist(self.app, "Temporary Playlist")
self.playlists = [self.temporary_playlist] self.playlists = [self.temporary_playlist]
self.play_icon = QIcon.fromTheme(QIcon.ThemeIcon.MediaPlaybackStart)
def create_playlist_views(self): def create_playlist_views(self):
for library_dock in self.library_docks: for library_dock in self.library_docks:
playlist_tabs: QTabWidget = library_dock.library.playlist_tabs playlist_tabs: QTabWidget = library_dock.library.playlist_tabs
@ -66,3 +69,19 @@ class Library:
index = item.treeWidget().indexOfTopLevelItem(item) index = item.treeWidget().indexOfTopLevelItem(item)
self.app.player.play_track_in_playlist(index) 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)

View file

@ -37,11 +37,12 @@ class Player:
def track_finished(self): def track_finished(self):
if not self.current_playlist.on_last_track(): 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.current_sound, self.current_sound_duration = self.current_playlist.next_track()
self.play() self.play()
self.track_progress.start() 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: else:
self.stop() self.stop()
@ -52,17 +53,21 @@ class Player:
self.play() self.play()
self.track_progress.start() 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() self.app.gui_communication.on_playstate_update()
def play_track_in_playlist(self, track_index): def play_track_in_playlist(self, track_index):
self.stop() self.stop()
previous_track = self.current_playlist.current_track
self.current_sound, self.current_sound_duration = self.current_playlist.set_track(track_index) self.current_sound, self.current_sound_duration = self.current_playlist.set_track(track_index)
self.play() self.play()
self.track_progress.start() 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): def pause(self):
self.music_channel.pause() self.music_channel.pause()
@ -90,6 +95,8 @@ class Player:
if not self.current_playlist.on_first_track(): if not self.current_playlist.on_first_track():
self.music_channel.stop() self.music_channel.stop()
last_track = self.current_playlist.current_track
self.current_sound, self.current_sound_duration = self.current_playlist.previous_track() self.current_sound, self.current_sound_duration = self.current_playlist.previous_track()
self.track_progress.stop() self.track_progress.stop()
@ -97,7 +104,7 @@ class Player:
self.play() self.play()
self.track_progress.start() 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): def stop(self):
self.music_channel.stop() self.music_channel.stop()

View file

@ -7,9 +7,10 @@ class PlaylistView(QTreeWidget):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.setColumnCount(3) self.setColumnCount(4)
headers = [ headers = [
"",
"#", "#",
"Title", "Title",
"Artist", "Artist",