Last active
May 24, 2021 10:52
-
-
Save tshirtman/b3d76886ef190e8b544442f7ad318ced to your computer and use it in GitHub Desktop.
A Spinner/DropDown that opens progressively by animationg opacity of the items.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kivy.uix.dropdown import DropDown | |
from kivy.app import App | |
from kivy.lang import Builder | |
from kivy.properties import NumericProperty | |
from kivy.animation import Animation | |
KV = ''' | |
FloatLayout: | |
Spinner: | |
dropdown_cls: 'SlowDown' | |
text: 'sing along' | |
values: 'hello darkness my old friend'.split(' ') | |
size_hint: None, None | |
size: 100, 38 | |
pos_hint: {'center': (.5, .5)} | |
''' | |
class SlowDown(DropDown): | |
item_delay = NumericProperty(.1) | |
display_time = NumericProperty(.5) | |
def open(self, widget): | |
super(SlowDown, self).open(widget) | |
# determine if we openned up or down | |
if self.attach_to.y > self.y: | |
children = reversed(self.container.children) | |
else: | |
children = self.container.children | |
# | |
for i, w in enumerate(children): | |
anim = ( | |
Animation(duration=i * self.item_delay) | |
+ Animation(opacity=1, duration=self.display_time) | |
) | |
w.opacity = 0 | |
anim.start(w) | |
bar_color = self.bar_color | |
def restore_bar_color(*args): | |
Animation(bar_color=bar_color, d=self.display_time).start(self) | |
self.bar_color = (0, 0, 0, 0) | |
anim.bind(on_complete=restore_bar_color) | |
class SlowDownApp(App): | |
def build(self): | |
return Builder.load_string(KV) | |
if __name__ == '__main__': | |
SlowDownApp().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment