comparison cagou/plugins/plugin_wid_file_sharing.py @ 196:519b3a29743c

utils, plugin file sharing: new utils module, with a FilterBehavior: FilterBehavior do a smooth animation for filtering out children of a layout according to a text content.
author Goffi <goffi@goffi.org>
date Wed, 23 May 2018 21:25:08 +0200
parents a68c9baa6694
children 60b63c3e63a1
comparison
equal deleted inserted replaced
195:cf30cb1d1c12 196:519b3a29743c
25 from sat.tools.common import files_utils 25 from sat.tools.common import files_utils
26 from sat_frontends.quick_frontend import quick_widgets 26 from sat_frontends.quick_frontend import quick_widgets
27 from sat_frontends.tools import jid 27 from sat_frontends.tools import jid
28 from cagou.core.constants import Const as C 28 from cagou.core.constants import Const as C
29 from cagou.core import cagou_widget 29 from cagou.core import cagou_widget
30 from cagou.core.utils import FilterBehavior
30 from cagou import G 31 from cagou import G
31 from kivy import properties 32 from kivy import properties
32 from kivy.uix.label import Label 33 from kivy.uix.label import Label
33 from kivy.uix.button import Button 34 from kivy.uix.button import Button
34 from kivy.uix.boxlayout import BoxLayout 35 from kivy.uix.boxlayout import BoxLayout
35 from kivy.garden import modernmenu 36 from kivy.garden import modernmenu
36 from kivy.clock import Clock 37 from kivy.clock import Clock
37 from kivy.metrics import dp 38 from kivy.metrics import dp
38 from kivy.animation import Animation
39 from functools import partial 39 from functools import partial
40 import os.path 40 import os.path
41 import json 41 import json
42 42
43 43
205 205
206 class Menu(modernmenu.ModernMenu): 206 class Menu(modernmenu.ModernMenu):
207 pass 207 pass
208 208
209 209
210 class FileSharing(quick_widgets.QuickWidget, cagou_widget.CagouWidget): 210 class FileSharing(quick_widgets.QuickWidget, cagou_widget.CagouWidget, FilterBehavior):
211 SINGLE=False 211 SINGLE=False
212 float_layout = properties.ObjectProperty() 212 float_layout = properties.ObjectProperty()
213 layout = properties.ObjectProperty() 213 layout = properties.ObjectProperty()
214 mode = properties.OptionProperty(MODE_LOCAL, options=[MODE_VIEW, MODE_LOCAL]) 214 mode = properties.OptionProperty(MODE_LOCAL, options=[MODE_VIEW, MODE_LOCAL])
215 local_dir = properties.StringProperty(os.path.expanduser(u'~')) 215 local_dir = properties.StringProperty(os.path.expanduser(u'~'))
217 remote_entity = properties.StringProperty(u'') 217 remote_entity = properties.StringProperty(u'')
218 shared_paths = properties.ListProperty() 218 shared_paths = properties.ListProperty()
219 signals_registered = False 219 signals_registered = False
220 220
221 def __init__(self, host, target, profiles): 221 def __init__(self, host, target, profiles):
222 self._filter_last = u''
223 self._filter_anim = Animation(width = 0,
224 height = 0,
225 opacity = 0,
226 d = 0.5)
227 quick_widgets.QuickWidget.__init__(self, host, target, profiles) 222 quick_widgets.QuickWidget.__init__(self, host, target, profiles)
228 cagou_widget.CagouWidget.__init__(self) 223 cagou_widget.CagouWidget.__init__(self)
224 FilterBehavior.__init__(self)
229 self.mode_btn = ModeBtn(self) 225 self.mode_btn = ModeBtn(self)
230 self.mode_btn.bind(on_release=self.change_mode) 226 self.mode_btn.bind(on_release=self.change_mode)
231 self.headerInputAddExtra(self.mode_btn) 227 self.headerInputAddExtra(self.mode_btn)
232 self.bind(local_dir=self.update_view, 228 self.bind(local_dir=self.update_view,
233 remote_dir=self.update_view, 229 remote_dir=self.update_view,
272 268
273 def onHeaderInput(self): 269 def onHeaderInput(self):
274 if u'/' in self.header_input.text or self.header_input.text == u'~': 270 if u'/' in self.header_input.text or self.header_input.text == u'~':
275 self.current_dir = os.path.expanduser(self.header_input.text) 271 self.current_dir = os.path.expanduser(self.header_input.text)
276 272
277 def onHeaderInputComplete(self, wid, text): 273 def onHeaderInputComplete(self, wid, text, **kwargs):
278 """we filter items when text is entered in input box""" 274 """we filter items when text is entered in input box"""
279 text = text.strip().lower()
280 if u'/' in text: 275 if u'/' in text:
281 return 276 return
282 filtering = len(text)>len(self._filter_last) 277 self.do_filter(self.layout.children,
283 self._filter_last = text 278 text,
284 for child in self.layout.children: 279 lambda c: c.name,
285 if not isinstance(child, ItemWidget): 280 width_cb=lambda c: c.base_width,
286 continue 281 height_cb=lambda c: c.minimum_height,
287 if child.name == u'..': 282 continue_tests=[lambda c: not isinstance(c, ItemWidget),
288 continue 283 lambda c: c.name == u'..'])
289 if text in child.name.lower(): 284
290 self._filter_anim.cancel(child)
291 child.width = child.base_width
292 child.height = child.minimum_height
293 child.opacity = 1
294 elif (filtering
295 and child.opacity > 0
296 and not self._filter_anim.have_properties_to_animate(child)):
297 self._filter_anim.start(child)
298 285
299 ## remote sharing callback ## 286 ## remote sharing callback ##
300 287
301 def _discoFindByFeaturesCb(self, data): 288 def _discoFindByFeaturesCb(self, data):
302 entities_services, entities_own, entities_roster = data 289 entities_services, entities_own, entities_roster = data