Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from kivy.app import App
- from kivy.lang import Builder
- from kivy.uix.boxlayout import BoxLayout
- from kivy.uix.label import Label
- from kivy.animation import Animation
- from kivy.core.window import Window
- from kivy.metrics import dp
- from kivy.clock import mainthread
- from kivy.properties import BooleanProperty
- Window.size = 400, 600
- kv = r'''
- PullDown:
- orientation:"vertical"
- Button:
- id:btn
- size_hint:1,None
- height:0
- opacity:0
- ScrollView:
- id:sv
- BoxLayout:
- id:bl
- orientation:"vertical"
- size_hint:1,None
- height: dp(600) if dp(500) < self.minimum_height < dp(560) else self.minimum_height
- '''
- class PullDown(BoxLayout):
- sv_open = BooleanProperty(False) # used to create an event
- animation_ongoing = False
- def on_kv_post(self, base_widget):
- for i in range(5): # <<<<<<<--------------- buggy for 5 or 6, all others work
- l = Label(size_hint=(1, None), height=dp(110), text="test")
- self.ids.bl.add_widget(l)
- # return super().on_kv_post(base_widget) #this is an event, not overloading
- def on_touch_down(self, touch):
- if self.collide_point(*touch.pos):
- touch.grab(self)
- if self.sv_open:
- self.collapse(touch)
- return super().on_touch_down(touch)
- def on_touch_move(self, touch):
- if (touch.grab_current is self) and (not self.animation_ongoing):
- if touch.dy < 0 and self.ids.sv.effect_y.overscroll < -dp(150):
- self.expand(touch)
- return False
- return super().on_touch_move(touch)
- def on_touch_up(self, touch):
- if touch.grab_current is self:
- touch.ungrab(self)
- return super().on_touch_up(touch)
- def on_sv_open(self, instance, button_open):
- print(f'{self.sv_open=}')
- # if button_open:
- # scroll_anim = Animation(scroll_y=1, d=.9) # this is a hack, might be platform dependent
- # scroll_anim.start(self.ids.sv)
- @mainthread
- def expand(self, touch):
- self.animation_ongoing = True
- super().on_touch_up(touch)
- anim = Animation(
- height=dp(100),
- opacity=1,
- d=0.3, t="out_cubic"
- )
- def on_animation_complete(*args):
- self.animation_ongoing = False
- self.sv_open = True
- anim.bind(on_complete=on_animation_complete)
- anim.start(self.ids.btn)
- @mainthread
- def collapse(self, touch):
- self.animation_ongoing = True
- super().on_touch_up(touch)
- anim = Animation(
- height=0,
- opacity=0,
- d=0.3, t="out_cubic"
- )
- def on_animation_complete(*args):
- self.animation_ongoing = False
- self.sv_open = False
- self.ids.sv.scroll_y = 1
- anim.bind(on_complete=on_animation_complete)
- anim.start(self.ids.btn)
- class Test(App):
- def build(self):
- return Builder.load_string(kv)
- Test().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement