UI Config Manager#

Summary

The UIConfigManager handles managing the customizable UI elements of exported PDF reports. For additional reference, see Customizing Reports.

class UIConfigManager(custom_ca_file: str | None = None)[source]#

Manages the user interface configuration settings.

This includes the management of header and footer text for exported PDFs, custom fonts, and font paths. The class also handles the downloading of default fonts if they are not already present.

Initializes the UIConfigManager by loading the user interface configuration.

Parameters:

custom_ca_file (Optional[str]) – Optional path to a custom Certificate Authority (CA) file. This is used for SSL verification during font downloads.

property fonts_present: bool#

Checks if the default fonts have already been downloaded.

This property verifies if the required font files (regular and bold) are present in the expected directory.

Returns:

True if the fonts are present, False otherwise.

Return type:

bool

download_font(url: AnyStr, dest_path: AnyStr)[source]#

Downloads the Assistant font family from the specified URL to the given destination path.

If a custom CA file is provided, it is used to create an SSL context for the download. This method ensures the fonts are stored securely in the appropriate directory.

Parameters:
  • url (AnyStr) – The URL to download the font from.

  • dest_path (AnyStr) – The local path where the downloaded font should be saved.

Raises:

OSError – Raised if the font cannot be downloaded due to a network error or invalid response.

create_default_config()[source]#

Creates the config.ini file with default settings for the user interface.

This method writes default values for header text, footer text, and font paths into the configuration file. It also ensures that the necessary fonts are downloaded if they are not already present.

load_ui_config()[source]#

Loads the user interface configuration from the default and user configuration files.

This method reads the config.ini file to retrieve the settings. If the configuration file does not exist, it is created with default values.

get_ui_config() Dict[source]#

Retrieves the user interface configuration settings as a dictionary.

Returns:

A dictionary containing UI configuration settings such as header text, footer text, and font paths.

Return type:

Dict

get(key: AnyStr, fallback: AnyStr = None) AnyStr[source]#

Retrieves a specific configuration value from the UI configuration.

Parameters:
  • key (AnyStr) – The key for the configuration value to retrieve.

  • fallback (AnyStr, optional) – The value to return if the key is not found. Defaults to None.

Returns:

The configuration value corresponding to the provided key, or the fallback value if the key is not found.

Return type:

AnyStr

reset_config(config_path: AnyStr | None = None) bool[source]#

Resets the user interface settings in the config.ini file.

This method removes all existing UI settings from the configuration file. It can be useful for restoring default values or clearing the configuration.

Parameters:

config_path (Optional[AnyStr]) – The path of the configuration file to reset. If None, defaults to the current user’s configuration path.

Returns:

True if the reset was successful, False otherwise.

Return type:

bool