Esempio n. 1
0
class BasePressedButton(BaseButton):
    '''
    Abstract base class for those button which fade to a background color on
    press.
    '''
    def on_touch_down(self, touch):
        if touch.is_mouse_scrolling:
            return False
        elif not self.collide_point(touch.x, touch.y):
            return False
        elif self in touch.ud:
            return False
        elif self.disabled:
            return False
        else:
            self.fade_bg = \
                Animation(duration=.5,
                          _current_button_color=self.md_bg_color_down)
            self.fade_bg.start(self)
            return super(BaseButton, self).on_touch_down(touch)

    def on_touch_up(self, touch):
        if touch.grab_current is self:
            self.fade_bg.stop_property(self, '_current_button_color')
            Animation(duration=.05,
                      _current_button_color=self.md_bg_color).start(self)
        return super(BaseButton, self).on_touch_up(touch)
Esempio n. 2
0
class BasePressedButton(BaseButton):
    """
    Abstract base class for those button which fade to a background color on
    press.
    """

    _fade_bg = None

    def on_touch_down(self, touch):
        if touch.is_mouse_scrolling:
            return False
        elif not self.collide_point(touch.x, touch.y):
            return False
        elif self in touch.ud:
            return False
        elif self.disabled:
            return False
        else:
            # Button dimming animation.
            if self.md_bg_color == [0.0, 0.0, 0.0, 0.0]:
                self._fade_bg = Animation(
                    duration=0.5, _current_button_color=self._md_bg_color_down
                )
                self._fade_bg.start(self)
            return super().on_touch_down(touch)

    def on_touch_up(self, touch):
        if touch.grab_current is self and self._fade_bg:
            self._fade_bg.stop_property(self, "_current_button_color")
            Animation(
                duration=0.05, _current_button_color=self.md_bg_color
            ).start(self)
        return super().on_touch_up(touch)
Esempio n. 3
0
class BasePressedButton(BaseButton):
    '''
    Abstract base class for those button which fade to a background color on
    press.
    '''
    def on_touch_down(self, touch):
        if touch.is_mouse_scrolling:
            return False
        elif not self.collide_point(touch.x, touch.y):
            return False
        elif self in touch.ud:
            return False
        elif self.disabled:
            return False
        else:
            self.fade_bg = Animation(duration=.5,
                    _current_button_color=self.md_bg_color_down)
            self.fade_bg.start(self)
            return super(BaseButton, self).on_touch_down(touch)

    def on_touch_up(self, touch):
        if touch.grab_current is self:
            self.fade_bg.stop_property(self, '_current_button_color')
            Animation(duration=.05,
                      _current_button_color=self.md_bg_color).start(self)
        return super(BaseButton, self).on_touch_up(touch)
Esempio n. 4
0
class PopScrollBut(Button):
    fade_bg = ObjectProperty(None)
    bg_color_down = ListProperty([0.0, 0.0, 0.0, 0.0])
    bg_color = ListProperty([0.0, 0.0, 0.0, 0.0])

    def on_touch_down(self, touch):
        self.bg_color_down = App.get_running_app().theme_cls.bg_light
        self.bg_color = self.background_color
        if touch.is_mouse_scrolling:
            return False
        elif not self.collide_point(touch.x, touch.y):
            return False
        elif self in touch.ud:
            return False
        elif self.disabled:
            return False
        else:
            self.fade_bg = Animation(duration=0.5,
                                     background_color=self.bg_color_down)
            self.fade_bg.start(self)
            return super().on_touch_down(touch)

    def on_touch_up(self, touch):
        if touch.grab_current is self:
            self.fade_bg.stop_property(self, "background_color")
            Animation(duration=0.05,
                      background_color=self.bg_color).start(self)
        return super().on_touch_up(touch)
Esempio n. 5
0
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('')
    theme_text_color = OptionProperty(
        None,
        allownone=True,
        options=['Primary', 'Secondary', 'Hint', 'Error', 'Custom'])
    text_color = ListProperty(None, allownone=True)

    _text = StringProperty('')
    _bg_color_down = ListProperty([0, 0, 0, 0])
    _current_button_color = ListProperty([0, 0, 0, 0])

    def __init__(self, **kwargs):
        super(MDFlatButton, self).__init__(**kwargs)
        self._current_button_color = self.background_color
        self._bg_color_down = get_color_from_hex(
            colors[self.theme_cls.theme_style]['FlatButtonDown'])

        Clock.schedule_once(lambda x: self.ids._label.bind(
            texture_size=self.update_width_on_label_texture))

    def update_width_on_label_texture(self, instance, value):
        self.ids._label.width = value[0]

    def on_text(self, instance, value):
        self._text = value.upper()

    def on_touch_down(self, touch):
        if touch.is_mouse_scrolling:
            return False
        elif not self.collide_point(touch.x, touch.y):
            return False
        elif self in touch.ud:
            return False
        elif self.disabled:
            return False
        else:
            self.fade_bg = Animation(
                duration=.2,
                _current_button_color=get_color_from_hex(
                    colors[self.theme_cls.theme_style]['FlatButtonDown']))
            self.fade_bg.start(self)
            return super(MDFlatButton, self).on_touch_down(touch)

    def on_touch_up(self, touch):
        if touch.grab_current is self:
            self.fade_bg.stop_property(self, '_current_button_color')
            Animation(duration=.05,
                      _current_button_color=self.background_color).start(self)
        return super(MDFlatButton, self).on_touch_up(touch)
Esempio n. 6
0
class TestLayout(FloatLayout):

    # create and start two animations
    def start_animations(self):
        self.anim1 = Animation(font_size=200, d=5)
        self.anim2 = Animation(color=[0, 1, 0, 1],
                               outline_width=20,
                               outline_color=[1, 0, 0, 1],
                               d=5)
        self.anim1.start(self.label)
        self.anim2.start(self.label)

    # stop both animations
    def stop_all_animations(self):
        Animation.stop_all(self.label)

    # stop animating just the two color properties from the second animation
    def stop_color_animations(self):
        Animation.stop_all(self.label, 'color', 'outline_color')

    # stop animating the outline_width property from the second animation
    def stop_outline_animation(self):
        self.anim2.stop_property(self.label, 'outline_width')