Source code for simvx.editor.preferences
"""Editor preferences and theme system.
Persistent settings via the unified ``AppConfig`` system
(``~/.config/simvx/config.json``). ``EditorPreferences`` wraps an
``AppConfig`` and adds editor-specific theme application.
"""
from simvx.core.config import AppConfig
from simvx.core.ui.theme import AppTheme, set_theme
_THEME_PRESETS = {
"dark": AppTheme.dark,
"light": AppTheme.light,
"monokai": AppTheme.monokai,
}
[docs]
class EditorPreferences:
"""Holds the unified ``AppConfig`` and applies editor themes."""
def __init__(self) -> None:
self.config = AppConfig()
[docs]
def load(self) -> None:
self.config.load()
[docs]
def save(self) -> None:
self.config.save()
[docs]
def get_theme(self) -> AppTheme:
"""Return an ``AppTheme`` for the current preset and make it the singleton."""
factory = _THEME_PRESETS.get(self.config.general.theme_preset, AppTheme.dark)
theme = factory()
theme.font_size = self.config.general.font_size
theme._sync_dicts()
set_theme(theme)
return theme
[docs]
def reset_to_defaults(self) -> None:
self.config = AppConfig()