Mercurial > libervia-desktop-kivy
comparison cagou/core/menu.py @ 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 | cd99f70ea592 |
children | 5cf17930bb09 |
comparison
equal
deleted
inserted
replaced
167:ffef21fd97a2 | 168:397f2fb67aab |
---|---|
26 from kivy.uix.label import Label | 26 from kivy.uix.label import Label |
27 from kivy.uix.popup import Popup | 27 from kivy.uix.popup import Popup |
28 from kivy import properties | 28 from kivy import properties |
29 from kivy.garden import contextmenu | 29 from kivy.garden import contextmenu |
30 from sat_frontends.quick_frontend import quick_menus | 30 from sat_frontends.quick_frontend import quick_menus |
31 from kivy.core.window import Window | |
32 from kivy.animation import Animation | |
31 from cagou import G | 33 from cagou import G |
32 import webbrowser | 34 import webbrowser |
33 | 35 |
34 ABOUT_TITLE = _(u"About {}".format(C.APP_NAME)) | 36 ABOUT_TITLE = _(u"About {}".format(C.APP_NAME)) |
35 ABOUT_CONTENT = _(u"""Cagou (Salut à Toi) v{} | 37 ABOUT_CONTENT = _(u"""Cagou (Salut à Toi) v{} |
197 plug_info = plug_info | 199 plug_info = plug_info |
198 ) | 200 ) |
199 self.items_layout.add_widget(item) | 201 self.items_layout.add_widget(item) |
200 | 202 |
201 def show(self, caller_wid=None): | 203 def show(self, caller_wid=None): |
202 self.visible = True | 204 self.size_hint_y = 0 |
205 Window.bind(on_keyboard=self.key_input) | |
203 G.host.app.root.add_widget(self) | 206 G.host.app.root.add_widget(self) |
207 Animation(size_hint_y=0.5, d=2, t='out_elastic').start(self) | |
208 | |
209 def hide(self): | |
210 Window.unbind(on_keyboard=self.key_input) | |
211 anim = Animation(size_hint_y=0, d=0.3) | |
212 anim.bind(on_complete=lambda anim, menu: self.parent.remove_widget(self)) | |
213 anim.start(self) | |
204 | 214 |
205 def on_touch_down(self, touch): | 215 def on_touch_down(self, touch): |
206 # we remove the menu if we click outside | 216 # we remove the menu if we click outside |
207 # else we want to handle the event, but not | 217 # else we want to handle the event, but not |
208 # transmit it to parents | 218 # transmit it to parents |
209 if not self.collide_point(*touch.pos): | 219 if not self.collide_point(*touch.pos): |
210 self.parent.remove_widget(self) | 220 self.hide() |
211 else: | 221 else: |
212 return super(TransferMenu, self).on_touch_down(touch) | 222 return super(TransferMenu, self).on_touch_down(touch) |
213 return True | 223 return True |
224 | |
225 def key_input(self, window, key, scancode, codepoint, modifier): | |
226 if key == 27: | |
227 self.hide() | |
228 return True | |
214 | 229 |
215 def _closeUI(self, wid): | 230 def _closeUI(self, wid): |
216 G.host.closeUI() | 231 G.host.closeUI() |
217 | 232 |
218 def onTransferCancelled(self, wid, cleaning_cb=None): | 233 def onTransferCancelled(self, wid, cleaning_cb=None): |