diff --git a/CLAUDE.md b/CLAUDE.md index f407e42..9448a81 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -294,6 +294,15 @@ persistence) → GUI (Qt widgets that read the manager and connect to its signal The laser page draws the rig (`gui/laser_diagram.py`, textbook line art through the renderer's own `_rotation`); it labels distance, angles and dot size, so those sliders show no number. + **Dark mode** (Round 101, Preferences › Appearance): `theme.mode(prefs)` + picks a whole palette (`_dark_palette`, every role) in dark, or the + base palette plus overrides in light. Each mode has its own gray sliders + (dark's are `dark_`, light keeps the original keys) and a tint + (`tint_color`/`tint_level`, `dark_…`): the gray's lightness with the + tint's hue at level × its saturation, on every surface but text. Paint + surfaces with `theme.surface(prefs, key)`, glyphs with + `theme.icon_gray()` and button text with `theme.text_color()` — a + hardcoded black/#4A4A4A vanishes in dark. The highlight is shared. The highlight swatches can be repainted with a color picker: `highlight_palette` overrides a slot, and `theme.highlight_color` reads through `theme.highlight_palette`, so nothing else needs to know. diff --git a/lintunes/__init__.py b/lintunes/__init__.py index 2f63ee8..caff63c 100644 --- a/lintunes/__init__.py +++ b/lintunes/__init__.py @@ -1,3 +1,3 @@ """LinTunes — iTunes-style music library manager and player for Linux.""" -__version__ = "0.68.0" +__version__ = "0.69.0" diff --git a/lintunes/gui/preferences_dialog.py b/lintunes/gui/preferences_dialog.py index bf4f9fc..a1e0511 100644 --- a/lintunes/gui/preferences_dialog.py +++ b/lintunes/gui/preferences_dialog.py @@ -32,6 +32,7 @@ _COLOR_ROWS = [ ("color_now_playing_bg", "Now-playing panel:"), ("color_now_playing_text", "Now-playing text:"), ("color_stripe", "Stripes:"), + ("color_base", "Lists:"), ("color_visualizer_gray", "Visualizer (gray mode):"), ] @@ -387,6 +388,15 @@ class PreferencesDialog(QDialog): size_row.addStretch() form.addRow("UI size:", size_row) + self._dark_check = QCheckBox("Dark mode") + self._dark_check.setToolTip("Dark mode has its own colors and tint " + "(Colors, below); the highlight is shared") + self._dark_check.setChecked(theme.mode(self._prefs) == "dark") + self._dark_check.toggled.connect(self._on_dark_toggled) + form.addRow("Mode:", self._dark_check) + # The toolbar's light/dark button flips the same pref while this is open. + self._prefs.changed.connect(self._sync_dark_check) + # Highlight color: a radio per slot, and beside it the slot's swatch, # which opens a full color picker; the color picked replaces that # slot's (right-click the swatch to put the original back). @@ -940,27 +950,112 @@ class PreferencesDialog(QDialog): self._prefs.set("visualizer_style", key) def _build_colors_group(self) -> QGroupBox: + """Light and dark each have a tint and a full set of grays; the + Light | Dark switch picks which set the controls show and edit, and + every control moves to that set's saved values.""" group = QGroupBox("Colors") form = QFormLayout(group) - note = QLabel("Each slider runs black → white and updates instantly.") + note = QLabel("Each gray runs black → white and updates instantly. " + "The tint colors every gray but text, by the tint level.") note.setWordWrap(True) form.addRow(note) + switch = QHBoxLayout() + switch.setSpacing(0) + self._color_mode_group = QButtonGroup(self) + self._color_mode_buttons = {} + for which in theme.MODES: + button = QPushButton(which.capitalize()) + button.setCheckable(True) + button.setProperty("tile", "first" if which == "light" else "last") + self._color_mode_group.addButton(button) + self._color_mode_buttons[which] = button + switch.addWidget(button) + button.toggled.connect( + lambda on, w=which: on and self._edit_colors_of(w)) + switch.addStretch() + form.addRow("Editing:", switch) + + self._editing = theme.mode(self._prefs) + tint_row = QHBoxLayout() + self._tint_swatch = QToolButton() + self._tint_swatch.setAutoRaise(True) + self._tint_swatch.setToolTip("Choose the tint color") + self._tint_swatch.clicked.connect(self._choose_tint) + self._tint_slider = QSlider(Qt.Orientation.Horizontal) + self._tint_slider.setRange(0, 100) + self._tint_label = QLabel("") + self._tint_label.setMinimumWidth(36) + self._tint_slider.valueChanged.connect(self._on_tint_level) + tint_row.addWidget(self._tint_swatch) + tint_row.addWidget(self._tint_slider, stretch=1) + tint_row.addWidget(self._tint_label) + form.addRow("Tint:", tint_row) + self._color_sliders = {} for key, label in _COLOR_ROWS: slider = QSlider(Qt.Orientation.Horizontal) slider.setRange(0, 255) - slider.setValue(theme.gray_value(self._prefs, key)) # before connect slider.valueChanged.connect( lambda value, k=key: self._on_color_changed(k, value)) self._color_sliders[key] = slider form.addRow(label, slider) + self._color_mode_buttons[self._editing].setChecked(True) + self._show_color_values() return group + def _edit_colors_of(self, which: str): + if which != self._editing: + self._editing = which + self._show_color_values() + + def _show_color_values(self): + """Move every control to the edited mode's saved values, without + writing anything.""" + which = self._editing + for key, slider in self._color_sliders.items(): + slider.blockSignals(True) + slider.setValue(theme.gray_value(self._prefs, key, which)) + slider.blockSignals(False) + color, level = theme.tint(self._prefs, which) + self._tint_swatch.setIcon(theme.swatch_icon(color.name())) + self._tint_slider.blockSignals(True) + self._tint_slider.setValue(round(level * 100)) + self._tint_slider.blockSignals(False) + self._tint_label.setText(f"{round(level * 100)} %") + def _on_color_changed(self, key: str, value: int): - self._prefs.set_live(key, value) # live preview, no disk write yet + self._prefs.set_live(theme.mode_key(key, self._editing), value) self._color_save_timer.start() # persist once the drag settles + def _on_tint_level(self, value: int): + self._tint_label.setText(f"{value} %") + self._prefs.set_live(theme.mode_key("tint_level", self._editing), value) + self._color_save_timer.start() + + def _choose_tint(self): + which = self._editing + current, _level = theme.tint(self._prefs, which) + color = QColorDialog.getColor(current, self, "Tint color") + if not color.isValid(): + return + self._prefs.set(theme.mode_key("tint_color", which), color.name()) + if self._tint_slider.value() == 0: + self._tint_slider.setValue(20) # a tint at 0 % would show nothing + self._show_color_values() + + def _on_dark_toggled(self, on: bool): + self._prefs.set("dark_mode", on) + self._color_mode_buttons["dark" if on else "light"].setChecked(True) + + def _sync_dark_check(self): + on = theme.mode(self._prefs) == "dark" + if self._dark_check.isChecked() != on: + self._dark_check.blockSignals(True) + self._dark_check.setChecked(on) + self._dark_check.blockSignals(False) + self._color_mode_buttons["dark" if on else "light"].setChecked(True) + # ---- Last.fm ---- def _build_lastfm_group(self) -> QGroupBox: diff --git a/lintunes/gui/transport.py b/lintunes/gui/transport.py index 6fa0843..20643fc 100644 --- a/lintunes/gui/transport.py +++ b/lintunes/gui/transport.py @@ -15,7 +15,7 @@ from lintunes.player import REPEAT_MODES from lintunes import theme -ICON_GRAY = QColor("#4A4A4A") +ICON_GRAY = QColor("#4A4A4A") # light mode's; theme.icon_gray() follows the mode # Breathing room between the menu bar and the row of boxes. TOP_MARGIN = 9 @@ -54,7 +54,12 @@ def _box_style(bg: QColor) -> str: for kind in ("QToolButton", "QPushButton"): face += (f"QFrame#transportBox > {kind}:disabled {{ background:" f" {bg.lighter(104).name()}; border-color: {bg.darker(112).name()}; }}") - return face + TILE_STYLE + text = theme.text_color().name() + return face + TILE_STYLE + f""" +QFrame#transportBox QPushButton, QFrame#transportBox QPushButton:disabled {{ + color: {text}; +}} +""" # Where tiles meet: square corners, and one shared line (the later tile @@ -66,11 +71,7 @@ TILE_STYLE = "".join( ("first", "border-top-right-radius: 0; border-bottom-right-radius: 0;"), ("middle", "border-radius: 0; border-left: none;"), ("last", "border-top-left-radius: 0; border-bottom-left-radius: 0;" - " border-left: none;"))) + """ -QFrame#transportBox QPushButton, QFrame#transportBox QPushButton:disabled { - color: black; -} -""" + " border-left: none;"))) def _nowplaying_style(bg: QColor) -> str: @@ -142,9 +143,10 @@ class FlashButton(QToolButton): def _apply_icon(self, active: bool = False): show_active = active or (self.isCheckable() and self.isChecked()) - color = self.palette().highlight().color() if show_active else ICON_GRAY + rest = theme.icon_gray() + color = self.palette().highlight().color() if show_active else rest if not self.isEnabled(): - color = QColor(ICON_GRAY).lighter(160) + color = rest.lighter(160) if not theme.is_dark() else rest.darker(180) self.setIcon(transport_icon(self._kind, color)) @@ -439,7 +441,7 @@ class TransportBar(QWidget): # Rounded button boxes carry a user-tunable grayscale fill, decoupled # from the stripe color they used to share via palette(alternate-base). self._boxes = [] - box_bg = theme.gray(theme.gray_value(prefs, "color_button")) + box_bg = theme.surface(prefs, "color_button") self._prev_btn = FlashButton("previous") self._play_btn = FlashButton("play") @@ -581,7 +583,7 @@ class TransportBar(QWidget): self.dj_button.setObjectName("djButton") self.dj_button.setCheckable(True) self.dj_button.setToolTip("DJ mode") - self.dj_button.setIcon(turntable_icon(QColor(ICON_GRAY), 22)) + self.dj_button.setIcon(turntable_icon(theme.icon_gray(), 22)) self.dj_button.setIconSize(QSize(30, 22)) self.dj_button.setFocusPolicy(Qt.FocusPolicy.NoFocus) self.dj_button.setFixedWidth(52) @@ -635,10 +637,10 @@ class TransportBar(QWidget): def _apply_dj_button_style(self): """The bpm button under the DJ box wears the shared face (radius 8); the DJ button is styled by its box like shuffle and repeat.""" - bg = theme.gray(theme.gray_value(self._prefs, "color_button")) + bg = theme.surface(self._prefs, "color_button") self._bpm_button.setStyleSheet(theme.button_face_qss( "QPushButton#bpmHeader", bg, radius=8, - extra="padding: 0; color: black;")) + extra=f"padding: 0; color: {theme.text_color().name()};")) def _on_dj_button(self, on: bool): self._on_dj_button_icon(on) @@ -671,7 +673,7 @@ class TransportBar(QWidget): self._on_track_changed(self._current_track) def _on_dj_button_icon(self, on: bool): - color = self.palette().highlight().color() if on else QColor(ICON_GRAY) + color = self.palette().highlight().color() if on else theme.icon_gray() self.dj_button.setIcon(turntable_icon(color, 22)) def volume_level(self) -> float: @@ -787,16 +789,17 @@ class TransportBar(QWidget): for button in (self._prev_btn, self._play_btn, self._next_btn, self._shuffle_btn, self._repeat_btn): button.refresh_icons() - box_bg = theme.gray(theme.gray_value(self._prefs, "color_button")) + box_bg = theme.surface(self._prefs, "color_button") for box in self._boxes: box.setStyleSheet(_box_style(box_bg)) self._apply_now_playing_bg() self._apply_now_playing_font() self._apply_dj_button_style() + self._on_dj_button_icon(self.dj_button.isChecked()) 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")) + bg = theme.surface(self._prefs, "color_now_playing_bg") self._now_playing.setStyleSheet(_nowplaying_style(bg)) def _on_volume_changed(self, value: int): diff --git a/lintunes/gui/visualizer.py b/lintunes/gui/visualizer.py index a40eeb4..b9c381c 100644 --- a/lintunes/gui/visualizer.py +++ b/lintunes/gui/visualizer.py @@ -483,9 +483,10 @@ class VisualizerWidget(QWidget): def _gray(self): """Dim mode's color.""" if self._prefs is not None: - saved = self._prefs.get("color_visualizer_gray") - if saved is not None: - return theme.gray(saved) + which = theme.mode(self._prefs) + saved = self._prefs.get(theme.mode_key("color_visualizer_gray", which)) + if saved is not None or which == "dark": + return theme.surface(self._prefs, "color_visualizer_gray") # 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()) diff --git a/lintunes/preferences.py b/lintunes/preferences.py index e09baa8..609e7ce 100644 --- a/lintunes/preferences.py +++ b/lintunes/preferences.py @@ -47,6 +47,14 @@ DEFAULTS = { "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 + "color_base": None, # the lists' background (QPalette.Base) + # Dark mode (Round 101): the same sliders again under dark_, and a + # tint per mode — a hue laid over the grays at tint_level percent. + "dark_mode": False, + "tint_color": "#3584E4", + "tint_level": 0, + "dark_tint_color": "#3584E4", + "dark_tint_level": 0, "lastfm": { "api_key": "", "api_secret": "", diff --git a/lintunes/theme.py b/lintunes/theme.py index daba242..34df266 100644 --- a/lintunes/theme.py +++ b/lintunes/theme.py @@ -49,19 +49,94 @@ UI_SCALES = { _base_palette = None -# The five user-tunable grayscale surfaces. now-playing bg/text have fixed +# The user-tunable grayscale surfaces. now-playing bg/text have fixed # defaults (white/black); the rest default to whatever the base palette uses, # so an untouched install looks exactly as it did before the feature existed. _PALETTE_GRAY_ROLE = { "color_background": QPalette.ColorRole.Window, "color_stripe": QPalette.ColorRole.AlternateBase, "color_button": QPalette.ColorRole.AlternateBase, + "color_base": QPalette.ColorRole.Base, } _FIXED_GRAY_DEFAULT = { "color_now_playing_bg": 255, "color_now_playing_text": 0, } +# Dark mode (Round 101) has its own set of every slider, saved under the +# same key with ``dark_`` in front, and its own tint; the highlight color is +# shared. The light set keeps the original key names, so an existing +# preferences.json reads exactly as before. +MODES = ("light", "dark") +DARK_DEFAULTS = { + "color_background": 48, + "color_button": 72, + "color_now_playing_bg": 30, + "color_now_playing_text": 225, + "color_stripe": 40, + "color_base": 32, + "color_visualizer_gray": 95, +} +# Text and glyphs, which follow the mode rather than a slider. +_TEXT = {"light": QColor("black"), "dark": QColor("#e6e6e6")} +_ICON = {"light": QColor("#4A4A4A"), "dark": QColor("#c8c8c8")} +_mode = "light" # the mode last applied (apply_theme) + + +def mode(prefs) -> str: + """"dark" or "light", as Preferences has it.""" + return "dark" if prefs is not None and prefs.get("dark_mode") else "light" + + +def current_mode() -> str: + """The mode last applied, for painters with no prefs to hand.""" + return _mode + + +def is_dark() -> bool: + return _mode == "dark" + + +def mode_key(key: str, which: str) -> str: + """The preferences key for ``key`` in mode ``which``.""" + return key if which == "light" else f"dark_{key}" + + +def text_color(which: str | None = None) -> QColor: + """Text on a button or panel in this mode (black in light).""" + return QColor(_TEXT[which or _mode]) + + +def icon_gray(which: str | None = None) -> QColor: + """The transport glyphs' resting color in this mode.""" + return QColor(_ICON[which or _mode]) + + +def tint(prefs, which: str | None = None) -> tuple[QColor, float]: + """(tint color, level 0..1) for mode ``which`` (the current one when + None). Level 0 is no tint at all.""" + which = which or mode(prefs) + color = QColor(str(prefs.get(mode_key("tint_color", which)) or "#3584E4")) + if not color.isValid(): + color = QColor("#3584E4") + try: + level = float(prefs.get(mode_key("tint_level", which)) or 0) / 100 + except (TypeError, ValueError): + level = 0.0 + return color, max(0.0, min(1.0, level)) + + +def tinted(value, color: QColor, level: float) -> QColor: + """A 0..255 gray with ``color``'s hue at ``level`` of its saturation. + Lightness stays the gray's, so the slider still means light ↔ dark.""" + plain = gray(value) + if level <= 0: + return plain + h, s, _l, _a = color.getHslF() + if h < 0: # an achromatic tint has no hue + return plain + return QColor.fromHslF(h, s * level, plain.lightnessF()) + def _base() -> QPalette: """The app's original palette, captured once, used as the reference for @@ -80,9 +155,11 @@ def gray(value) -> QColor: return QColor(v, v, v) -def default_gray(key: str) -> int: +def default_gray(key: str, which: str = "light") -> int: """The slider's value when this surface hasn't been overridden — i.e. its current appearance, so showing the slider doesn't imply a change.""" + if which == "dark": + return DARK_DEFAULTS[key] if key in _FIXED_GRAY_DEFAULT: return _FIXED_GRAY_DEFAULT[key] if key == "color_visualizer_gray": @@ -100,11 +177,20 @@ def default_gray(key: str) -> int: + 0.114 * color.blue()) -def gray_value(prefs, key: str) -> int: - """The 0..255 value to show/apply for a surface: the saved override, or the - current default when the user hasn't touched it.""" - saved = prefs.get(key) - return default_gray(key) if saved is None else max(0, min(255, int(saved))) +def gray_value(prefs, key: str, which: str | None = None) -> int: + """The 0..255 value to show/apply for a surface in mode ``which`` (the + current one when None): the saved override, or the default when the + user hasn't touched it.""" + which = which or mode(prefs) + saved = prefs.get(mode_key(key, which)) + return (default_gray(key, which) if saved is None + else max(0, min(255, int(saved)))) + + +def surface(prefs, key: str) -> QColor: + """A surface's color as painted: its gray in the current mode, tinted. + (Text — the now-playing text — is never tinted; use gray_value.)""" + return tinted(gray_value(prefs, key), *tint(prefs)) def swatch_icon(color_hex: str, size: int = 18) -> QIcon: @@ -136,8 +222,34 @@ def scale_metrics(prefs) -> dict: return UI_SCALES.get(prefs.get("ui_scale"), UI_SCALES["medium"]) +def _dark_palette(prefs) -> QPalette: + """Every role, since nothing of the light base palette suits dark.""" + window = surface(prefs, "color_background") + button = surface(prefs, "color_button") + palette = QPalette(button, window) + text = text_color("dark") + dim = QColor(text) + dim.setAlpha(110) + for group in (QPalette.ColorGroup.Active, QPalette.ColorGroup.Inactive, + QPalette.ColorGroup.Disabled): + disabled = group == QPalette.ColorGroup.Disabled + for role in (QPalette.ColorRole.WindowText, QPalette.ColorRole.Text, + QPalette.ColorRole.ButtonText): + palette.setColor(group, role, QColor("#808080") if disabled else text) + palette.setColor(group, QPalette.ColorRole.Base, surface(prefs, "color_base")) + palette.setColor(group, QPalette.ColorRole.AlternateBase, + surface(prefs, "color_stripe")) + palette.setColor(group, QPalette.ColorRole.PlaceholderText, dim) + palette.setColor(group, QPalette.ColorRole.ToolTipBase, window.lighter(130)) + palette.setColor(group, QPalette.ColorRole.ToolTipText, text) + palette.setColor(group, QPalette.ColorRole.Link, QColor("#8ab4f8")) + return palette + + def apply_theme(app, prefs): + global _mode base = _base() + _mode = mode(prefs) color = highlight_color(prefs) # Black text on light highlights, white on dark @@ -145,22 +257,24 @@ def apply_theme(app, prefs): + 0.114 * color.blue()) / 255 text = QColor("black") if luminance > 0.6 else QColor("white") - palette = QPalette(base) + palette = _dark_palette(prefs) if _mode == "dark" else QPalette(base) groups = (QPalette.ColorGroup.Active, QPalette.ColorGroup.Inactive) for group in groups: palette.setColor(group, QPalette.ColorRole.Highlight, color) palette.setColor(group, QPalette.ColorRole.HighlightedText, text) palette.setColor(group, QPalette.ColorRole.Accent, color) - # User grayscale overrides (None = leave the base color untouched). The - # button-box color lives in transport.py, not the palette. - background = prefs.get("color_background") - if background is not None: - for group in groups: - palette.setColor(group, QPalette.ColorRole.Window, gray(background)) - stripe = prefs.get("color_stripe") - if stripe is not None: - for group in groups: - palette.setColor(group, QPalette.ColorRole.AlternateBase, gray(stripe)) + if _mode == "light": + # User grayscale overrides; a surface nobody touched keeps the base + # palette's own color unless a tint asks to color it. The + # button-box color lives in transport.py, not the palette. + _hue, level = tint(prefs, "light") + for key, role in (("color_background", QPalette.ColorRole.Window), + ("color_stripe", QPalette.ColorRole.AlternateBase), + ("color_base", QPalette.ColorRole.Base)): + if prefs.get(key) is None and level <= 0: + continue + for group in groups: + palette.setColor(group, role, surface(prefs, key)) app.setPalette(palette) metrics = scale_metrics(prefs) diff --git a/tests/test_round101.py b/tests/test_round101.py new file mode 100644 index 0000000..7b7177f --- /dev/null +++ b/tests/test_round101.py @@ -0,0 +1,95 @@ +"""Round 101: dark mode, a tint per mode, and the toolbar configurator.""" +from PyQt6.QtGui import QColor, QPalette +from PyQt6.QtWidgets import QApplication + +from lintunes import theme +from lintunes.preferences import Preferences + + +def _luma(color: QColor) -> float: + return 0.299 * color.red() + 0.587 * color.green() + 0.114 * color.blue() + + +def test_dark_mode_turns_every_surface_dark_and_text_light(qapp, tmp_path): + prefs = Preferences(tmp_path) + prefs.set("dark_mode", True) + try: + theme.apply_theme(qapp, prefs) + palette = QApplication.palette() + for role in (QPalette.ColorRole.Window, QPalette.ColorRole.Base, + QPalette.ColorRole.AlternateBase, QPalette.ColorRole.Button): + assert _luma(palette.color(role)) < 90, role + for role in (QPalette.ColorRole.Text, QPalette.ColorRole.WindowText, + QPalette.ColorRole.ButtonText): + assert _luma(palette.color(role)) > 180, role + assert palette.color(QPalette.ColorRole.Highlight) == theme.highlight_color(prefs) + assert theme.is_dark() + finally: + theme.apply_theme(qapp, Preferences(tmp_path / "light")) + assert not theme.is_dark() + + +def test_each_mode_keeps_its_own_grays(tmp_path): + prefs = Preferences(tmp_path) + prefs.set("color_background", 200) + prefs.set("dark_color_background", 20) + assert theme.gray_value(prefs, "color_background") == 200 + prefs.set("dark_mode", True) + assert theme.gray_value(prefs, "color_background") == 20 + assert theme.gray_value(prefs, "color_stripe") == theme.DARK_DEFAULTS["color_stripe"] + assert theme.gray_value(prefs, "color_background", "light") == 200 + + +def test_a_tint_keeps_the_gray_lightness(tmp_path): + prefs = Preferences(tmp_path) + prefs.set("dark_mode", True) + prefs.set("dark_tint_color", "#ff0000") + prefs.set("dark_tint_level", 50) + color = theme.surface(prefs, "color_background") + plain = theme.gray(theme.gray_value(prefs, "color_background")) + assert abs(color.lightnessF() - plain.lightnessF()) < 0.01 + assert color.red() > color.green() == color.blue() + prefs.set("dark_tint_level", 0) + assert theme.surface(prefs, "color_background") == plain + + +def test_untouched_light_mode_keeps_the_base_palette(qapp, tmp_path): + theme.apply_theme(qapp, Preferences(tmp_path)) + assert (QApplication.palette().color(QPalette.ColorRole.Window) + == theme._base().color(QPalette.ColorRole.Window)) + + +def _dialog(tmp_path): + from lintunes.gui.preferences_dialog import PreferencesDialog + from tests.test_round40 import _FakeLastFm + prefs = Preferences(tmp_path) + return prefs, PreferencesDialog(prefs, _FakeLastFm()) + + +def test_switching_the_edited_mode_moves_the_sliders(qapp, tmp_path): + prefs, dialog = _dialog(tmp_path) + slider = dialog._color_sliders["color_background"] + slider.setValue(222) + assert prefs.get("color_background") == 222 + dialog._color_mode_buttons["dark"].setChecked(True) + assert slider.value() == theme.DARK_DEFAULTS["color_background"] + slider.setValue(11) + assert prefs.get("dark_color_background") == 11 + assert prefs.get("color_background") == 222 # light untouched + dialog._color_mode_buttons["light"].setChecked(True) + assert slider.value() == 222 + dialog._tint_slider.setValue(40) + assert prefs.get("tint_level") == 40 + assert prefs.get("dark_tint_level") == 0 + dialog.deleteLater() + + +def test_the_dark_mode_box_follows_the_pref(qapp, tmp_path): + prefs, dialog = _dialog(tmp_path) + dialog._dark_check.setChecked(True) + assert prefs.get("dark_mode") is True + assert dialog._color_mode_buttons["dark"].isChecked() + prefs.set("dark_mode", False) # e.g. the toolbar's button + assert not dialog._dark_check.isChecked() + dialog.deleteLater() + theme.apply_theme(qapp, Preferences(tmp_path / "light"))