I have a ScrollView
that's supposed to have an update feature when you overscroll to the top (like in many apps). I've found a way to trigger it when the overscroll exceeds a certain threshold, but it triggers it a lot of times, as the on_overscroll
event is triggered on every movement. So is there a way to limit it?
My code looks like this:
from kivy.app import App
from kivy.uix.scrollview import ScrollView
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Buttonfrom kivy.effects.dampedscroll import DampedScrollEffectclass Effect(DampedScrollEffect):def on_overscroll(self, *args):super().on_overscroll(*args)if self.overscroll < -50:print('hey')class TestApp(App):def build(self):sv = ScrollView(effect_cls = Effect,size_hint_y = 0.2)gl = GridLayout(cols = 1,size_hint_y = None)gl.bind(minimum_height = gl.setter('height'))for i in range(5):gl.add_widget(Button(text = str(i),size_hint = (None, None)))sv.add_widget(gl)return svTestApp().run()
So, as you can see, when the overscroll goes beyond 50, it prints a simple message. But when you actually try it, you'll see that it prints it many times. What I want for it is to trigger an event, stay untriggerable for some time (like a second) and update the content. I've tried messing with boolean flags and Clock
, but it didn't work. What could be done here?