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 = '')[source]#

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

A class for managing color themes.

add_themes(*themes: ColorTheme) None[source]#

Add new themes to the manager.

load_directory(path: Path | str | None) None[source]#

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][source]#

Visualize all managed themes within a provided rectangle.

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

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)[source]#

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

A class implementing a theme color interface.

add(key: str, color: str | Hsl | Rgb | Color) ColorToken[source]#

Add a new color to this theme.

add_mapping(data: Dict[str, Any]) None[source]#

Add a mapping of tokens and colors to this theme.

create(color: str | Hsl | Rgb | Color) Color[source]#

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[source]#

Load a color theme from a data file on disk.

lookup(key: str) Tuple[str, Color | None][source]#

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

resolve(key: str, strict: bool = False) ColorToken[source]#

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)[source]#

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[source]#

Create a color token from a color.

token: str#

Alias for field number 0