Mercurial > libervia-desktop-kivy
diff 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 |
line wrap: on
line diff
--- a/cagou/plugins/plugin_wid_file_sharing.py Wed May 23 21:22:29 2018 +0200 +++ b/cagou/plugins/plugin_wid_file_sharing.py Wed May 23 21:25:08 2018 +0200 @@ -27,6 +27,7 @@ from sat_frontends.tools import jid from cagou.core.constants import Const as C from cagou.core import cagou_widget +from cagou.core.utils import FilterBehavior from cagou import G from kivy import properties from kivy.uix.label import Label @@ -35,7 +36,6 @@ from kivy.garden import modernmenu from kivy.clock import Clock from kivy.metrics import dp -from kivy.animation import Animation from functools import partial import os.path import json @@ -207,7 +207,7 @@ pass -class FileSharing(quick_widgets.QuickWidget, cagou_widget.CagouWidget): +class FileSharing(quick_widgets.QuickWidget, cagou_widget.CagouWidget, FilterBehavior): SINGLE=False float_layout = properties.ObjectProperty() layout = properties.ObjectProperty() @@ -219,13 +219,9 @@ signals_registered = False def __init__(self, host, target, profiles): - self._filter_last = u'' - self._filter_anim = Animation(width = 0, - height = 0, - opacity = 0, - d = 0.5) quick_widgets.QuickWidget.__init__(self, host, target, profiles) cagou_widget.CagouWidget.__init__(self) + FilterBehavior.__init__(self) self.mode_btn = ModeBtn(self) self.mode_btn.bind(on_release=self.change_mode) self.headerInputAddExtra(self.mode_btn) @@ -274,27 +270,18 @@ if u'/' in self.header_input.text or self.header_input.text == u'~': self.current_dir = os.path.expanduser(self.header_input.text) - def onHeaderInputComplete(self, wid, text): + def onHeaderInputComplete(self, wid, text, **kwargs): """we filter items when text is entered in input box""" - text = text.strip().lower() if u'/' in text: return - filtering = len(text)>len(self._filter_last) - self._filter_last = text - for child in self.layout.children: - if not isinstance(child, ItemWidget): - continue - if child.name == u'..': - continue - if text in child.name.lower(): - self._filter_anim.cancel(child) - child.width = child.base_width - child.height = child.minimum_height - child.opacity = 1 - elif (filtering - and child.opacity > 0 - and not self._filter_anim.have_properties_to_animate(child)): - self._filter_anim.start(child) + self.do_filter(self.layout.children, + text, + lambda c: c.name, + width_cb=lambda c: c.base_width, + height_cb=lambda c: c.minimum_height, + continue_tests=[lambda c: not isinstance(c, ItemWidget), + lambda c: c.name == u'..']) + ## remote sharing callback ##