class MaterialCheckBox(ThemeBehaviour, CircularRippleBehavior, ToggleButtonBehavior, Label): _bg_color_down = ListProperty([1, 1, 1, 0]) def _get_bg_color_down(self): return self._bg_color_down def _set_bg_color_down(self, color, alpha=None): if len(color) == 2: self._bg_color_down = get_rgba_color(color, control_alpha=alpha) elif len(color) == 4: self._bg_color_down = color background_color_down = AliasProperty(_get_bg_color_down, _set_bg_color_down, bind=('_bg_color_down', )) _bg_color_disabled = ListProperty([1, 1, 1, 0]) def _get_bg_color_disabled(self): return self._bg_color_disabled def _set_bg_color_disabled(self, color, alpha=None): if len(color) == 2: self._bg_color_disabled = get_rgba_color(color, control_alpha=alpha) elif len(color) == 4: self._bg_color_disabled = color background_color_disabled = AliasProperty(_get_bg_color_disabled, _set_bg_color_disabled, bind=('_bg_color_disabled', )) active = BooleanProperty(False) _icon_normal = StringProperty(u"{}".format(get_icon_char('md-check-box-outline-blank'))) _icon_active = StringProperty(u"{}".format(get_icon_char('md-check-box'))) def __init__(self, **kwargs): super(MaterialCheckBox, self).__init__(**kwargs) self.register_event_type('on_active') self.color = self._theme_cls.secondary_text_color() self.check_anim_out = Animation(font_size=0, duration=.1, t='out_quad') self.check_anim_in = Animation(font_size=sp(24), duration=.1, t='out_quad') self.check_anim_in.bind(on_complete=self._set_state) self.check_anim_out.bind(on_complete=lambda *x: self.check_anim_in.start(self)) def on_release(self): Animation.cancel_all(self, '_size') self.check_anim_out.start(self) def _set_state(self, *args): if self.state == 'down': self.active = True self.color = self._theme_cls.primary_color else: self.active = False self.color = self._theme_cls.secondary_text_color() def on_active(self, instance, value): self.state = 'down' if value else 'normal'
def on_font_style(self, instance, style): self.font_style = style if self.font_style == 'Button': self.halign = 'center' self.valign = 'middle' if self.font_style == 'Icon': self.text = u"{}".format(get_icon_char(self.icon)) self.font_name = self._font_styles[self.font_style][0] self.bold = self._font_styles[self.font_style][1] self.font_size = sp(self._font_styles[self.font_style][2])
def on_icon(self, instance, icon): if self.font_style == 'Icon': self.text = u"{}".format(get_icon_char(self.icon))