UI Config Manager#
- class UIConfigManager[source]#
Manages the user interface configuration settings.
This includes the management of header and footer text for exported PDFs, custom fonts, font paths, and an optional branding logo. The class also handles the downloading of default fonts if they are not already present.
- property config: Dict[source]#
Retrieves the current UI configuration from property list.
If no configuration is found, the default configuration is created.
- Returns:
Retrieved UI configuration settings or default config.
- Return type:
- property fonts_present: bool[source]#
This property verifies if the required font files (regular and bold) are present in the expected directory.
- Returns:
True
if the fonts are present.- Return type:
- load_ui_config()[source]#
Reads the Patcher property list file to retrieve UI settings and loads them. If the property list file does not exist, it is created with default values.
- create_default_config()[source]#
This method writes default values for header text, footer text, font paths and optional branding logo into the property list file. It also ensures that the necessary fonts are downloaded if they are not already present.
- reset_config() bool [source]#
Removes all existing UI settings from the property list file.
This method is useful if the user wants to reconfigure the UI elements of PDF reports, such as header/footer text, font choices, and branding logo.
- Returns:
True
if the reset was successful.- Return type:
- setup_ui()[source]#
Guides the user through configuring UI settings for PDF reports, including header/footer text, font choices, and an optional branding logo.
Note
This function is used solely by the
Setup
class during initial setup.
- configure_font(use_custom_font: bool, font_dir: Path) Tuple[str, Path, Path] [source]#
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.
If the specified font files cannot be copied to the passed
font_dir
, the default fonts are used and a warning is logged.Note
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:
- Raises:
SetupError – If the provided logo path does not exist.
PatcherError – If the provided logo fails pillow validation.
PatcherError – If the logo file could not be copied to the destination path.
- 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.
Note
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
]]) – The path to company/branding logo file. Defaults to None.