Skip to content

Commit c6d0de0

Browse files
committed
Revert "theming: change primary_color to ColorProperty"
This reverts commit 6ae68ec.
1 parent 6ae68ec commit c6d0de0

File tree

2 files changed

+26
-232
lines changed

2 files changed

+26
-232
lines changed

Diff for: kivymd/dynamic_color.py

-192
Original file line numberDiff line numberDiff line change
@@ -630,195 +630,3 @@ class DynamicColor:
630630
:attr:`rippleColor` is an :class:`~kivy.properties.ColorProperty`
631631
and defaults to `'#BDBDBD'`.
632632
"""
633-
634-
colorAccentPrimaryColor = ColorProperty()
635-
"""
636-
Color accent primary.
637-
638-
:attr:`colorAccentPrimaryColor` is an :class:`~kivy.properties.ColorProperty`
639-
and defaults to `None`.
640-
"""
641-
642-
colorAccentPrimaryVariantColor = ColorProperty()
643-
"""
644-
Color accent primary variant.
645-
646-
:attr:`colorAccentPrimaryVariantColor` is an :class:`~kivy.properties.ColorProperty`
647-
and defaults to `None`.
648-
"""
649-
650-
colorAccentSecondaryColor = ColorProperty()
651-
"""
652-
Color accent secondary.
653-
654-
:attr:`colorAccentSecondaryColor` is an :class:`~kivy.properties.ColorProperty`
655-
and defaults to `None`.
656-
"""
657-
658-
colorAccentSecondaryVariantColor = ColorProperty()
659-
"""
660-
Color accent secondary variant.
661-
662-
:attr:`colorAccentSecondaryVariantColor` is an :class:`~kivy.properties.ColorProperty`
663-
and defaults to `None`.
664-
"""
665-
666-
colorAccentTertiaryColor = ColorProperty()
667-
"""
668-
Color accent tertiary.
669-
670-
:attr:`colorAccentTertiaryColor` is an :class:`~kivy.properties.ColorProperty`
671-
and defaults to `None`.
672-
"""
673-
674-
colorAccentTertiaryVariantColor = ColorProperty()
675-
"""
676-
Color accent tertiary variant.
677-
678-
:attr:`colorAccentTertiaryVariantColor` is an :class:`~kivy.properties.ColorProperty`
679-
and defaults to `None`.
680-
"""
681-
682-
textColorPrimaryColor = ColorProperty()
683-
"""
684-
Text color primary.
685-
686-
:attr:`textColorPrimaryColor` is an :class:`~kivy.properties.ColorProperty`
687-
and defaults to `None`.
688-
"""
689-
690-
textColorSecondaryColor = ColorProperty()
691-
"""
692-
Text color secondary.
693-
694-
:attr:`textColorSecondaryColor` is an :class:`~kivy.properties.ColorProperty`
695-
and defaults to `None`.
696-
"""
697-
698-
textColorTertiaryColor = ColorProperty()
699-
"""
700-
Text color tertiary.
701-
702-
:attr:`textColorTertiaryColor` is an :class:`~kivy.properties.ColorProperty`
703-
and defaults to `None`.
704-
"""
705-
706-
textColorPrimaryInverseColor = ColorProperty()
707-
"""
708-
Text color primary inverse.
709-
710-
:attr:`textColorPrimaryInverseColor` is an :class:`~kivy.properties.ColorProperty`
711-
and defaults to `None`.
712-
"""
713-
714-
textColorSecondaryInverseColor = ColorProperty()
715-
"""
716-
Text color secondary inverse.
717-
718-
:attr:`textColorSecondaryInverseColor` is an :class:`~kivy.properties.ColorProperty`
719-
and defaults to `None`.
720-
"""
721-
722-
textColorTertiaryInverseColor = ColorProperty()
723-
"""
724-
Text color tertiary inverse.
725-
726-
:attr:`textColorTertiaryInverseColor` is an :class:`~kivy.properties.ColorProperty`
727-
and defaults to `None`.
728-
"""
729-
730-
colorBackgroundColor = ColorProperty()
731-
"""
732-
Color background.
733-
734-
:attr:`colorBackgroundColor` is an :class:`~kivy.properties.ColorProperty`
735-
and defaults to `None`.
736-
"""
737-
738-
colorBackgroundFloatingColor = ColorProperty()
739-
"""
740-
Color background floating.
741-
742-
:attr:`colorBackgroundFloatingColor` is an :class:`~kivy.properties.ColorProperty`
743-
and defaults to `None`.
744-
"""
745-
746-
colorSurfaceColor = ColorProperty()
747-
"""
748-
Color surface.
749-
750-
:attr:`colorSurfaceColor` is an :class:`~kivy.properties.ColorProperty`
751-
and defaults to `None`.
752-
"""
753-
754-
colorSurfaceVariantColor = ColorProperty()
755-
"""
756-
Color surface variant.
757-
758-
:attr:`colorSurfaceVariantColor` is an :class:`~kivy.properties.ColorProperty`
759-
and defaults to `None`.
760-
"""
761-
762-
colorSurfaceHighlightColor = ColorProperty()
763-
"""
764-
Color surface highlight.
765-
766-
:attr:`colorSurfaceHighlightColor` is an :class:`~kivy.properties.ColorProperty`
767-
and defaults to `None`.
768-
"""
769-
770-
surfaceHeaderColor = ColorProperty()
771-
"""
772-
Surface header.
773-
774-
:attr:`surfaceHeaderColor` is an :class:`~kivy.properties.ColorProperty`
775-
and defaults to `None`.
776-
"""
777-
778-
underSurfaceColor = ColorProperty()
779-
"""
780-
Under surface.
781-
782-
:attr:`underSurfaceColor` is an :class:`~kivy.properties.ColorProperty`
783-
and defaults to `None`.
784-
"""
785-
786-
offStateColor = ColorProperty()
787-
"""
788-
Off state.
789-
790-
:attr:`offStateColor` is an :class:`~kivy.properties.ColorProperty`
791-
and defaults to `None`.
792-
"""
793-
794-
accentSurfaceColor = ColorProperty()
795-
"""
796-
Accent surface.
797-
798-
:attr:`accentSurfaceColor` is an :class:`~kivy.properties.ColorProperty`
799-
and defaults to `None`.
800-
"""
801-
802-
textPrimaryOnAccentColor = ColorProperty()
803-
"""
804-
Text primary on accent.
805-
806-
:attr:`textPrimaryOnAccentColor` is an :class:`~kivy.properties.ColorProperty`
807-
and defaults to `None`.
808-
"""
809-
810-
textSecondaryOnAccentColor = ColorProperty()
811-
"""
812-
Text secondary on accent.
813-
814-
:attr:`textSecondaryOnAccentColor` is an :class:`~kivy.properties.ColorProperty`
815-
and defaults to `None`.
816-
"""
817-
818-
volumeBackgroundColor = ColorProperty()
819-
"""
820-
Volume background.
821-
822-
:attr:`volumeBackgroundColor` is an :class:`~kivy.properties.ColorProperty`
823-
and defaults to `None`.
824-
"""

Diff for: kivymd/theming.py

+26-40
Original file line numberDiff line numberDiff line change
@@ -26,50 +26,46 @@
2626
import os.path
2727
from timeit import default_timer
2828

29-
import kivy.utils
30-
from kivy import platform
3129
from kivy.app import App
30+
from kivy.logger import Logger
3231
from kivy.core.window import Window
3332
from kivy.event import EventDispatcher
34-
from kivy.logger import Logger
3533
from kivy.properties import (
3634
AliasProperty,
3735
BooleanProperty,
38-
ColorProperty,
3936
DictProperty,
4037
NumericProperty,
4138
ObjectProperty,
4239
OptionProperty,
4340
StringProperty,
4441
)
42+
from kivy import platform
4543
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
5444

5545
from kivymd.dynamic_color import DynamicColor
5646
from kivymd.font_definitions import theme_font_styles
5747
from kivymd.material_resources import DEVICE_IOS
5848

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
6556

6657

6758
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+
)
6963
"""
70-
The color which will be used to generate scheme.
64+
The name of the color scheme that the application will use.
7165
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.
7369
7470
To change the color scheme of an application:
7571
@@ -144,8 +140,8 @@ def build(self):
144140
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/primary-palette-m3.png
145141
:align: center
146142
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`.
149145
"""
150146

151147
dynamic_color_quality = NumericProperty(1 if platform == "android" else 10)
@@ -241,7 +237,7 @@ def callback(permission, results):
241237
:attr:`dynamic_color` is an :class:`~kivy.properties.BooleanProperty`
242238
and defaults to `False`.
243239
"""
244-
240+
245241
dynamic_scheme_name = OptionProperty("TONAL_SPOT", options=SCHEMES.keys())
246242
"""
247243
Name of the dynamic scheme. Availabe schemes `TONAL_SPOT`, `SPRITZ`
@@ -644,7 +640,7 @@ def build(self):
644640
"""
645641

646642
_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
648644

649645
def __init__(self, **kwargs):
650646
super().__init__(**kwargs)
@@ -667,7 +663,7 @@ def set_colors(self, *args) -> None:
667663
fallback_wallpaper_path=self.path_to_wallpaper,
668664
fallback_scheme_name=self.dynamic_scheme_name,
669665
message_logger=Logger.info,
670-
logger_head="KivyMD",
666+
logger_head="KivyMD"
671667
)
672668
if system_scheme:
673669
self._set_color_names(system_scheme)
@@ -704,10 +700,12 @@ def sync_theme_styles(self, *args) -> None:
704700

705701
def _set_application_scheme(
706702
self,
707-
color=[0, 0, 1, 1], # Google default
703+
color = "blue", # Google default
708704
) -> None:
709705
if not color:
710-
color = [0, 0, 1, 1]
706+
color = "blue"
707+
708+
color = get_color_from_hex(hex_colormap[color.lower()])
711709
color = Hct.from_int(argb_from_rgba_01(color))
712710
color = DislikeAnalyzer.fix_if_disliked(color).to_int()
713711

@@ -720,22 +718,10 @@ def _set_application_scheme(
720718
)
721719

722720
def _set_color_names(self, scheme) -> None:
723-
# Dynamic colors
724-
_added_colors = []
725721
for color_name in vars(MaterialDynamicColors).keys():
726722
attr = getattr(MaterialDynamicColors, color_name)
727723
if hasattr(attr, "get_hct"):
728724
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])
739725
exec(f"self.{color_name}Color = {color_value}")
740726

741727
self.disabledTextColor = self._get_disabled_hint_text_color()

0 commit comments

Comments
 (0)