Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions materialyoucolor/dynamiccolor/material_dynamic_colors.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
from __future__ import annotations

from typing import List, Optional
from typing import List

from materialyoucolor.dynamiccolor.color_spec import (
COLOR_NAMES,
ColorSpecDelegate,
get_spec,
)
from materialyoucolor.dynamiccolor.dynamic_color import DynamicColor
from materialyoucolor.dynamiccolor.dynamic_scheme import DynamicScheme


class MaterialDynamicColors:
content_accent_tone_delta = 15.0

def __init__(self, spec="2025"):
self.color_spec: ColorSpecDelegate = get_spec(spec)

# define them dynamically
for color_name in COLOR_NAMES:
exec(
f"@property\ndef {color_name}(self) -> DynamicColor:\n\treturn self.color_spec.{color_name}()"
)
for name in COLOR_NAMES:
setattr(self, name, getattr(self.color_spec, name)())

@property
def all_colors(self) -> List[DynamicColor]:
colors = [getattr(self, _) for _ in COLOR_NAMES]
return [c for c in colors if c is not None]


# backward compatibility class attrs
_spec = get_spec("2025")
for name in COLOR_NAMES:
setattr(MaterialDynamicColors, name, getattr(_spec, name)())
Loading