forked from trav/lintunes
Snapshot of the existing codebase before working through the TASKS.md backlog. Real library data (data/) and the iTunes import fixture (itunes-test-library/) are gitignored.
37 lines
1.5 KiB
Python
37 lines
1.5 KiB
Python
from PyQt6.QtWidgets import QWidget, QApplication
|
|
from PyQt6.QtCore import Qt
|
|
from PyQt6.QtGui import QPainter, QPixmap
|
|
|
|
|
|
class ArtWindow(QWidget):
|
|
"""Non-modal window showing the current track's album art as large as
|
|
possible. Just an album art window — closing it has no side effects."""
|
|
|
|
def __init__(self, parent=None):
|
|
super().__init__(parent, Qt.WindowType.Window)
|
|
self._pixmap: QPixmap | None = None
|
|
self.setMinimumSize(120, 120)
|
|
self.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose, False)
|
|
|
|
def set_artwork(self, pixmap: QPixmap | None, title: str):
|
|
self.setWindowTitle(title or "Album Art")
|
|
self._pixmap = pixmap
|
|
if pixmap is not None and not self.isVisible():
|
|
screen = QApplication.primaryScreen().availableGeometry()
|
|
width = min(pixmap.width(), int(screen.width() * 0.8))
|
|
height = min(pixmap.height(), int(screen.height() * 0.8))
|
|
self.resize(max(width, 240), max(height, 240))
|
|
self.update()
|
|
|
|
def paintEvent(self, event):
|
|
painter = QPainter(self)
|
|
painter.fillRect(self.rect(), Qt.GlobalColor.black)
|
|
if self._pixmap is None or self._pixmap.isNull():
|
|
return
|
|
scaled = self._pixmap.scaled(
|
|
self.size(), Qt.AspectRatioMode.KeepAspectRatio,
|
|
Qt.TransformationMode.SmoothTransformation)
|
|
x = (self.width() - scaled.width()) // 2
|
|
y = (self.height() - scaled.height()) // 2
|
|
painter.drawPixmap(x, y, scaled)
|