"""The small cast glyph under the volume slider. Click to disconnect.""" from PyQt6.QtCore import QSize, Qt from PyQt6.QtGui import QIcon from PyQt6.QtWidgets import QToolButton from lintunes.gui.icons import transport_icon HEIGHT = 18 class CastIndicator(QToolButton): """Shows what playback is coming out of, when it isn't this machine. Never hidden, even when nothing is connected. `setVisible(False)` would take it out of the layout's height budget, which lifts the volume slider the instant you connect and drops it again when you disconnect — so idle is a visible widget with an empty icon, holding its space. """ def __init__(self, parent=None): super().__init__(parent) self._connected = False self._device = "" self.setAutoRaise(True) self.setFocusPolicy(Qt.FocusPolicy.NoFocus) self.setFixedHeight(HEIGHT) self.setIconSize(QSize(HEIGHT, HEIGHT)) self._apply() def set_connected(self, connected: bool, device_name: str = ""): self._connected = bool(connected) self._device = device_name or "" self._apply() def refresh_theme(self): self._apply() def sizeHint(self) -> QSize: return QSize(HEIGHT + 6, HEIGHT) def _apply(self): if self._connected: self.setIcon(transport_icon( "cast_connected", self.palette().highlight().color())) name = self._device or "a Chromecast" self.setToolTip(f"Casting to {name} — click to stop") self.setCursor(Qt.CursorShape.PointingHandCursor) self.setEnabled(True) else: # Empty icon rather than a hidden widget: holds the slot open. self.setIcon(QIcon()) self.setToolTip("") self.setCursor(Qt.CursorShape.ArrowCursor) self.setEnabled(False)