# HG changeset patch # User Goffi # Date 1524925370 -7200 # Node ID 397f2fb67aab69a9c09bb7c8b15a0b22fc058b08 # Parent ffef21fd97a2f5f0dff893059bacc01bc429e003 core (menu): animate transfer menu opening/closing + close it on [ESC]/back diff -r ffef21fd97a2 -r 397f2fb67aab cagou/core/menu.py --- 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() diff -r ffef21fd97a2 -r 397f2fb67aab cagou/kv/menu.kv --- a/cagou/kv/menu.kv Sat Apr 28 15:40:29 2018 +0200 +++ b/cagou/kv/menu.kv Sat Apr 28 16:22:50 2018 +0200 @@ -39,7 +39,6 @@ : items_layout: items_layout orientation: "vertical" - pos_hint: {"top": 0.5} size_hint: 1, 0.5 canvas.before: Color: