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_ellipse(self, instance, value):
super(CircularRippleBehavior, self)._set_ellipse(instance, value)
if self.ellipse.size[0] > self.width * .6 and not self.fading_out:
self.fade_out()
self.ellipse.pos = (self.center_x - self.ripple_rad / 2.,
self.center_y - self.ripple_rad / 2.)
if t.theme_style == 'Dark':
if self.md_bg_color == t.primary_color:
c = t.primary_dark
elif self.md_bg_color == t.accent_color:
c = t.accent_dark
return c
def _get_md_bg_color_disabled(self):
if self.theme_cls.theme_style == 'Dark':
c = (1., 1., 1., 0.12)
else:
c = (0., 0., 0., 0.12)
return c
class BaseRoundButton(CircularRippleBehavior, BaseButton):
'''
Abstract base class for all round buttons, bringing in the appropriate
on-touch behavior
'''
pass
class BaseRectangularButton(RectangularRippleBehavior, BaseButton):
'''
Abstract base class for all rectangular buttons, bringing in the
appropriate on-touch behavior. Also maintains the correct minimum width
as stated in guidelines.
'''
width = BoundedNumericProperty(dp(88), min=dp(88), max=None,
errorhandler=lambda x: dp(88))
text = StringProperty('')
else:
self.shown = False
def set_widget(self, widget):
self.selected_widget = widget
self.pos = widget.pos
self.move_resize(do_again=True)
self.update()
def move_resize(self, window=None, width=None, height=None, do_again=True):
self.pos = self.selected_widget.pos
if do_again:
Clock.schedule_once(lambda x: self.move_resize(do_again=False), 0.01)
class DayButton(ThemableBehavior, CircularRippleBehavior, ButtonBehavior,
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):
md_icons['checkbox-marked-outline'])
self.active = True
else:
self.check_anim_in.cancel(self)
self.check_anim_out.start(self)
self._radio_icon = "{}".format(
md_icons['checkbox-blank-circle-outline'])
self._checkbox_icon = "{}".format(
md_icons['checkbox-blank-outline'])
self.active = False
def on_active(self, instance, value):
self.state = 'down' if value else 'normal'
class Thumb(CircularElevationBehavior, CircularRippleBehavior, ButtonBehavior,
Widget):
ripple_scale = NumericProperty(2)
def _set_ellipse(self, instance, value):
self.ellipse.size = (self.ripple_rad, self.ripple_rad)
if self.ellipse.size[0] > self.width * 1.5 and not self.fading_out:
self.fade_out()
self.ellipse.pos = (self.center_x - self.ripple_rad / 2.,
self.center_y - self.ripple_rad / 2.)
self.stencil.pos = (
self.center_x - (self.width * self.ripple_scale) / 2,
self.center_y - (self.height * self.ripple_scale) / 2)
class MDSwitch(ThemableBehavior, ButtonBehavior, FloatLayout):
active = BooleanProperty(False)
if touch.grab_current is not self:
return super(ButtonBehavior, self).on_touch_up(touch)
self.elevation_release_anim.stop(self)
self.elevation_release_anim.start(self)
return super(MDFloatingActionButton, self).on_touch_up(touch)
def on_elevation_normal(self, instance, value):
self.elevation = value
def on_elevation_raised(self, instance, value):
if self.elevation_raised == 0 and self.elevation_normal + 6 <= 12:
self.elevation_raised = self.elevation_normal + 6
elif self.elevation_raised == 0:
self.elevation_raised = 12
class MDFloatingTempActionButton(ThemableBehavior, CircularRippleBehavior,
RoundElevationBehavior, ButtonBehavior,
AnchorLayout):
_bg_color_down = ListProperty([])
background_color = ListProperty()
background_color_down = ListProperty()
background_color_disabled = ListProperty()
theme_text_color = OptionProperty(None, allownone=True,
options=['Primary', 'Secondary', 'Hint',
'Error', 'Custom'])
text_color = ListProperty(None, allownone=True)
def _get_bg_color_down(self):
return self._bg_color_down
def _set_bg_color_down(self, color, alpha=None):
if len(color) == 2:
angle_end: 180
on_release: thumb.trigger_action()
Thumb:
id: thumb
size_hint: None, None
size: dp(24), dp(24)
pos: root._thumb_pos
color: root.thumb_color_disabled if root.disabled else \
(root.thumb_color_down if root.active else root.thumb_color)
elevation: 4 if root.active else 2
on_release: setattr(root, 'active', not root.active)
''')
class MDCheckbox(ThemableBehavior, CircularRippleBehavior,
ToggleButtonBehavior, Label):
active = BooleanProperty(False)
_checkbox_icon = StringProperty(
u"{}".format(md_icons['checkbox-blank-outline']))
_radio_icon = StringProperty(u"{}".format(
md_icons['checkbox-blank-circle-outline']))
_icon_active = StringProperty(u"{}".format(md_icons['checkbox-marked']))
def __init__(self, **kwargs):
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')
super(MDCheckbox, self).__init__(**kwargs)
self.register_event_type('on_active')
self.check_anim_out.bind(
def _set_ellipse(self, instance, value):
super(CircularRippleBehavior, self)._set_ellipse(instance, value)
if self.ellipse.size[0] > self.width * .6 and not self.fading_out:
self.fade_out()
self.ellipse.pos = (self.center_x - self.ripple_rad / 2.,
self.center_y - self.ripple_rad / 2.)
opposite_colors: root.opposite_colors
disabled: root.disabled
halign: 'center'
valign: 'middle'
''')
class MDIconButton(CircularRippleBehavior, ButtonBehavior, BoxLayout):
icon = StringProperty('circle')
theme_text_color = OptionProperty(None, allownone=True,
options=['Primary', 'Secondary', 'Hint',
'Error', 'Custom'])
text_color = ListProperty(None, allownone=True)
opposite_colors = BooleanProperty(False)
class JZInvisiButton(CircularRippleBehavior, ButtonBehavior, BoxLayout):
icon = StringProperty('circle')
theme_text_color = OptionProperty(None, allownone=True,
options=['Primary', 'Secondary', 'Hint',
'Error', 'Custom'])
text_color = ListProperty(None, allownone=True)
opposite_colors = BooleanProperty(False)
class MDFlatButton(ThemableBehavior, RectangularRippleBehavior,
ButtonBehavior, BackgroundColorBehavior, AnchorLayout):
width = BoundedNumericProperty(dp(64), min=dp(64), max=None,
errorhandler=lambda x: dp(64))
text_color = ListProperty()
text = StringProperty('')
angle_end: 180
on_release: thumb.trigger_action()
Thumb:
id: thumb
size_hint: None, None
size: dp(24), dp(24)
pos: root._thumb_pos
color: root.thumb_color_disabled if root.disabled else \
(root.thumb_color_down if root.active else root.thumb_color)
elevation: 4 if root.active else 2
on_release: setattr(root, 'active', not root.active)
''')
class MDCheckbox(ThemableBehavior, CircularRippleBehavior,
ToggleButtonBehavior, Label):
active = BooleanProperty(False)
_checkbox_icon = StringProperty(
"{}".format(md_icons['checkbox-blank-outline']))
_radio_icon = StringProperty("{}".format(
md_icons['checkbox-blank-circle-outline']))
_icon_active = StringProperty("{}".format(md_icons['checkbox-marked']))
def __init__(self, **kwargs):
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')
super(MDCheckbox, self).__init__(**kwargs)
self.register_event_type('on_active')
self.check_anim_out.bind(
md_icons['checkbox-marked-outline'])
self.active = True
else:
self.check_anim_in.cancel(self)
self.check_anim_out.start(self)
self._radio_icon = u"{}".format(
md_icons['checkbox-blank-circle-outline'])
self._checkbox_icon = u"{}".format(
md_icons['checkbox-blank-outline'])
self.active = False
def on_active(self, instance, value):
self.state = 'down' if value else 'normal'
class Thumb(CircularElevationBehavior, CircularRippleBehavior, ButtonBehavior,
Widget):
ripple_scale = NumericProperty(2)
def _set_ellipse(self, instance, value):
self.ellipse.size = (self.ripple_rad, self.ripple_rad)
if self.ellipse.size[0] > self.width * 1.5 and not self.fading_out:
self.fade_out()
self.ellipse.pos = (self.center_x - self.ripple_rad / 2.,
self.center_y - self.ripple_rad / 2.)
self.stencil.pos = (
self.center_x - (self.width * self.ripple_scale) / 2,
self.center_y - (self.height * self.ripple_scale) / 2)
class MDSwitch(ThemableBehavior, ButtonBehavior, FloatLayout):
active = BooleanProperty(False)