Skip to content

Settings & Theme (core/settings.py)

core/settings.py persists preferences such as language, theme, and the onboarding flag, and installs / uninstalls the translator. Settings are written as JSON into the Qt standard config directory (settings.json under QStandardPaths.AppConfigLocation); the path is cached after the first resolution.

Warning

This module can only resolve the settings path correctly after run.py sets the QCoreApplication organization and application name; otherwise different run stages resolve to different files and settings won't persist across restarts (a historical bug).

Language

Function Description
apply_language(lang) Install / uninstall the translator. lang of None / '' / zh_CN uninstalls it (source Chinese is used); other values (e.g. en_US) load the matching .qm and install it.
load_saved_language() -> str Read the last chosen language, default 'zh_CN'.
save_language(lang) Write the language choice to the persisted file (merged, not overwriting other keys).
current_language() -> str Return the current language code (e.g. 'zh_CN' / 'en_US').

Theme

Function Description
current_theme() -> str Return the current theme 'light' / 'dark'.
load_saved_theme() -> str Read the last chosen theme, default 'light'.
save_theme(theme) Write the theme choice; theme of empty is treated as 'dark'.

Onboarding flag

Function Description
load_initialized() -> bool Read the "has seen the guide" flag, default False. Missing file / corrupt file / missing key all count as not initialized.
save_initialized(val=True) Write the onboarding flag (merged, not overwriting other keys).

Version

Function / constant Description
APP_VERSION The application version string — the single source of truth, written to the settings file on startup.
load_saved_version() -> str \| None Read the last written version; returns None if absent.
save_version(version=APP_VERSION) Write the version to the persisted file (merged, not overwriting other keys), recording the "last run version" for upgrade checks / compatibility debugging. It only writes when the version actually changed; on normal startups (same version) it returns early to avoid rewriting the settings file and slowing down startup.

Misc

Function Description
clear_settings_file() Delete the persisted settings.json (if present). The in-memory current language / theme is unaffected; the caller decides whether to restore defaults.

Example

python from core.settings import apply_language, load_saved_language, current_theme apply_language(load_saved_language()) # restore language on startup if current_theme() == "dark": ...

Note

On module load, current_theme() is synced with the persisted value. The configurable UI items (language, theme, save scope) are described in Configuration.