Skip to content

Commit 2515814

Browse files
committed
refactor: generate text states from DynamicScheme and tonal palette
materialyoucolor-python v3.0.x made the generation take arount twice the time, this change brings it back very close to the previous time
1 parent 4888f85 commit 2515814

3 files changed

Lines changed: 134 additions & 107 deletions

File tree

src/kde_material_you_colors/schemeconfigs.py

Lines changed: 87 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __init__(
4545

4646
self._extras = colors["custom"]
4747

48-
extras = self._extras
48+
extras = self.get_extras()
4949

5050
best_colors_count = len(colors_best)
5151
# bg , ansi 30
@@ -254,12 +254,12 @@ def __init__(
254254
DecorationHover={colors_light['primary']}
255255
ForegroundActive={colors_light['onSurface']}
256256
ForegroundInactive={colors_light['outline']}
257-
ForegroundLink={extras['link']['light']['primary']}
258-
ForegroundNegative={extras['negative']['light']['primary']}
259-
ForegroundNeutral={extras['neutral']['light']['primary']}
257+
ForegroundLink={extras['link']['light']['color']}
258+
ForegroundNegative={extras['negative']['light']['color']}
259+
ForegroundNeutral={extras['neutral']['light']['color']}
260260
ForegroundNormal={colors_light['onSurface']}
261-
ForegroundPositive={extras['positive']['light']['primary']}
262-
ForegroundVisited={extras['visited']['light']['primary']}
261+
ForegroundPositive={extras['positive']['light']['color']}
262+
ForegroundVisited={extras['visited']['light']['color']}
263263
264264
[Colors:Complementary]
265265
BackgroundAlternate={colors_light['surface']}
@@ -268,12 +268,12 @@ def __init__(
268268
DecorationHover={colors_light['primary']}
269269
ForegroundActive={colors_light['inverseSurface']}
270270
ForegroundInactive={colors_light['outline']}
271-
ForegroundLink={extras['link']['light']['primary']}
272-
ForegroundNegative={extras['negative']['light']['primary']}
273-
ForegroundNeutral={extras['neutral']['light']['primary']}
271+
ForegroundLink={extras['link']['light']['color']}
272+
ForegroundNegative={extras['negative']['light']['color']}
273+
ForegroundNeutral={extras['neutral']['light']['color']}
274274
ForegroundNormal={colors_light['onSurfaceVariant']}
275-
ForegroundPositive={extras['positive']['light']['primary']}
276-
ForegroundVisited={extras['visited']['light']['primary']}
275+
ForegroundPositive={extras['positive']['light']['color']}
276+
ForegroundVisited={extras['visited']['light']['color']}
277277
278278
[Colors:Header]
279279
BackgroundAlternate={colors_light['surfaceContainer']}
@@ -282,12 +282,12 @@ def __init__(
282282
DecorationHover={colors_light['primary']}
283283
ForegroundActive={colors_light['inverseSurface']}
284284
ForegroundInactive={colors_light['outline']}
285-
ForegroundLink={extras['link']['light']['primary']}
286-
ForegroundNegative={extras['negative']['light']['primary']}
287-
ForegroundNeutral={extras['neutral']['light']['primary']}
285+
ForegroundLink={extras['link']['light']['color']}
286+
ForegroundNegative={extras['negative']['light']['color']}
287+
ForegroundNeutral={extras['neutral']['light']['color']}
288288
ForegroundNormal={colors_light['onSurfaceVariant']}
289-
ForegroundPositive={extras['positive']['light']['primary']}
290-
ForegroundVisited={extras['visited']['light']['primary']}
289+
ForegroundPositive={extras['positive']['light']['color']}
290+
ForegroundVisited={extras['visited']['light']['color']}
291291
292292
[Colors:Header][Inactive]
293293
BackgroundAlternate={colors_light['surfaceContainer']}
@@ -296,12 +296,12 @@ def __init__(
296296
DecorationHover={colors_light['primary']}
297297
ForegroundActive={colors_light['inverseSurface']}
298298
ForegroundInactive={colors_light['outline']}
299-
ForegroundLink={extras['link']['light']['primary']}
300-
ForegroundNegative={extras['negative']['light']['primary']}
301-
ForegroundNeutral={extras['neutral']['light']['primary']}
299+
ForegroundLink={extras['link']['light']['color']}
300+
ForegroundNegative={extras['negative']['light']['color']}
301+
ForegroundNeutral={extras['neutral']['light']['color']}
302302
ForegroundNormal={colors_light['onSurfaceVariant']}
303-
ForegroundPositive={extras['positive']['light']['primary']}
304-
ForegroundVisited={extras['visited']['light']['primary']}
303+
ForegroundPositive={extras['positive']['light']['color']}
304+
ForegroundVisited={extras['visited']['light']['color']}
305305
306306
[Colors:Selection]
307307
BackgroundAlternate={colors_light['primary']}
@@ -310,12 +310,12 @@ def __init__(
310310
DecorationHover={colors_light['secondary']}
311311
ForegroundActive={colors_light['onPrimary']}
312312
ForegroundInactive={colors_light['onPrimary']}
313-
ForegroundLink={extras['link']['light']['onPrimaryFixedVariant']}
314-
ForegroundNegative={extras['negative']['light']['onPrimaryFixedVariant']}
315-
ForegroundNeutral={extras['neutral']['light']['onPrimaryFixedVariant']}
313+
ForegroundLink={extras['link']['light']['container']}
314+
ForegroundNegative={extras['negative']['light']['container']}
315+
ForegroundNeutral={extras['neutral']['light']['container']}
316316
ForegroundNormal={colors_light['onPrimary']}
317-
ForegroundPositive={extras['positive']['light']['onPrimaryFixedVariant']}
318-
ForegroundVisited={extras['visited']['light']['onPrimaryFixedVariant']}
317+
ForegroundPositive={extras['positive']['light']['container']}
318+
ForegroundVisited={extras['visited']['light']['container']}
319319
320320
[Colors:Tooltip]
321321
BackgroundAlternate={colors_light['surfaceVariant']}
@@ -324,12 +324,12 @@ def __init__(
324324
DecorationHover={colors_light['primary']}
325325
ForegroundActive={colors_light['onSurface']}
326326
ForegroundInactive={colors_light['outline']}
327-
ForegroundLink={extras['link']['light']['primary']}
328-
ForegroundNegative={extras['negative']['light']['primary']}
329-
ForegroundNeutral={extras['neutral']['light']['primary']}
327+
ForegroundLink={extras['link']['light']['color']}
328+
ForegroundNegative={extras['negative']['light']['color']}
329+
ForegroundNeutral={extras['neutral']['light']['color']}
330330
ForegroundNormal={colors_light['onSurface']}
331-
ForegroundPositive={extras['positive']['light']['primary']}
332-
ForegroundVisited={extras['visited']['light']['primary']}
331+
ForegroundPositive={extras['positive']['light']['color']}
332+
ForegroundVisited={extras['visited']['light']['color']}
333333
334334
[Colors:View]
335335
BackgroundAlternate={colors_light['surfaceContainer']}
@@ -339,27 +339,27 @@ def __init__(
339339
DecorationHover={colors_light['secondaryFixed']}
340340
ForegroundActive={colors_light['inverseSurface']}
341341
ForegroundInactive={colors_light['outline']}
342-
ForegroundLink={extras['link']['light']['primary']}
343-
ForegroundNegative={extras['negative']['light']['primary']}
344-
ForegroundNeutral={extras['neutral']['light']['primary']}
342+
ForegroundLink={extras['link']['light']['color']}
343+
ForegroundNegative={extras['negative']['light']['color']}
344+
ForegroundNeutral={extras['neutral']['light']['color']}
345345
ForegroundNormal={colors_light['onSurface']}
346-
ForegroundPositive={extras['positive']['light']['primary']}
347-
ForegroundVisited={extras['visited']['light']['primary']}
346+
ForegroundPositive={extras['positive']['light']['color']}
347+
ForegroundVisited={extras['visited']['light']['color']}
348348
349349
[Colors:Window]
350350
BackgroundAlternate={colors_light['surfaceVariant']}
351351
BackgroundNormal={colors_light['surfaceContainer']}
352352
DecorationFocus={colors_light['primary']}
353353
DecorationHover={colors_light['primary']}
354-
ForegroundActive={extras['link']['light']['primary']}
354+
ForegroundActive={extras['link']['light']['color']}
355355
ForegroundInactive={colors_light['outline']}
356-
ForegroundLink={extras['link']['light']['primary']}
357-
ForegroundNegative={extras['negative']['light']['primary']}
358-
ForegroundNeutral={extras['neutral']['light']['primary']}
356+
ForegroundLink={extras['link']['light']['color']}
357+
ForegroundNegative={extras['negative']['light']['color']}
358+
ForegroundNeutral={extras['neutral']['light']['color']}
359359
#--- Window titles, context icons
360360
ForegroundNormal={colors_light['onSurfaceVariant']}
361-
ForegroundPositive={extras['positive']['light']['primary']}
362-
ForegroundVisited={extras['visited']['light']['primary']}
361+
ForegroundPositive={extras['positive']['light']['color']}
362+
ForegroundVisited={extras['visited']['light']['color']}
363363
364364
[General]
365365
ColorScheme=MaterialYouLight
@@ -405,12 +405,12 @@ def __init__(
405405
DecorationHover={colors_dark['primary']}
406406
ForegroundActive={colors_dark['onSurface']}
407407
ForegroundInactive={colors_dark['outline']}
408-
ForegroundLink={extras['link']['dark']['primary']}
409-
ForegroundNegative={extras['negative']['dark']['primary']}
410-
ForegroundNeutral={extras['neutral']['dark']['primary']}
408+
ForegroundLink={extras['link']['dark']['color']}
409+
ForegroundNegative={extras['negative']['dark']['color']}
410+
ForegroundNeutral={extras['neutral']['dark']['color']}
411411
ForegroundNormal={colors_dark['onSurface']}
412-
ForegroundPositive={extras['positive']['dark']['primary']}
413-
ForegroundVisited={extras['visited']['dark']['primary']}
412+
ForegroundPositive={extras['positive']['dark']['color']}
413+
ForegroundVisited={extras['visited']['dark']['color']}
414414
415415
[Colors:Complementary]
416416
BackgroundAlternate={colors_dark['surface']}
@@ -419,12 +419,12 @@ def __init__(
419419
DecorationHover={colors_dark['primary']}
420420
ForegroundActive={colors_dark['inverseSurface']}
421421
ForegroundInactive={colors_dark['outline']}
422-
ForegroundLink={extras['link']['dark']['primary']}
423-
ForegroundNegative={extras['negative']['dark']['primary']}
424-
ForegroundNeutral={extras['neutral']['dark']['primary']}
422+
ForegroundLink={extras['link']['dark']['color']}
423+
ForegroundNegative={extras['negative']['dark']['color']}
424+
ForegroundNeutral={extras['neutral']['dark']['color']}
425425
ForegroundNormal={colors_dark['onSurfaceVariant']}
426-
ForegroundPositive={extras['positive']['dark']['primary']}
427-
ForegroundVisited={extras['visited']['dark']['primary']}
426+
ForegroundPositive={extras['positive']['dark']['color']}
427+
ForegroundVisited={extras['visited']['dark']['color']}
428428
429429
[Colors:Header]
430430
BackgroundAlternate={colors_dark['surfaceContainer']}
@@ -433,12 +433,12 @@ def __init__(
433433
DecorationHover={colors_dark['primary']}
434434
ForegroundActive={colors_dark['inverseSurface']}
435435
ForegroundInactive={colors_dark['outline']}
436-
ForegroundLink={extras['link']['dark']['primary']}
437-
ForegroundNegative={extras['negative']['dark']['primary']}
438-
ForegroundNeutral={extras['neutral']['dark']['primary']}
436+
ForegroundLink={extras['link']['dark']['color']}
437+
ForegroundNegative={extras['negative']['dark']['color']}
438+
ForegroundNeutral={extras['neutral']['dark']['color']}
439439
ForegroundNormal={colors_dark['onSurfaceVariant']}
440-
ForegroundPositive={extras['positive']['dark']['primary']}
441-
ForegroundVisited={extras['visited']['dark']['primary']}
440+
ForegroundPositive={extras['positive']['dark']['color']}
441+
ForegroundVisited={extras['visited']['dark']['color']}
442442
443443
[Colors:Header][Inactive]
444444
BackgroundAlternate={colors_dark['surfaceContainer']}
@@ -447,12 +447,12 @@ def __init__(
447447
DecorationHover={colors_dark['primary']}
448448
ForegroundActive={colors_dark['inverseSurface']}
449449
ForegroundInactive={colors_dark['outline']}
450-
ForegroundLink={extras['link']['dark']['primary']}
451-
ForegroundNegative={extras['negative']['dark']['primary']}
452-
ForegroundNeutral={extras['neutral']['dark']['primary']}
450+
ForegroundLink={extras['link']['dark']['color']}
451+
ForegroundNegative={extras['negative']['dark']['color']}
452+
ForegroundNeutral={extras['neutral']['dark']['color']}
453453
ForegroundNormal={colors_dark['onSurfaceVariant']}
454-
ForegroundPositive={extras['positive']['dark']['primary']}
455-
ForegroundVisited={extras['visited']['dark']['primary']}
454+
ForegroundPositive={extras['positive']['dark']['color']}
455+
ForegroundVisited={extras['visited']['dark']['color']}
456456
457457
[Colors:Selection]
458458
BackgroundAlternate={colors_dark['primary']}
@@ -461,12 +461,12 @@ def __init__(
461461
DecorationHover={colors_dark['secondary']}
462462
ForegroundActive={colors_dark['onPrimary']}
463463
ForegroundInactive={colors_dark['onPrimary']}
464-
ForegroundLink={extras['link']['dark']['onPrimaryFixedVariant']}
465-
ForegroundNegative={extras['negative']['dark']['onPrimaryFixedVariant']}
466-
ForegroundNeutral={extras['neutral']['dark']['onPrimaryFixedVariant']}
464+
ForegroundLink={extras['link']['dark']['container']}
465+
ForegroundNegative={extras['negative']['dark']['container']}
466+
ForegroundNeutral={extras['neutral']['dark']['container']}
467467
ForegroundNormal={colors_dark['onPrimary']}
468-
ForegroundPositive={extras['positive']['dark']['onPrimaryFixedVariant']}
469-
ForegroundVisited={extras['visited']['dark']['onPrimaryFixedVariant']}
468+
ForegroundPositive={extras['positive']['dark']['container']}
469+
ForegroundVisited={extras['visited']['dark']['container']}
470470
471471
[Colors:Tooltip]
472472
BackgroundAlternate={colors_dark['surfaceVariant']}
@@ -475,12 +475,12 @@ def __init__(
475475
DecorationHover={colors_dark['primary']}
476476
ForegroundActive={colors_dark['onSurface']}
477477
ForegroundInactive={colors_dark['outline']}
478-
ForegroundLink={extras['link']['dark']['primary']}
479-
ForegroundNegative={extras['negative']['dark']['primary']}
480-
ForegroundNeutral={extras['neutral']['dark']['primary']}
478+
ForegroundLink={extras['link']['dark']['color']}
479+
ForegroundNegative={extras['negative']['dark']['color']}
480+
ForegroundNeutral={extras['neutral']['dark']['color']}
481481
ForegroundNormal={colors_dark['onSurface']}
482-
ForegroundPositive={extras['positive']['dark']['primary']}
483-
ForegroundVisited={extras['visited']['dark']['primary']}
482+
ForegroundPositive={extras['positive']['dark']['color']}
483+
ForegroundVisited={extras['visited']['dark']['color']}
484484
485485
[Colors:View]
486486
BackgroundAlternate={colors_dark['surfaceContainer']}
@@ -490,27 +490,27 @@ def __init__(
490490
DecorationHover={colors_dark['inversePrimary']}
491491
ForegroundActive={colors_dark['inverseSurface']}
492492
ForegroundInactive={colors_dark['outline']}
493-
ForegroundLink={extras['link']['dark']['primary']}
494-
ForegroundNegative={extras['negative']['dark']['primary']}
495-
ForegroundNeutral={extras['neutral']['dark']['primary']}
493+
ForegroundLink={extras['link']['dark']['color']}
494+
ForegroundNegative={extras['negative']['dark']['color']}
495+
ForegroundNeutral={extras['neutral']['dark']['color']}
496496
ForegroundNormal={colors_dark['onSurface']}
497-
ForegroundPositive={extras['positive']['dark']['primary']}
498-
ForegroundVisited={extras['visited']['dark']['primary']}
497+
ForegroundPositive={extras['positive']['dark']['color']}
498+
ForegroundVisited={extras['visited']['dark']['color']}
499499
500500
[Colors:Window]
501501
BackgroundAlternate={colors_dark['surfaceVariant']}
502502
BackgroundNormal={colors_dark['surfaceContainer']}
503503
DecorationFocus={colors_dark['primary']}
504504
DecorationHover={colors_dark['primary']}
505-
ForegroundActive={extras['link']['dark']['primary']}
505+
ForegroundActive={extras['link']['dark']['color']}
506506
ForegroundInactive={colors_dark['outline']}
507-
ForegroundLink={extras['link']['dark']['primary']}
508-
ForegroundNegative={extras['negative']['dark']['primary']}
509-
ForegroundNeutral={extras['neutral']['dark']['primary']}
507+
ForegroundLink={extras['link']['dark']['color']}
508+
ForegroundNegative={extras['negative']['dark']['color']}
509+
ForegroundNeutral={extras['neutral']['dark']['color']}
510510
#--- Window titles, context icons
511511
ForegroundNormal={colors_dark['onSurfaceVariant']}
512-
ForegroundPositive={extras['positive']['dark']['primary']}
513-
ForegroundVisited={extras['visited']['dark']['primary']}
512+
ForegroundPositive={extras['positive']['dark']['color']}
513+
ForegroundVisited={extras['visited']['dark']['color']}
514514
515515
[General]
516516
ColorScheme=MaterialYouDark
@@ -712,9 +712,9 @@ def __init__(
712712
"MarkBreakpointActive": "#8b0607",
713713
"MarkBreakpointDisabled": "#820683",
714714
"MarkBreakpointReached": "#6d6e07",
715-
"MarkError": extras["negative"]["dark"]["onPrimaryFixedVariant"],
715+
"MarkError": extras["negative"]["dark"]["onColor"],
716716
"MarkExecution": "#4d4e50",
717-
"MarkWarning": extras["neutral"]["dark"]["onPrimaryFixedVariant"],
717+
"MarkWarning": extras["neutral"]["dark"]["onColor"],
718718
"ModifiedLines": "#c04900",
719719
"ReplaceHighlight": "#808021",
720720
"SavedLines": "#1c8042",
@@ -848,8 +848,8 @@ def __init__(
848848
"MarkBreakpointReached": "#ffff00",
849849
"MarkBreakpointDisabled": "#ff00ff",
850850
"MarkExecution": "#a0a0a4",
851-
"MarkWarning": extras["neutral"]["dark"]["onPrimaryFixedVariant"],
852-
"MarkError": extras["negative"]["dark"]["onPrimaryFixedVariant"],
851+
"MarkWarning": extras["neutral"]["dark"]["onColor"],
852+
"MarkError": extras["negative"]["dark"]["onColor"],
853853
"ModifiedLines": "#fdbc4b",
854854
"ReplaceHighlight": "#00ff00",
855855
"SavedLines": "#2ecc71",

src/kde_material_you_colors/utils/color_utils.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import colorsys
22
import re
33
import operator
4+
import copy
45
import numpy
56
from materialyoucolor.blend import Blend
67
from materialyoucolor.utils.color_utils import red_from_argb
78
from materialyoucolor.utils.color_utils import green_from_argb
89
from materialyoucolor.utils.color_utils import blue_from_argb
10+
from materialyoucolor.dynamiccolor.dynamic_scheme import DynamicScheme
11+
from materialyoucolor.hct import Hct
12+
from materialyoucolor.dynamiccolor.material_dynamic_colors import MaterialDynamicColors
13+
from materialyoucolor.palettes.tonal_palette import TonalPalette
914
from kde_material_you_colors.utils import math_utils
1015

1116

@@ -358,6 +363,34 @@ def argbFromHex(hex):
358363
)
359364

360365

366+
def static_color(scheme: DynamicScheme, color, blend=True) -> dict:
367+
"""_summary_
368+
369+
Args:
370+
scheme (DynamicScheme): DynamicScheme to use as source
371+
color (int): color to generate static version of
372+
blend (bool, optional): Whether to blend the color with the scheme's source color. Defaults to True.
373+
374+
Returns:
375+
dict: Static color roles for the given color in hex format
376+
"""
377+
md = MaterialDynamicColors()
378+
if blend:
379+
color = Blend.harmonize(color, scheme.source_color_argb)
380+
hct = Hct.from_int(color)
381+
palette = TonalPalette.from_hue_and_chroma(hct.hue, hct.chroma)
382+
383+
scheme2 = copy.copy(scheme)
384+
scheme2.error_palette = palette
385+
386+
return {
387+
"color": md.error.get_hex(scheme2)[:-2],
388+
"onColor": md.onError.get_hex(scheme2)[:-2],
389+
"container": md.errorContainer.get_hex(scheme2)[:-2],
390+
"onContainer": md.onErrorContainer.get_hex(scheme2)[:-2],
391+
}
392+
393+
361394
# Tests
362395
if __name__ == "__main__":
363396
# Test color blend

0 commit comments

Comments
 (0)