Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def on_tab_press(self, *args):
par = self.parent_widget
par.ids.tab_manager.current = self.name
if par.previous_tab is not self:
Animation(_label_font_size=sp(12), d=0.1).start(par.previous_tab.header)
Animation(_current_color=par.previous_tab.header.theme_cls.disabled_hint_text_color, d=0.1).start(par.previous_tab.header)
par.previous_tab.header.active = False
self.header.active = True
par.previous_tab = self
def on_leave(self, *args):
pass
class TabbedPanelBase(ThemableBehavior, SpecificBackgroundColorBehavior, BoxLayout):
"""
A class that contains all variables a TabPannel must have
It is here so I (zingballyhoo) don't get mad about the TabbedPannels not being DRY
"""
tabs = ListProperty([])
# Current tab name
current = StringProperty(None)
previous_tab = ObjectProperty(None)
class MDTabbedPanel(TabbedPanelBase):
""" A tab panel that is implemented by delegating all tabs
to a ScreenManager.
"""
class ColorSelector(MDIconButton):
color_name = OptionProperty(
'Indigo',
options=['Red', 'Pink', 'Purple', 'DeepPurple', 'Indigo', 'Blue',
'LightBlue', 'Cyan', 'Teal', 'Green', 'LightGreen',
'Lime', 'Yellow', 'Amber', 'Orange', 'DeepOrange',
'Brown', 'Grey', 'BlueGrey'])
def rgb_hex(self, col):
return get_color_from_hex(colors[col][self.theme_cls.accent_hue])
class MDThemePicker(ThemableBehavior, FloatLayout, ModalView,
SpecificBackgroundColorBehavior,
RectangularElevationBehavior):
pass
if __name__ == "__main__":
from kivy.app import App
from kivymd.theming import ThemeManager
class ThemePickerApp(App):
theme_cls = ThemeManager()
def build(self):
main_widget = Builder.load_string("""
#:import MDRaisedButton kivymd.button.MDRaisedButton
#:import MDThemePicker kivymd.theme_picker.MDThemePicker
FloatLayout:
AnchorLayout):
text = StringProperty()
owner = ObjectProperty()
is_today = BooleanProperty(False)
is_selected = BooleanProperty(False)
def on_release(self):
self.owner.set_selected_widget(self)
class WeekdayLabel(MDLabel):
pass
class MDDatePicker(FloatLayout, ThemableBehavior, RectangularElevationBehavior,
SpecificBackgroundColorBehavior, ModalView):
_sel_day_widget = ObjectProperty()
cal_list = None
cal_layout = ObjectProperty()
sel_year = NumericProperty()
sel_month = NumericProperty()
sel_day = NumericProperty()
day = NumericProperty()
month = NumericProperty()
year = NumericProperty()
today = date.today()
callback = ObjectProperty()
background_color = ListProperty([0, 0, 0, 0.7])
class SetDateError(Exception):
pass
from kivy.lang import Builder
from kivy.properties import (ListProperty, ObjectProperty, OptionProperty,
StringProperty)
from kivy.uix.accordion import Accordion, AccordionItem
from kivy.uix.boxlayout import BoxLayout
from kivymd.backgroundcolorbehavior import SpecificBackgroundColorBehavior
from kivymd.list import OneLineListItem
from kivymd.theming import ThemableBehavior
class MDAccordionItemTitleLayout(ThemableBehavior, BoxLayout):
pass
class MDAccordion(ThemableBehavior, SpecificBackgroundColorBehavior, Accordion):
pass
class MDAccordionSubItem(OneLineListItem):
parent_item = ObjectProperty()
class MDAccordionItem(ThemableBehavior, AccordionItem):
title_theme_color = OptionProperty(None, allownone=True,
options=['Primary', 'Secondary', 'Hint',
'Error', 'Custom'])
''' Color theme for title text and icon '''
title_color = ListProperty(None, allownone=True)
''' Color for title text and icon if `title_theme_color` is Custom '''
class ColorSelector(MDIconButton):
color_name = OptionProperty(
'Indigo',
options=['Red', 'Pink', 'Purple', 'DeepPurple', 'Indigo', 'Blue',
'LightBlue', 'Cyan', 'Teal', 'Green', 'LightGreen',
'Lime', 'Yellow', 'Amber', 'Orange', 'DeepOrange',
'Brown', 'Grey', 'BlueGrey'])
def rgb_hex(self, col):
return get_color_from_hex(colors[col][self.theme_cls.accent_hue])
class MDThemePicker(ThemableBehavior, FloatLayout, ModalView,
SpecificBackgroundColorBehavior,
RectangularElevationBehavior):
pass
if __name__ == "__main__":
from kivy.app import App
from kivymd.theming import ThemeManager
class ThemePickerApp(App):
theme_cls = ThemeManager()
def build(self):
main_widget = Builder.load_string('''
#:import MDRaisedButton kivymd.button.MDRaisedButton
#:import MDThemePicker kivymd.theme_picker.MDThemePicker
opposite_colors: root.opposite_colors
theme_text_color: 'Custom'
text_color: root.specific_text_color
text: root.title
shorten: True
shorten_from: 'right'
BoxLayout:
id: right_actions
orientation: 'horizontal'
size_hint_x: None
padding: [0, (self.height - dp(48))/2]
''')
class Toolbar(ThemableBehavior, RectangularElevationBehavior,
SpecificBackgroundColorBehavior, BoxLayout):
left_action_items = ListProperty()
"""The icons on the left of the Toolbar.
To add one, append a list like the following:
['icon_name', callback]
where 'icon_name' is a string that corresponds to an icon definition and
callback is the function called on a touch release event.
"""
right_action_items = ListProperty()
"""The icons on the left of the Toolbar.
Works the same way as :attr:`left_action_items`
"""
def __init__(self, **kwargs):
super(SpecificBackgroundColorBehavior, self).__init__(**kwargs)
if hasattr(self, 'theme_cls'):
self.theme_cls.bind(primary_palette=self._update_specific_text_color)
self.theme_cls.bind(accent_palette=self._update_specific_text_color)
self.theme_cls.bind(theme_style=self._update_specific_text_color)
self.bind(background_hue=self._update_specific_text_color)
self.bind(background_palette=self._update_specific_text_color)
self._update_specific_text_color(None, None)
md_bg_color: root.theme_cls.primary_color
theme_text_color: 'Custom'
text_color: root.specific_text_color
:
# Defaults to 56-by-56 and a backround of the accent color according to
# guidelines
size: (dp(56), dp(56))
md_bg_color: root.theme_cls.accent_color
theme_text_color: 'Custom'
text_color: root.specific_text_color
''')
class BaseButton(ThemableBehavior, ButtonBehavior,
SpecificBackgroundColorBehavior, AnchorLayout):
'''
Abstract base class for all MD buttons. This class handles the button's
colors (disabled/down colors handled in children classes as those depend on
type of button) as well as the disabled state.
'''
_md_bg_color_down = ListProperty(None, allownone=True)
_md_bg_color_disabled = ListProperty(None, allownone=True)
_current_button_color = ListProperty([0., 0., 0., 0.])
theme_text_color = OptionProperty(None, allownone=True,
options=['Primary', 'Secondary', 'Hint',
'Error', 'Custom',
'ContrastParentBackground'])
text_color = ListProperty(None, allownone=True)
opposite_colors = BooleanProperty(False)
def __init__(self, **kwargs):