26
26
import os .path
27
27
from timeit import default_timer
28
28
29
- import kivy .utils
30
- from kivy import platform
31
29
from kivy .app import App
30
+ from kivy .logger import Logger
32
31
from kivy .core .window import Window
33
32
from kivy .event import EventDispatcher
34
- from kivy .logger import Logger
35
33
from kivy .properties import (
36
34
AliasProperty ,
37
35
BooleanProperty ,
38
- ColorProperty ,
39
36
DictProperty ,
40
37
NumericProperty ,
41
38
ObjectProperty ,
42
39
OptionProperty ,
43
40
StringProperty ,
44
41
)
42
+ from kivy import platform
45
43
from 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
54
44
55
45
from kivymd .dynamic_color import DynamicColor
56
46
from kivymd .font_definitions import theme_font_styles
57
47
from kivymd .material_resources import DEVICE_IOS
58
48
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
- )},)()
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
65
56
66
57
67
58
class ThemeManager (EventDispatcher , DynamicColor ):
68
- primary_palette = ColorProperty ("blue" )
59
+ primary_palette = OptionProperty (
60
+ None ,
61
+ options = [name_color .capitalize () for name_color in hex_colormap .keys ()],
62
+ )
69
63
"""
70
- The color which will be used to generate scheme .
64
+ The name of the color scheme that the application will use .
71
65
All major `material` components will have the color
72
- of the generated color scheme.
66
+ of the specified color theme.
67
+
68
+ See :attr:`kivy.utils.hex_colormap` keys for available values.
73
69
74
70
To change the color scheme of an application:
75
71
@@ -144,8 +140,8 @@ def build(self):
144
140
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/primary-palette-m3.png
145
141
:align: center
146
142
147
- :attr:`primary_palette` is an :class:`~kivy.properties.ColorProperty `
148
- and defaults to `blue `.
143
+ :attr:`primary_palette` is an :class:`~kivy.properties.OptionProperty `
144
+ and defaults to `None `.
149
145
"""
150
146
151
147
dynamic_color_quality = NumericProperty (1 if platform == "android" else 10 )
@@ -241,7 +237,7 @@ def callback(permission, results):
241
237
:attr:`dynamic_color` is an :class:`~kivy.properties.BooleanProperty`
242
238
and defaults to `False`.
243
239
"""
244
-
240
+
245
241
dynamic_scheme_name = OptionProperty ("TONAL_SPOT" , options = SCHEMES .keys ())
246
242
"""
247
243
Name of the dynamic scheme. Availabe schemes `TONAL_SPOT`, `SPRITZ`
@@ -644,7 +640,7 @@ def build(self):
644
640
"""
645
641
646
642
_size_current_wallpaper = NumericProperty (0 )
647
- _dark_mode = lambda self : False if self .theme_style == "Light" else True
643
+ _dark_mode = lambda self : False if self .theme_style == "Light" else True
648
644
649
645
def __init__ (self , ** kwargs ):
650
646
super ().__init__ (** kwargs )
@@ -667,7 +663,7 @@ def set_colors(self, *args) -> None:
667
663
fallback_wallpaper_path = self .path_to_wallpaper ,
668
664
fallback_scheme_name = self .dynamic_scheme_name ,
669
665
message_logger = Logger .info ,
670
- logger_head = "KivyMD" ,
666
+ logger_head = "KivyMD"
671
667
)
672
668
if system_scheme :
673
669
self ._set_color_names (system_scheme )
@@ -704,10 +700,12 @@ def sync_theme_styles(self, *args) -> None:
704
700
705
701
def _set_application_scheme (
706
702
self ,
707
- color = [ 0 , 0 , 1 , 1 ], # Google default
703
+ color = "blue" , # Google default
708
704
) -> None :
709
705
if not color :
710
- color = [0 , 0 , 1 , 1 ]
706
+ color = "blue"
707
+
708
+ color = get_color_from_hex (hex_colormap [color .lower ()])
711
709
color = Hct .from_int (argb_from_rgba_01 (color ))
712
710
color = DislikeAnalyzer .fix_if_disliked (color ).to_int ()
713
711
@@ -720,22 +718,10 @@ def _set_application_scheme(
720
718
)
721
719
722
720
def _set_color_names (self , scheme ) -> None :
723
- # Dynamic colors
724
- _added_colors = []
725
721
for color_name in vars (MaterialDynamicColors ).keys ():
726
722
attr = getattr (MaterialDynamicColors , color_name )
727
723
if hasattr (attr , "get_hct" ):
728
724
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 ])
739
725
exec (f"self.{ color_name } Color = { color_value } " )
740
726
741
727
self .disabledTextColor = self ._get_disabled_hint_text_color ()
0 commit comments