From 90d7e1b992ea9e4d07abe9f11917141a5980711b Mon Sep 17 00:00:00 2001 From: Yuri Ivanov Date: Mon, 24 Oct 2022 21:55:49 +0300 Subject: [PATCH] Fixed `on_long_touch` method call The `on_long_touch` method was called at the `on_touch_down` event. --- kivymd/uix/behaviors/touch_behavior.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/kivymd/uix/behaviors/touch_behavior.py b/kivymd/uix/behaviors/touch_behavior.py index 49b54fcfb..8aca7bf22 100644 --- a/kivymd/uix/behaviors/touch_behavior.py +++ b/kivymd/uix/behaviors/touch_behavior.py @@ -22,7 +22,7 @@ from kivymd.uix.button import MDRaisedButton KV = ''' - Screen: + MDScreen: MyButton: text: "PRESS ME" @@ -74,9 +74,10 @@ def __init__(self, **kwargs): def create_clock(self, widget, touch, *args): if self.collide_point(touch.x, touch.y): - callback = partial(self.on_long_touch, touch) - Clock.schedule_once(callback, self.duration_long_touch) - touch.ud["event"] = callback + if "event" not in touch.ud: + callback = partial(self.on_long_touch, touch) + Clock.schedule_once(callback, self.duration_long_touch) + touch.ud["event"] = callback if touch.is_double_tap: self.on_double_tap(touch, *args) @@ -85,10 +86,9 @@ def create_clock(self, widget, touch, *args): def delete_clock(self, widget, touch, *args): if self.collide_point(touch.x, touch.y): - try: + if "event" in touch.ud: Clock.unschedule(touch.ud["event"]) - except KeyError: - pass + del touch.ud["event"] def on_long_touch(self, touch, *args): """Called when the widget is pressed for a long time."""