Skip to content

raster_2d_style

raster_2d_style

Tool for converting style string to ColorScheme objects.

STYLE_TO_COLOR_SCHEME module-attribute

STYLE_TO_COLOR_SCHEME = {
    "silk": SILK,
    "silk_alpha": SILK_ALPHA,
    "copper": COPPER,
    "copper_alpha": COPPER_ALPHA,
    "paste_mask": PASTE_MASK,
    "paste_mask_alpha": PASTE_MASK_ALPHA,
    "solder_mask": SOLDER_MASK,
    "solder_mask_alpha": SOLDER_MASK_ALPHA,
    "default_grayscale": DEFAULT_GRAYSCALE,
    "debug_1": DEBUG_1,
    CUSTOM_STYLE_OPTION: None,
}

Map of known color styles to ColorScheme objects.

get_color_scheme_from_style

get_color_scheme_from_style(
    style: str, custom: Optional[str] = None
) -> ColorScheme

Convert style string to ColorScheme object.

Accepted values for style are any key from STYLE_TO_COLOR_SCHEME. When style is 'custom' then parameter custom must also be provided. Custom color should be a single string consisting of 5 or 7 valid hexadecimal colors separated with commas. Any color which can be parsed by RGBA type is accepted. Colors are assigned in order:

  • background_color
  • clear_color
  • solid_color
  • clear_region_color
  • solid_region_color
  • debug_1_color (optional, by default #ABABAB)
  • debug_2_color (optional, by default #7D7D7D)

eg. "000000,000000,FFFFFF,000000,FFFFFF"

Source code in src/pygerber/console/raster_2d_style.py
def get_color_scheme_from_style(
    style: str,
    custom: Optional[str] = None,
) -> ColorScheme:
    """Convert style string to ColorScheme object.

    Accepted values for style are any key from STYLE_TO_COLOR_SCHEME. When style is
    'custom' then parameter custom must also be provided.
    Custom color should be a single string consisting of 5 or 7 valid hexadecimal colors
    separated with commas. Any color which can be parsed by RGBA type is accepted.
    Colors are assigned in order:

    - background_color
    - clear_color
    - solid_color
    - clear_region_color
    - solid_region_color
    - debug_1_color (optional, by default #ABABAB)
    - debug_2_color (optional, by default #7D7D7D)

    eg. `"000000,000000,FFFFFF,000000,FFFFFF"`
    """
    if style == CUSTOM_STYLE_OPTION:
        if custom is None:
            msg = (
                f"When style is {CUSTOM_STYLE_OPTION!r} custom have to be a valid "
                "custom scheme."
            )
            raise TypeError(msg)
        return _construct_custom_scheme(custom)

    color_scheme = STYLE_TO_COLOR_SCHEME[style]
    if color_scheme is None:
        # Can't happen - option 'custom' is picked by if above.
        raise TypeError

    return color_scheme