Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _set_colors(self, *args):
if self.theme_cls.theme_style == "Dark":
self._track_color_normal = get_color_from_hex("FFFFFF")
self._track_color_normal[3] = 0.3
self._track_color_active = self._track_color_normal
self._track_color_disabled = self._track_color_normal
self.thumb_color = get_color_from_hex(colors["Gray"]["400"])
self.thumb_color_down = get_color_from_hex(
colors[self.theme_cls.primary_palette]["200"]
)
self.thumb_color_disabled = get_color_from_hex(
colors["Gray"]["800"]
)
else:
self._track_color_normal = get_color_from_hex("000000")
self._track_color_normal[3] = 0.26
self._track_color_active = get_color_from_hex("000000")
self._track_color_active[3] = 0.38
self._track_color_disabled = get_color_from_hex("000000")
self._track_color_disabled[3] = 0.26
self.thumb_color_down = self.theme_cls.primary_color
def _get_bg_dark(self, opposite=False):
theme_style = self._get_theme_style(opposite)
if theme_style == 'Light':
return get_color_from_hex(colors['Light']['AppBar'])
elif theme_style == 'Dark':
return get_color_from_hex(colors['Dark']['AppBar'])
def _set_colors(self, *args):
self._track_color_normal = self.theme_cls.disabled_hint_text_color
if self.theme_cls.theme_style == 'Dark':
self._track_color_active = self.theme_cls.primary_color
self._track_color_active[3] = .5
self._track_color_disabled = get_color_from_hex('FFFFFF')
self._track_color_disabled[3] = .1
self.thumb_color = get_color_from_hex(colors['Grey']['400'])
self.thumb_color_down = get_color_from_hex(
colors[self.theme_cls.primary_palette]['200'])
self.thumb_color_disabled = get_color_from_hex(
colors['Grey']['800'])
else:
self._track_color_active = get_color_from_hex(
colors[self.theme_cls.primary_palette]['200'])
self._track_color_active[3] = .5
self._track_color_disabled = self.theme_cls.disabled_hint_text_color
self.thumb_color_down = self.theme_cls.primary_color
self.thumb_color_disabled = get_color_from_hex(
colors['Grey']['400'])
def get_contrast_text_color(color, use_color_brightness=True):
if use_color_brightness:
contrast_color = _black_or_white_by_color_brightness(color)
else:
contrast_color = _black_or_white_by_contrast_ratio(color)
if contrast_color == "white":
return 1, 1, 1, 1
else:
return 0, 0, 0, 1
if __name__ == "__main__":
from kivy.utils import get_color_from_hex
from kivymd.color_definitions import colors, text_colors
for c in colors.items():
if c[0] in ["Light", "Dark"]:
continue
color = c[0]
print(f"For the {color} color palette:")
for name, hex_color in c[1].items():
if hex_color:
col = get_color_from_hex(hex_color)
col_bri = get_contrast_text_color(col)
con_rat = get_contrast_text_color(col, use_color_brightness=False)
text_color = text_colors[c[0]][name]
print(
f" The {name} hue gives {col_bri} using color "
f"brightness, {con_rat} using contrast ratio, and "
def rgb_hex(self, col):
return get_color_from_hex(colors[col][self.theme_cls.accent_hue])
def _get_error_color(self):
return get_color_from_hex(colors['Red']['A700'])
def rgb_hex(self, col):
return get_color_from_hex(colors[col][self.theme_cls.accent_hue])
def rgb_hex(self, col):
return get_color_from_hex(colors[col][self.theme_cls.accent_hue])
def get_contrast_text_color(color, use_color_brightness=True):
if use_color_brightness:
contrast_color = _black_or_white_by_color_brightness(color)
else:
contrast_color = _black_or_white_by_contrast_ratio(color)
if contrast_color == 'white':
return 1, 1, 1, 1
else:
return 0, 0, 0, 1
if __name__ == '__main__':
from kivy.utils import get_color_from_hex
from kivymd.color_definitions import colors, text_colors
for c in list(colors.items()):
if c[0] in ['Light', 'Dark']:
continue
print(("For the {} color palette:".format(c[0])))
for name, hex_color in list(c[1].items()):
if hex_color:
col = get_color_from_hex(hex_color)
col_bri = get_contrast_text_color(col)
con_rat = get_contrast_text_color(col, use_color_brightness=False)
text_color = text_colors[c[0]][name]
print((" The {} hue gives {} using color brightness, {} using contrast ratio, and {} from the MD spec"
.format(name, col_bri, con_rat, text_color)))
def _set_colors(self, *args):
if self.theme_cls.theme_style == 'Dark':
self._track_color_normal = get_color_from_hex('FFFFFF')
self._track_color_normal[3] = .3
self._track_color_active = self._track_color_normal
self._track_color_disabled = self._track_color_normal
self.thumb_color = get_color_from_hex(colors['Grey']['400'])
self.thumb_color_down = get_color_from_hex(colors[self.theme_cls.primary_palette]['200'])
self.thumb_color_disabled = get_color_from_hex(colors['Grey']['800'])
else:
self._track_color_normal = get_color_from_hex('000000')
self._track_color_normal[3] = 0.26
self._track_color_active = get_color_from_hex('000000')
self._track_color_active[3] = 0.38
self._track_color_disabled = get_color_from_hex('000000')
self._track_color_disabled[3] = 0.26
self.thumb_color_down = self.theme_cls.primary_color