comparison cagou/core/menu.py @ 216:e42e0c45d384

core (menu): allow to specify size in SideMenu: size menu now use 4 variable to open and close state: - size_hint_close - size_hint_open - size_open - size_close if one value of size_hint_open or size_hint_close tuples is None, the corresponding size is used instead.
author Goffi <goffi@goffi.org>
date Sun, 24 Jun 2018 22:08:16 +0200
parents c7d15ef4bfa8
children a676cb07c1cb
comparison
equal deleted inserted replaced
215:254481ba2bae 216:e42e0c45d384
177 transfer_menu.do_callback(self.plug_info) 177 transfer_menu.do_callback(self.plug_info)
178 return True 178 return True
179 179
180 180
181 class SideMenu(BoxLayout): 181 class SideMenu(BoxLayout):
182 base_size_hint_close = (0, 1) 182 size_hint_close = (0, 1)
183 base_size_hint_open = (0.4, 1) 183 size_hint_open = (0.4, 1)
184 size_close = (100, 100)
185 size_open = (0, 0)
184 bg_color = properties.ListProperty([0, 0, 0, 1]) 186 bg_color = properties.ListProperty([0, 0, 0, 1])
185 # callback will be called with arguments relevant to menu 187 # callback will be called with arguments relevant to menu
186 callback = properties.ObjectProperty() 188 callback = properties.ObjectProperty()
187 # call do_callback even when menu is cancelled 189 # call do_callback even when menu is cancelled
188 callback_on_close = properties.BooleanProperty(False) 190 callback_on_close = properties.BooleanProperty(False)
193 def __init__(self, **kwargs): 195 def __init__(self, **kwargs):
194 super(SideMenu, self).__init__(**kwargs) 196 super(SideMenu, self).__init__(**kwargs)
195 if self.cancel_cb is None: 197 if self.cancel_cb is None:
196 self.cancel_cb = self.onMenuCancelled 198 self.cancel_cb = self.onMenuCancelled
197 199
200 def _set_anim_kw(self, kw, size_hint, size):
201 """Set animation keywords
202
203 for each value of size_hint it is used if not None,
204 else size is used.
205 If one value of size is bigger than the respective one of Window
206 the one of Window is used
207 """
208 size_hint_x, size_hint_y = size_hint
209 width, height = size
210 if size_hint_x is not None:
211 kw['size_hint_x'] = size_hint_x
212 elif width is not None:
213 kw['width'] = min(width, Window.width)
214
215 if size_hint_y is not None:
216 kw['size_hint_y'] = size_hint_y
217 elif height is not None:
218 kw['height'] = min(height, Window.height)
219
198 def show(self, caller_wid=None): 220 def show(self, caller_wid=None):
199 Window.bind(on_keyboard=self.key_input) 221 Window.bind(on_keyboard=self.key_input)
200 G.host.app.root.add_widget(self) 222 G.host.app.root.add_widget(self)
201 Animation(size_hint=self.base_size_hint_open, d=0.3, t='out_back').start(self) 223 kw = {'d': 0.3, 't': 'out_back'}
224 self._set_anim_kw(kw, self.size_hint_open, self.size_open)
225 Animation(**kw).start(self)
202 226
203 def hide(self): 227 def hide(self):
204 Window.unbind(on_keyboard=self.key_input) 228 Window.unbind(on_keyboard=self.key_input)
205 anim = Animation(size_hint=self.base_size_hint_close, d=0.2) 229 kw = {'d': 0.2}
230 self._set_anim_kw(kw, self.size_hint_close, self.size_close)
231 anim = Animation(**kw)
206 anim.bind(on_complete=lambda anim, menu: self.parent.remove_widget(self)) 232 anim.bind(on_complete=lambda anim, menu: self.parent.remove_widget(self))
207 anim.start(self) 233 anim.start(self)
208 if self.callback_on_close: 234 if self.callback_on_close:
209 self.do_callback() 235 self.do_callback()
210 236
241 # profiles if set will be sent to transfer widget, may be used to get specific files 267 # profiles if set will be sent to transfer widget, may be used to get specific files
242 profiles = properties.ObjectProperty() 268 profiles = properties.ObjectProperty()
243 transfer_txt = _(u"Beware! The file will be sent to your server and stay unencrypted there\nServer admin(s) can see the file, and they choose how, when and if it will be deleted") 269 transfer_txt = _(u"Beware! The file will be sent to your server and stay unencrypted there\nServer admin(s) can see the file, and they choose how, when and if it will be deleted")
244 send_txt = _(u"The file will be sent unencrypted directly to your contact (without transiting by the server), except in some cases") 270 send_txt = _(u"The file will be sent unencrypted directly to your contact (without transiting by the server), except in some cases")
245 items_layout = properties.ObjectProperty() 271 items_layout = properties.ObjectProperty()
246 base_size_hint_close = (1, 0) 272 size_hint_close = (1, 0)
247 base_size_hint_open = (1, 0.5) 273 size_hint_open = (1, 0.5)
248 274
249 def __init__(self, **kwargs): 275 def __init__(self, **kwargs):
250 super(TransferMenu, self).__init__(**kwargs) 276 super(TransferMenu, self).__init__(**kwargs)
251 if self.profiles is None: 277 if self.profiles is None:
252 self.profiles = iter(G.host.profiles) 278 self.profiles = iter(G.host.profiles)
279 """allow to select entities from roster""" 305 """allow to select entities from roster"""
280 profiles = properties.ObjectProperty() 306 profiles = properties.ObjectProperty()
281 layout = properties.ObjectProperty() 307 layout = properties.ObjectProperty()
282 instructions = properties.StringProperty(_(u"Please select entities")) 308 instructions = properties.StringProperty(_(u"Please select entities"))
283 filter_input = properties.ObjectProperty() 309 filter_input = properties.ObjectProperty()
310 size_hint_close = (None, 1)
311 size_hint_open = (None, 1)
312 size_open = (dp(250), 100)
313 size_close = (0, 100)
284 314
285 def __init__(self, **kwargs): 315 def __init__(self, **kwargs):
286 super(EntitiesSelectorMenu, self).__init__(**kwargs) 316 super(EntitiesSelectorMenu, self).__init__(**kwargs)
287 self.filter_input.bind(text=self.do_filter_input) 317 self.filter_input.bind(text=self.do_filter_input)
288 if self.profiles is None: 318 if self.profiles is None: