Advertisement
jevixlugya

animation scroll

Dec 1st, 2022
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.74 KB | None | 0 0
  1. from kivy.app import App
  2. from kivy.lang import Builder
  3. from kivy.uix.scrollview import ScrollView
  4. from kivy.uix.button import Button
  5. from kivy.animation import Animation
  6.  
  7. kv = """
  8. <ScrollButton>:
  9.    size_hint_y: None
  10.    height: dp(48)
  11.    on_release: print(f'{self.text} pressed')
  12.  
  13. BoxLayout:
  14.    orientation: 'vertical'
  15.    spacing: dp(10)
  16.    Label:
  17.        text: 'Example of ScrollView Animation'
  18.        size_hint_y: None
  19.        height: 30
  20.    AnimScrollView:
  21.        id: sv
  22.        effect_cls: 'ScrollEffect' # Use 'ScrollEffect', 'DampedScrollEffect' or 'OpacityScrollEffect'
  23.        BoxLayout:
  24.            orientation: 'vertical'
  25.            id: box
  26.            size_hint_y: None
  27.            height: self.minimum_height
  28.    ToggleButton:
  29.        size_hint_y: None
  30.        height: dp(48)
  31.        on_state:
  32.            sv.animate_scroll(self.state)
  33.            self.text = {'normal': 'Start', 'down': 'Stop'}[self.state]
  34.        text: 'Start'
  35. """
  36.  
  37.  
  38. class ScrollButton(Button):
  39.     pass
  40.  
  41. class AnimScrollView(ScrollView):
  42.     def __init__(self, **kwargs):
  43.         super().__init__(**kwargs)
  44.         self.anim = Animation(scroll_y=0, duration=15) + Animation(scroll_y=1, duration=5)
  45.         self.anim.repeat = True
  46.  
  47.     def animate_scroll(self, toggle_state):
  48.         if toggle_state == 'down':
  49.             self.anim.start(self)
  50.         else:
  51.             self.anim.stop(self)
  52.  
  53.  
  54. class ScrollViewExampleApp(App):
  55.     def build(self):
  56.         return Builder.load_string(kv)
  57.  
  58.     def on_start(self):
  59.         # create buttons in the boxlayout that is in the scrollview
  60.         for i in range(20):
  61.             self.root.ids.box.add_widget(ScrollButton(text=f'Button {i}'))
  62.  
  63.  
  64.  
  65.  
  66. ScrollViewExampleApp().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement