forked from Wobbl/Wobuzz
Added a "track_info"-toolbar which shows an image found in the current audio file's metadata (usually the front-cover) and information about the currently playing track such as title and artist name.
This commit is contained in:
parent
ccda6b30c8
commit
39bd7e3167
5 changed files with 101 additions and 5 deletions
83
wobuzz/ui/track_info.py
Normal file
83
wobuzz/ui/track_info.py
Normal file
|
@ -0,0 +1,83 @@
|
|||
#!/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
|
||||
cover_data = current_track.tags.images.any.data
|
||||
|
||||
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")
|
||||
|
||||
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)
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue