3030from kivy .event import EventDispatcher
3131from kivy .logger import Logger
3232from kivy .properties import (
33+ Property ,
3334 AliasProperty ,
3435 BooleanProperty ,
3536 DictProperty ,
5354
5455
5556class ThemeManager (EventDispatcher , DynamicColor ):
56- primary_palette = OptionProperty (
57- None ,
58- options = [name_color .capitalize () for name_color in hex_colormap .keys ()],
59- )
57+ primary_palette = Property (None )
6058 """
6159 The name of the color scheme that the application will use.
6260 All major `material` components will have the color
6361 of the specified color theme.
6462
63+ Works like a :class:`~kivy.properties.ColorProperty`, but also accepts
64+ color names from :attr:`kivy.utils.hex_colormap`, including keys with
65+ capital letters.
66+
67+ Example::
68+ primary_palette = (1, 0, 0, 1)
69+ primary_palette = "Red"
70+ primary_palette = "lightblue"
71+
6572 See :attr:`kivy.utils.hex_colormap` keys for available values.
6673
6774 To change the color scheme of an application:
@@ -840,6 +847,18 @@ def sync_theme_styles(self, *args) -> None:
840847 for style in self .font_styles .keys ():
841848 theme_font_styles .append (style )
842849
850+ def color_to_rgba (self , color ):
851+ # convert any supported color form to normalized RGBA [r, g, b, a].
852+ if isinstance (color , str ):
853+ c = color .strip ().lower ()
854+ # check if in map
855+ if c in hex_colormap :
856+ color = hex_colormap [c ]
857+ # use Kivy’s parser for hex
858+ if color .startswith ('#' ):
859+ return list (get_color_from_hex (color ))
860+ return color
861+
843862 def _set_application_scheme (
844863 self ,
845864 color = "blue" , # Google default
@@ -849,8 +868,7 @@ def _set_application_scheme(
849868 else :
850869 color = self .primary_palette
851870
852- color = get_color_from_hex (hex_colormap [color .lower ()])
853- color = Hct .from_int (argb_from_rgba_01 (color ))
871+ color = Hct .from_int (argb_from_rgba_01 (self .color_to_rgba (color )))
854872 color = DislikeAnalyzer .fix_if_disliked (color ).to_int ()
855873
856874 self ._set_color_names (
0 commit comments