UI Config Manager#
Summary
The UIConfigManager
handles managing the customizable UI elements of exported PDF reports. For additional reference, see Customizing Reports.
- class UIConfigManager[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.
- 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:
- load_ui_config()[source]#
Loads the user interface configuration from the default and user configuration files.
This method reads the Patcher property list file to retrieve the settings. If the property list file does not exist, it is created with default values.
- async download_font(url: str, dest_path: Path)[source]#
Downloads the Assistant font family from the specified URL to the given destination path.
- Parameters:
- Raises:
exceptions.ShellCommandError – Raised if the font cannot be downloaded due to a network error or invalid response.
- async create_default_config()[source]#
This method writes default values for header text, footer text, and font paths into the property list file. It also ensures that the necessary fonts are downloaded if they are not already present.
- 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: str, fallback: str = None) str [source]#
Retrieves a specific configuration value from the UI configuration.
- reset_config() bool [source]#
Resets the user interface settings in the property list file.
This method removes all existing UI settings from the configuration file. It can be useful for restoring default values or clearing the configuration.
- Returns:
True
if the reset was successful,False
otherwise.- Return type:
- setup_ui()[source]#
Guides the user through configuring UI settings for PDF reports, including header/footer text and font choices. This function is used solely by the
Setup
class during initial setup.- Raises:
FileNotFoundError – IF the specified font file paths do not exist.
- static configure_font(use_custom_font: bool, font_dir: Path) Tuple[str, Path, Path] [source]#
Configures the font settings based on user input.
This method allows the user to specify a custom font or use the default provided by the application. The chosen fonts are copied to the appropriate directory for use in PDF report generation.
This function is used solely by the
Setup
class during initial setup.
- configure_logo(use_logo: bool) str | None [source]#
Configures the logo file for PDF reports based on user input.
If a logo file is specified, it is validated and copied to Patcher’s Application Support directory. Similar to
configure_font()
this method is solely used in conjunction with theSetup
class.- Parameters:
use_logo (bool) – Indicates whether or not to use a custom logo.
- Returns:
The path to the saved logo file, or None if no logo is configured.
- Return type:
Optional[str]
- Raises:
exceptions.SetupError – If the provided logo path does not exist.
exceptions.PatcherError – If the provided logo fails pillow validation.
- save_ui_config(header_text: str, footer_text: str, font_name: str, font_regular_path: str | Path, font_bold_path: str | Path, logo_path: str | Path | None = None)[source]#
Saves the UI configuration settings to the configuration file. This function is used solely by the
Setup
class during initial setup.- Parameters:
header_text (str) – The header text for PDF reports.
footer_text (str) – The footer text for PDF reports.
font_name (str) – The name of the font to use.
font_regular_path (Union[str, Path]) – The path to the regular font file.
font_bold_path (Union[str, Path]) – The path to the bold font file.
logo_path (Optional[Union[str, Path]], defaults to None.) – The path to company/branding logo file.