gui.config.config_manager

File:

EuljiroBible/gui/config/config_manager.py

Author:

Benjamin Jaedon Choi - https://github.com/saintbenjamin

Affiliated Church:

The Eulji-ro Presbyterian Church [대한예수교장로회(통합) 을지로교회]

Address:

The Eulji-ro Presbyterian Church, 24-10, Eulji-ro 20-gil, Jung-gu, Seoul 04549, South Korea

Telephone:

+82-2-2266-3070

E-mail:

euljirochurch [at] G.M.A.I.L. (replace [at] with @ and G.M.A.I.L as you understood.)

License:

MIT License with Attribution Requirement (see LICENSE file for details); Copyright (c) 2025 The Eulji-ro Presbyterian Church.

Configuration manager for the EuljiroBible GUI.

This module provides a single entry point for loading, saving, and updating user settings (JSON) used by the GUI. It also includes platform-aware defaults and utilities related to font selection.

Key responsibilities:

  • Read and write the settings JSON file (with UTF-8 encoding).

  • Recover safely from missing, corrupted, or invalid settings files by

    falling back to DEFAULT_SETTINGS.

  • Provide OS-specific reasonable default font selection.

Note

  • This module may show GUI error dialogs when a QApplication instance exists. If not, it falls back to console output.

class gui.config.config_manager.ConfigManager[source]

Bases: object

Manages loading, saving, and modifying user settings for the application.

This class centralizes access to the GUI settings JSON file and provides helpers for applying safe defaults when the settings file is missing or invalid. All methods are static to keep the API simple and to avoid accidental state drift.

BASE_DIR

Absolute path to the application/project base directory.

Type:

str

DEFAULT_OUTPUT_PATH

Default verse output path used when output_path is missing from the settings file. Typically <BASE_DIR>/verse_output.txt.

Type:

str

static get_icon_dir()[source]

Return the absolute path to the application’s icon directory.

Returns:

Absolute path to the icon directory (e.g., paths.ICON_DIR).

Return type:

str

static get_bible_data_dir()[source]

Return the directory path where Bible text JSON files are stored.

Returns:

Absolute path to the Bible text data directory (e.g., paths.BIBLE_DATA_DIR).

Return type:

str

static load()[source]

Load user settings from disk with safe fallback behavior.

This method reads the JSON settings file defined by paths.SETTINGS_FILE. If the file does not exist, it is created using DEFAULT_SETTINGS. If the file exists but is corrupted or not a JSON object, a GUI error dialog may be shown (when a QApplication instance exists) and the method falls back to DEFAULT_SETTINGS.

Backward compatibility:
  • Ensures output_path exists in the loaded settings; if missing, it is populated with DEFAULT_OUTPUT_PATH.

Returns:

A settings dictionary. If loading fails, returns DEFAULT_SETTINGS.

Return type:

dict

Raises:

None – This method is intentionally non-throwing and recovers internally.

static save(data)[source]

Save the given settings dictionary to the settings JSON file.

The settings are written to paths.SETTINGS_FILE using UTF-8 encoding and pretty-printed JSON for readability.

Parameters:

data (dict) – The full settings dictionary to write.

Raises:

Exception – Re-raises any I/O or serialization error after logging via log_error_with_dialog.

static update_partial(data)[source]

Update part of the settings dictionary and persist it.

This method loads the current settings, applies the given partial update (overwriting existing keys), and saves the result back to disk.

Parameters:

data (dict) – Partial key-value pairs to merge into the current settings.

Raises:

Exception – Propagates exceptions from load() or save() if saving fails.

static get_default_font()[source]

Return the best available default font family for the current platform.

This method inspects available system fonts (via QFontDatabase) and selects a preferred font from a platform-specific candidate list. If none of the candidates are available, it falls back to Qt’s default font family.

Returns:

Font family name that is expected to exist on the current system.

Return type:

str

static save_font(family, size, weight)[source]

Update and persist the application’s main UI font preferences.

This method updates font_family, font_size, and font_weight in the settings file and saves them immediately.

Parameters:
  • family (str) – Font family name.

  • size (int) – Font point size.

  • weight (int) – Font weight value. Typically a Qt weight integer (e.g., values aligned with QFont.Weight).