forked from trav/lintunes
Visualizer: gray-mode color slider + mode persists across launches
- New prefs: visualizer_mode (on/dim/off, saved on every click) and color_visualizer_gray (None = keep the derived alternateBase look). - VisualizerWidget takes prefs (optional, so existing call sites/tests keep working); restores its mode at startup and validates junk values. - New "Visualizer (gray mode):" row in the Preferences color sliders; theme.default_gray mirrors the widget's 0.88-lightness derivation so an untouched slider shows the current appearance. - TransportBar.refresh_theme() repaints the visualizer so slider drags preview live.
This commit is contained in:
@@ -19,6 +19,7 @@ _COLOR_ROWS = [
|
||||
("color_now_playing_bg", "Now-playing panel:"),
|
||||
("color_now_playing_text", "Now-playing text:"),
|
||||
("color_stripe", "Stripes:"),
|
||||
("color_visualizer_gray", "Visualizer (gray mode):"),
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -255,7 +255,7 @@ class TransportBar(QWidget):
|
||||
layout.addWidget(shuffle_box)
|
||||
|
||||
layout.addSpacing(10)
|
||||
self._visualizer = VisualizerWidget(player)
|
||||
self._visualizer = VisualizerWidget(player, prefs)
|
||||
self._visualizer.setFixedHeight(CONTROL_HEIGHT)
|
||||
layout.addWidget(self._visualizer)
|
||||
layout.addSpacing(10)
|
||||
@@ -359,6 +359,7 @@ class TransportBar(QWidget):
|
||||
box.setStyleSheet(_box_style(box_bg))
|
||||
self._apply_now_playing_bg()
|
||||
self._apply_now_playing_font()
|
||||
self._visualizer.update() # dim-mode bar color may have changed
|
||||
|
||||
def _apply_now_playing_bg(self):
|
||||
bg = theme.gray(theme.gray_value(self._prefs, "color_now_playing_bg"))
|
||||
|
||||
@@ -11,6 +11,8 @@ from PyQt6.QtCore import Qt, QTimer, QRectF
|
||||
from PyQt6.QtGui import QPainter, QColor, QPainterPath, QPen
|
||||
from PyQt6.QtMultimedia import QAudioFormat
|
||||
|
||||
from lintunes import theme
|
||||
|
||||
|
||||
BANDS = 20
|
||||
STEPS = 20 # vertical granularity per bar
|
||||
@@ -41,10 +43,12 @@ class VisualizerWidget(QWidget):
|
||||
panel; off = blank.
|
||||
"""
|
||||
|
||||
def __init__(self, player, parent=None):
|
||||
def __init__(self, player, prefs=None, parent=None):
|
||||
super().__init__(parent)
|
||||
self._player = player
|
||||
self._mode = MODE_ON
|
||||
self._prefs = prefs
|
||||
saved = prefs.get("visualizer_mode") if prefs is not None else None
|
||||
self._mode = saved if saved in _MODE_CYCLE else MODE_ON
|
||||
self._levels = np.zeros(BANDS)
|
||||
self._bars = [0] * BANDS # quantized 0..STEPS
|
||||
self._samples = np.zeros(FFT_SIZE, dtype=np.float32)
|
||||
@@ -113,6 +117,8 @@ class VisualizerWidget(QWidget):
|
||||
# Cycle on -> dim -> off -> on.
|
||||
idx = _MODE_CYCLE.index(self._mode)
|
||||
self._mode = _MODE_CYCLE[(idx + 1) % len(_MODE_CYCLE)]
|
||||
if self._prefs is not None:
|
||||
self._prefs.set("visualizer_mode", self._mode)
|
||||
if self._mode == MODE_OFF:
|
||||
self._timer.stop()
|
||||
self._clear() # off = blank, not the last frame held in place
|
||||
@@ -150,6 +156,10 @@ class VisualizerWidget(QWidget):
|
||||
|
||||
def _bar_color(self):
|
||||
if self._mode == MODE_DIM:
|
||||
if self._prefs is not None:
|
||||
saved = self._prefs.get("color_visualizer_gray")
|
||||
if saved is not None:
|
||||
return theme.gray(saved)
|
||||
# Light gray just darker than the panel: take alternateBase and
|
||||
# drop its lightness ~12% so it tracks theme/scale changes.
|
||||
base = QColor(self.palette().alternateBase().color())
|
||||
|
||||
@@ -11,6 +11,7 @@ DEFAULTS = {
|
||||
"now_playing_font": None, # None=prefer Century Gothic, ""=use app
|
||||
# default, "Family"=use app
|
||||
"volume": 0.8, # logical 0..1 master output volume
|
||||
"visualizer_mode": "on", # on (color) | dim (gray) | off — click cycle
|
||||
# Per-area grayscale overrides (0=black .. 255=white). None = inherit the
|
||||
# current/default look for that surface, so nothing changes until the user
|
||||
# drags a slider in Preferences.
|
||||
@@ -19,6 +20,7 @@ DEFAULTS = {
|
||||
"color_now_playing_bg": None, # panel behind the now-playing text
|
||||
"color_now_playing_text": None, # the now-playing title/artist text
|
||||
"color_stripe": None, # alternating row stripes (QPalette.AlternateBase)
|
||||
"color_visualizer_gray": None, # visualizer bars in dim (gray) mode
|
||||
"lastfm": {
|
||||
"api_key": "",
|
||||
"api_secret": "",
|
||||
|
||||
+11
-1
@@ -70,7 +70,17 @@ def default_gray(key: str) -> int:
|
||||
current appearance, so showing the slider doesn't imply a change."""
|
||||
if key in _FIXED_GRAY_DEFAULT:
|
||||
return _FIXED_GRAY_DEFAULT[key]
|
||||
color = _base().color(QPalette.ColorGroup.Active, _PALETTE_GRAY_ROLE[key])
|
||||
if key == "color_visualizer_gray":
|
||||
# Dim-mode bars derive from alternateBase dropped ~12% in lightness
|
||||
# (see VisualizerWidget._bar_color); mirror that so the slider shows
|
||||
# the current appearance.
|
||||
color = _base().color(QPalette.ColorGroup.Active,
|
||||
QPalette.ColorRole.AlternateBase)
|
||||
h, s, l, a = color.getHslF()
|
||||
color.setHslF(h, s, l * 0.88, a)
|
||||
else:
|
||||
color = _base().color(QPalette.ColorGroup.Active,
|
||||
_PALETTE_GRAY_ROLE[key])
|
||||
return round(0.299 * color.red() + 0.587 * color.green()
|
||||
+ 0.114 * color.blue())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user