Mercurial > libervia-desktop-kivy
changeset 168:397f2fb67aab
core (menu): animate transfer menu opening/closing + close it on [ESC]/back
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 28 Apr 2018 16:22:50 +0200 |
parents | ffef21fd97a2 |
children | 6a288d4a493f |
files | cagou/core/menu.py cagou/kv/menu.kv |
diffstat | 2 files changed, 17 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/cagou/core/menu.py Sat Apr 28 15:40:29 2018 +0200 +++ b/cagou/core/menu.py Sat Apr 28 16:22:50 2018 +0200 @@ -28,6 +28,8 @@ from kivy import properties from kivy.garden import contextmenu from sat_frontends.quick_frontend import quick_menus +from kivy.core.window import Window +from kivy.animation import Animation from cagou import G import webbrowser @@ -199,19 +201,32 @@ self.items_layout.add_widget(item) def show(self, caller_wid=None): - self.visible = True + self.size_hint_y = 0 + Window.bind(on_keyboard=self.key_input) G.host.app.root.add_widget(self) + Animation(size_hint_y=0.5, d=2, t='out_elastic').start(self) + + def hide(self): + Window.unbind(on_keyboard=self.key_input) + anim = Animation(size_hint_y=0, d=0.3) + anim.bind(on_complete=lambda anim, menu: self.parent.remove_widget(self)) + anim.start(self) def on_touch_down(self, touch): # we remove the menu if we click outside # else we want to handle the event, but not # transmit it to parents if not self.collide_point(*touch.pos): - self.parent.remove_widget(self) + self.hide() else: return super(TransferMenu, self).on_touch_down(touch) return True + def key_input(self, window, key, scancode, codepoint, modifier): + if key == 27: + self.hide() + return True + def _closeUI(self, wid): G.host.closeUI()