svgen.color.theme package — docs

Skip to main content
`Ctrl`+`K`

# svgen.color.theme package

## Submodules

## svgen.color.theme.manager module

A module implementing a color-theme manager.

class svgen.color.theme.manager.ColorThemeManager(initialdata: dict[str, ColorTheme] = None, theme: str = '')

  Bases: `UserDict`, `LoggerMixin`, `MutableMapping`[`str`, `ColorTheme`]

  A class for managing color themes.

  add_themes(*themes: ColorTheme) → None

    Add new themes to the manager.

  load_directory(path: Path | str | None) → None

    Load themes from a directory.

  property size: int

    Get the number of managed themes.

## svgen.color.theme.visualize module

A module for visualizing color themes.

svgen.color.theme.visualize.visualize(rect: Rectangle, manager: ColorThemeManager = None, columns: bool = True) → Iterator[Rect]

  Visualize all managed themes within a provided rectangle.

svgen.color.theme.visualize.visualize_theme(theme: ColorTheme | str, rect: Rectangle, columns: bool = True) → Iterator[Rect]

  Create filled rectangle elements for this theme inside another rectangle.

## Module contents

A module for working with color themes.

class svgen.color.theme.ColorTheme(name: str, initialdata: dict[str, str | Hsl | Rgb | Color] = None, namespace: Namespace = None)

  Bases: `UserDict`, `NamespaceMixin`, `MutableMapping`[`str`, `Color`]

  A class implementing a theme color interface.

  add(key: str, color: str | Hsl | Rgb | Color) → ColorToken

    Add a new color to this theme.

  add_mapping(data: dict[str, Any]) → None

    Add a mapping of tokens and colors to this theme.

  create(color: str | Hsl | Rgb | Color) → Color

    Attempt to create a color through this theme so that existing tokens can be used as color aliases.

  data: dict[str, Color]
  static from_path(path: Path | str | None) → ColorTheme

    Load a color theme from a data file on disk.

  lookup(key: str) → tuple[str, Color | None]

    Attempt to find an existing color in this theme by key.

  resolve(key: str, strict: bool = False) → ColorToken

    Attempt to resolve a color key as a theme color.

  property size: int

    Get the number of colors in this theme.

class svgen.color.theme.ColorToken(token: str, color: Color)

  Bases: `NamedTuple`

  A simple pairing of a color with a token.

  color: Color

    Alias for field number 1

  static create(key: str | Hsl | Rgb | Color) → ColorToken

    Create a color token from a color.

  token: str

    Alias for field number 0