Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. from kivy.uix.dropdown import DropDown
  2. from kivy.app import App
  3. from kivy.lang import Builder
  4. from kivy.properties import NumericProperty
  5. from kivy.animation import Animation
  6.  
  7. KV = '''
  8. FloatLayout:
  9. Spinner:
  10. dropdown_cls: 'SlowDown'
  11. text: 'sing along'
  12. values: 'hello darkness my old friend'.split(' ')
  13. size_hint: None, None
  14. size: 100, 38
  15. pos_hint: {'center': (.5, .5)}
  16. '''
  17.  
  18. class SlowDown(DropDown):
  19. item_delay = NumericProperty(.1)
  20. display_time = NumericProperty(.5)
  21.  
  22. def open(self, widget):
  23. super(SlowDown, self).open(widget)
  24.  
  25. # determine if we openned up or down
  26. if self.attach_to.y > self.y:
  27. children = reversed(self.container.children)
  28. else:
  29. children = self.container.children
  30.  
  31. #
  32. for i, w in enumerate(children):
  33. anim = (
  34. Animation(duration=i * self.item_delay)
  35. + Animation(opacity=1, duration=self.display_time)
  36. )
  37. w.opacity = 0
  38. anim.start(w)
  39.  
  40. bar_color = self.bar_color
  41.  
  42. def restore_bar_color(*args):
  43. Animation(bar_color=bar_color, d=self.display_time).start(self)
  44.  
  45. self.bar_color = (0, 0, 0, 0)
  46.  
  47. anim.bind(on_complete=restore_bar_color)
  48.  
  49.  
  50. class SlowDownApp(App):
  51. def build(self):
  52. return Builder.load_string(KV)
  53.  
  54.  
  55. if __name__ == '__main__':
  56. SlowDownApp().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement