2025-02-21 17:26:47 +01:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
from PyQt6.QtGui import QPixmap, QFont
|
|
|
|
from PyQt6.QtWidgets import QToolBar, QWidget, QLabel, QSizePolicy, QVBoxLayout
|
|
|
|
|
|
|
|
|
|
|
|
class TrackInfo(QToolBar):
|
|
|
|
title_font = QFont()
|
|
|
|
title_font.setPointSize(16)
|
|
|
|
title_font.setBold(True)
|
|
|
|
|
|
|
|
artist_font = QFont()
|
|
|
|
title_font.setPointSize(12)
|
|
|
|
|
|
|
|
album_font = QFont()
|
|
|
|
album_font.setPointSize(8)
|
|
|
|
|
|
|
|
def __init__(self, app, parent=None):
|
|
|
|
super().__init__(parent)
|
|
|
|
|
|
|
|
self.app = app
|
|
|
|
|
|
|
|
self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
|
|
|
|
|
|
|
|
self.wobuzz_logo = QPixmap(f"{self.app.utils.wobuzz_location}/icon.svg")
|
|
|
|
|
|
|
|
self.track_cover = QLabel(self)
|
|
|
|
self.track_cover.setFixedSize(64, 64)
|
|
|
|
self.track_cover.setScaledContents(True)
|
|
|
|
self.track_cover.setPixmap(self.wobuzz_logo)
|
|
|
|
self.addWidget(self.track_cover)
|
|
|
|
|
|
|
|
self.info_container = QWidget(self)
|
|
|
|
info_container_layout = QVBoxLayout(self.info_container)
|
|
|
|
self.info_container.setLayout(info_container_layout)
|
|
|
|
self.addWidget(self.info_container)
|
|
|
|
|
|
|
|
self.title = QLabel("Title", self.info_container)
|
|
|
|
self.title.setFont(self.title_font)
|
|
|
|
info_container_layout.addWidget(self.title)
|
|
|
|
|
|
|
|
self.artist = QLabel("Artist", self.info_container)
|
|
|
|
self.artist.setFont(self.artist_font)
|
|
|
|
info_container_layout.addWidget(self.artist)
|
|
|
|
|
|
|
|
self.album = QLabel("Album", self.info_container)
|
|
|
|
self.album.setFont(self.album_font)
|
|
|
|
info_container_layout.addWidget(self.album)
|
|
|
|
|
|
|
|
def update_info(self):
|
|
|
|
current_playlist = self.app.player.current_playlist
|
|
|
|
|
|
|
|
if current_playlist is not None:
|
|
|
|
current_track = current_playlist.current_track
|
|
|
|
title = current_track.tags.title
|
|
|
|
artist = current_track.tags.artist
|
|
|
|
album = current_track.tags.album
|
|
|
|
|
|
|
|
self.title.setText(title)
|
|
|
|
|
|
|
|
if artist is not None and not artist == "":
|
|
|
|
self.artist.setText(f"By {current_track.tags.artist}")
|
|
|
|
|
|
|
|
else:
|
|
|
|
self.artist.setText("No Artist")
|
|
|
|
|
|
|
|
if album is not None and not album == "":
|
|
|
|
self.album.setText(f"In {current_track.tags.album}")
|
|
|
|
|
|
|
|
else:
|
|
|
|
self.album.setText("No Album")
|
|
|
|
|
2025-02-21 20:37:24 +01:00
|
|
|
cover = current_track.tags.images.any
|
|
|
|
|
|
|
|
if cover is None:
|
|
|
|
self.track_cover.setPixmap(self.wobuzz_logo)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
cover_data = cover.data
|
|
|
|
|
2025-02-21 17:26:47 +01:00
|
|
|
if isinstance(cover_data, bytes):
|
|
|
|
cover_pixmap = QPixmap()
|
|
|
|
cover_pixmap.loadFromData(cover_data)
|
|
|
|
|
|
|
|
self.track_cover.setPixmap(cover_pixmap)
|
|
|
|
|
|
|
|
else:
|
|
|
|
self.track_cover.setPixmap(self.wobuzz_logo)
|
|
|
|
|
|
|
|
|