Skip to content

Add light/dark auto-switch - #14151

Open
larsoner wants to merge 1 commit into
mne-tools:mainfrom
larsoner:autoswitch
Open

Add light/dark auto-switch#14151
larsoner wants to merge 1 commit into
mne-tools:mainfrom
larsoner:autoswitch

Conversation

@larsoner

Copy link
Copy Markdown
Member

Closes #9182

Knocking off one more TODO in our code using Claude Opus 5 to draft changes (which I've reviewed)... automatic switching on macOS when the system theme changes. Mostly a code refactor, one tricky point (needing to apply to children iff they had one applied previously). Also deleted a comment that doesn't apply anymore.

Comment thread mne/viz/backends/_qt.py
# our own setStyleSheet emits PaletteChange; without this the signal recurses
window._mne_theme_updating = True
try:
# re-setting an unchanged sheet costs styled children (sliders) native rendering

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this comment (specifically the verb "costs")

Comment thread mne/viz/backends/_qt.py
if theme is None:
theme = _qt_detect_theme()
theme = get_config("MNE_3D_OPTION_THEME", theme)
stylesheet = _qt_get_stylesheet(theme)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this logic seems a bit convoluted:

  1. if a theme was passed in, set window._mne_theme to it
  2. replace value of theme variable with window._mne_theme, or
  3. if it's None, with _qt_detect_theme()
  4. override value of theme with the config variable.

I think I get why we do step 4 (user set an MNE-specific preference, AKA "don't follow system theme"). But the other 3 steps I can't quite follow... Could this be re-ordered, simplified, or just commented a bit better? Naively I'd think that something like this would be clearer:

theme = (
    get_config("MNE_3D_OPTION_THEME", None)
    or theme
    or getattr(window, "_mne_theme", None)
    or _qt_detect_theme()
)

...but IDK what the significance is of changing window._mne_theme to be the passed-in value and not one of the other values

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Automatic light/dark mode switching of open STC plot windows

2 participants