Source: factory.core/ObjPalette.py
Manages color palettes, including reading from and saving to the database,
extracting colors from images, and generating swatches.
| Method | Signature | Description |
|---|---|---|
| read | read(palette_name: str = '') -> dict |
|
| get_color | get_color(color_name: str, default_value: str = '') -> str |
|
| get_palette | get_palette(name: str = '', colour: str = '') |
Load the palette for the active package. |
| get_print_palette | get_print_palette() -> dict |
Load the PRINT palette for PDF/print output. |
| get_mermaid_theme | get_mermaid_theme() -> str |
Return the mermaid theme matching the palette. |
| hex_to_rgb | hex_to_rgb(hex_code: str) -> tuple[int, int, int] |
Convert a hex colour string to an (R, G, B) tuple. |
| wcag_ratio | wcag_ratio(hex_col: str, background: str = '#ffffff') -> float |
WCAG 2.1 contrast ratio between two colours. |
| pick_readable | pick_readable(min_ratio: float, background: str, fallback: str, *candidates) -> str |
Pick the first colour with sufficient |
| hex_to_name | hex_to_name(hex_code: str) -> str |
Return the nearest CSS3 colour name for a hex code. |
| get_piper_theme | get_piper_theme(palette: dict | None = None) -> str |
Match a palette to the closest piper theme. |
| populate_colour_names | populate_colour_names(palette_name: str = '') -> dict |
Resolve colour names for all hex values in a palette and |
| populate_all_colour_names | populate_all_colour_names() -> int |
Resolve colour names for every palette in the database. |
| save | save(palette_name: str) -> None |
|
| get_default | get_default() -> dict |
Return the default palette row for the current package, or {} if none set. |
| set_default | set_default(palette_name: str) -> None |
Mark palette_name as the default for the current package. |
| extract_from_image | extract_from_image(image_path: str, palette_name: str, num_colors: int = 6) -> list |
|
| are_complementary | are_complementary(color1_hex: str, color2_hex: str) -> bool |
|
| load_json_to_db | load_json_to_db() -> None |
|
| normalize_palettes | normalize_palettes() -> None |
|
| swatches | swatches(palette_name: str | None = None, combine: bool = True) -> None |
|
| combine_swatches | combine_swatches() -> None |
|
| display_cli_palette | display_cli_palette(palette: dict) -> None |
|
| seed_from_yaml | seed_from_yaml() -> None |
Insert palette seed data from ObjPalette.yaml for the current package. |
| export_to_yaml | export_to_yaml() -> int |
Write current DB palettes to the palettes: section of ObjPalette.yaml. |
| validate | validate(palette_name: str, delta_e_threshold: float = 20.0, wcag_level: str = 'AA') -> list[dict] |
Check a palette's semantic colours for clashing and WCAG contrast failures. |
| fix | fix(palette_name: str, issues: list[dict]) -> dict[str, str] |
Return suggested hex replacements for colours that have issues. |
Display the palette configured for the active package.
List all palettes with colour swatches, grouped by set.
Display a specific palette's colours by name.
Load color palettes from the JSON file into the database.
Fill missing palette fields from REFERENCE and normalize names.
Generate PNG swatches for each color palette.
Extract a color palette from an image and save it.
Check a palette for clashing colours and WCAG contrast failures.
Fix clashing colours and contrast failures in a palette.
Fix clashing colours and contrast failures across all palettes in the database.
Show or set the default palette for the active package.
Export current DB palettes to the palettes: seed section of ObjPalette.yaml.