2626import os .path
2727from timeit import default_timer
2828
29+ import kivy .utils
30+ from kivy import platform
2931from kivy .app import App
30- from kivy .logger import Logger
3132from kivy .core .window import Window
3233from kivy .event import EventDispatcher
34+ from kivy .logger import Logger
3335from kivy .properties import (
3436 AliasProperty ,
3537 BooleanProperty ,
38+ ColorProperty ,
3639 DictProperty ,
3740 NumericProperty ,
3841 ObjectProperty ,
3942 OptionProperty ,
4043 StringProperty ,
4144)
42- from kivy import platform
4345from kivy .utils import get_color_from_hex , rgba , hex_colormap
46+ from materialyoucolor .dislike .dislike_analyzer import DislikeAnalyzer
47+ from materialyoucolor .dynamiccolor .material_dynamic_colors import (
48+ MaterialDynamicColors ,
49+ )
50+ from materialyoucolor .hct import Hct
51+ from materialyoucolor .scheme .scheme_android import SchemeAndroid
52+ from materialyoucolor .utils .color_utils import argb_from_rgba_01
53+ from materialyoucolor .utils .platform_utils import SCHEMES , get_dynamic_scheme
4454
4555from kivymd .dynamic_color import DynamicColor
4656from kivymd .font_definitions import theme_font_styles
4757from kivymd .material_resources import DEVICE_IOS
4858
49- from materialyoucolor .utils .color_utils import argb_from_rgba_01
50- from materialyoucolor .dynamiccolor .material_dynamic_colors import (
51- MaterialDynamicColors ,
52- )
53- from materialyoucolor .utils .platform_utils import SCHEMES , get_dynamic_scheme
54- from materialyoucolor .hct import Hct
55- from materialyoucolor .dislike .dislike_analyzer import DislikeAnalyzer
59+
60+ # A small patch to support color names even when they are not in lower case
61+ kivy .utils .colormap = type ("_colormap" ,(),{
62+ "get" : staticmethod (
63+ lambda value , * args : kivy .utils .colormap .get (value .lower (), * args )
64+ )},)()
5665
5766
5867class ThemeManager (EventDispatcher , DynamicColor ):
59- primary_palette = OptionProperty (
60- None ,
61- options = [name_color .capitalize () for name_color in hex_colormap .keys ()],
62- )
68+ primary_palette = ColorProperty ("blue" )
6369 """
64- The name of the color scheme that the application will use .
70+ The color which will be used to generate scheme .
6571 All major `material` components will have the color
66- of the specified color theme.
67-
68- See :attr:`kivy.utils.hex_colormap` keys for available values.
72+ of the generated color scheme.
6973
7074 To change the color scheme of an application:
7175
@@ -140,8 +144,8 @@ def build(self):
140144 .. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/primary-palette-m3.png
141145 :align: center
142146
143- :attr:`primary_palette` is an :class:`~kivy.properties.OptionProperty `
144- and defaults to `None `.
147+ :attr:`primary_palette` is an :class:`~kivy.properties.ColorProperty `
148+ and defaults to `blue `.
145149 """
146150
147151 dynamic_color_quality = NumericProperty (1 if platform == "android" else 10 )
@@ -237,7 +241,7 @@ def callback(permission, results):
237241 :attr:`dynamic_color` is an :class:`~kivy.properties.BooleanProperty`
238242 and defaults to `False`.
239243 """
240-
244+
241245 dynamic_scheme_name = OptionProperty ("TONAL_SPOT" , options = SCHEMES .keys ())
242246 """
243247 Name of the dynamic scheme. Availabe schemes `TONAL_SPOT`, `SPRITZ`
@@ -640,7 +644,7 @@ def build(self):
640644 """
641645
642646 _size_current_wallpaper = NumericProperty (0 )
643- _dark_mode = lambda self : False if self .theme_style == "Light" else True
647+ _dark_mode = lambda self : False if self .theme_style == "Light" else True
644648
645649 def __init__ (self , ** kwargs ):
646650 super ().__init__ (** kwargs )
@@ -663,7 +667,7 @@ def set_colors(self, *args) -> None:
663667 fallback_wallpaper_path = self .path_to_wallpaper ,
664668 fallback_scheme_name = self .dynamic_scheme_name ,
665669 message_logger = Logger .info ,
666- logger_head = "KivyMD"
670+ logger_head = "KivyMD" ,
667671 )
668672 if system_scheme :
669673 self ._set_color_names (system_scheme )
@@ -700,12 +704,10 @@ def sync_theme_styles(self, *args) -> None:
700704
701705 def _set_application_scheme (
702706 self ,
703- color = "blue" , # Google default
707+ color = [ 0 , 0 , 1 , 1 ], # Google default
704708 ) -> None :
705709 if not color :
706- color = "blue"
707-
708- color = get_color_from_hex (hex_colormap [color .lower ()])
710+ color = [0 , 0 , 1 , 1 ]
709711 color = Hct .from_int (argb_from_rgba_01 (color ))
710712 color = DislikeAnalyzer .fix_if_disliked (color ).to_int ()
711713
@@ -718,10 +720,22 @@ def _set_application_scheme(
718720 )
719721
720722 def _set_color_names (self , scheme ) -> None :
723+ # Dynamic colors
724+ _added_colors = []
721725 for color_name in vars (MaterialDynamicColors ).keys ():
722726 attr = getattr (MaterialDynamicColors , color_name )
723727 if hasattr (attr , "get_hct" ):
724728 color_value = rgba (attr .get_hct (scheme ).to_rgba ())
729+ _added_colors .append (color_name )
730+ exec (f"self.{ color_name } Color = { color_value } " )
731+
732+ # Static colors
733+ static_scheme = getattr (SchemeAndroid , self .theme_style .lower ())(
734+ scheme .source_color_argb
735+ )
736+ for color_name in static_scheme .props .keys ():
737+ if color_name not in _added_colors : # prefer dynamic
738+ color_value = rgba (static_scheme .props [color_name ])
725739 exec (f"self.{ color_name } Color = { color_value } " )
726740
727741 self .disabledTextColor = self ._get_disabled_hint_text_color ()
0 commit comments