Mercurial > libervia-desktop-kivy
annotate cagou/core/behaviors.py @ 466:cd448b877d1d
install: update requirements with alabaster==0.7.12
alembic==1.4.3
anki @ file:///build/anki/src/anki/dist/anki-2.1.35-py3-none-any.whl
ankirspy @ file:///build/anki/src/anki/dist/ankirspy-2.1.35-cp39-cp39-manylinux1_x86_64.whl
ansi2html==1.6.0
anytree==2.8.0
apipkg==1.5
apparmor==3.0.1
appdirs==1.4.4
appimage-builder==0.8.5
aqt @ file:///build/anki/src/anki/dist/aqt-2.1.35-py3-none-any.whl
argcomplete==1.12.1
argon2-cffi==20.1.0
asn1crypto==1.4.0
async-generator==1.10
attrs==20.3.0
autobahn==21.3.1
Automat==20.2.0
autopep8==1.5.5
Babel==2.9.0
backcall==0.2.0
bcrypt==3.2.0
Beaker==1.11.0
beautifulsoup4==4.9.3
black==20.8b1
bleach==3.3.0
blinker==1.4
bmap-tools==3.5
breezy==3.1.0
Brlapi==0.8.2
btrfsutil==5.11
CacheControl==0.12.6
cached-property==1.5.2
cagou==0.8.0.dev0+83c67b093350.153
cairocffi==1.2.0
CairoSVG==2.5.2
certifi==2020.6.20
cffi==1.14.5
chardet==3.0.4
click==7.1.2
colorama==0.4.4
commonmark==0.9.1
configobj==5.1.0.dev0
constantly==15.1.0
contextlib2==0.6.0.post1
coverage==5.5
cryptography==3.4.6
css-parser==1.0.6
cssselect2==0.4.1
cycler==0.10.0
Cython==0.29.22
decorator==4.4.2
defusedxml==0.6.0
diffoscope==169
distlib==0.3.1
distro==1.5.0
docker==4.4.4
docker-compose==1.28.5
docker-pycreds==0.4.0
dockerpty==0.4.1
docopt==0.6.2
docutils==0.16
dulwich==0.20.20
emrichen==0.2.3
entrypoints==0.3
extras==1.0.0
fastimport==0.9.8
file-magic==0.4.0
filelock==3.0.12
fixtures==3.0.0
flake8==3.8.4
Flask==1.1.2
Flask-BabelEx==0.9.4
Flask-Compress==1.8.0
Flask-Cors==3.0.9
Flask-Gravatar==0.5.0
Flask-Login==0.5.0
Flask-Mail==0.9.1
Flask-Migrate==2.7.0
Flask-Paranoid==0.2.0
Flask-Principal==0.4.0
Flask-Script==2.0.6
Flask-Security-Too==3.3.3
Flask-SQLAlchemy==2.4.4
Flask-WTF==0.14.3
future==0.18.2
gajim==1.2.2
gssapi==1.6.12
html2text==2020.1.16
html5lib==1.1
httpie==2.4.0
httplib2==0.19.0
hyperlink==21.0.0
idna==2.10
imagesize==1.2.0
img2pdf==0.4.0
importlib-metadata==3.4.0
incremental==17.5.0
inflect==5.3.0
iniconfig==1.1.1
ipdb==0.13.6
ipykernel==5.4.2
ipython==7.19.0
ipython-genutils==0.2.0
ipywidgets==7.6.2
isc==2.0
itsdangerous==1.1.0
jedi==0.17.2
jeepney==0.6.0
Jinja2==2.11.3
joblib==1.0.0
jsonpath-rw==1.4.0
jsonpickle==1.5.1
jsonschema==3.2.0
jupyter-client==6.1.7
jupyter-console==6.2.0
jupyter-core==4.6.3
jupyterlab-pygments==0.1.2
keyring==23.0.0
Kivy==2.0.0
kiwisolver==1.3.1
langdetect==1.0.8
ldap3==2.9.dev0
lensfun==0.3.95
LibAppArmor==3.0.1
libarchive-c==2.9
libfdt==1.6.0
libnacl==1.7.2
lockfile==0.12.2
louis==3.17.0
lxml==4.6.2
Mako==1.1.4
Markdown==3.3.3
MarkupSafe==1.1.1
matplotlib==3.3.4
mccabe==0.6.1
meld==3.20.3
mercurial==5.7.1
meson==0.57.1
miniupnpc==2.1
mistune==0.8.4
more-itertools==8.6.0
msgpack==1.0.2
mypy==0.812
mypy-extensions==0.4.3
natsort==7.1.1
nbclient==0.5.1
nbconvert==6.0.7
nbformat==5.0.8
nbxmpp==1.0.2
nest-asyncio==1.4.3
netifaces==0.10.9
netsnmp-python==1.0a1
networkx==2.5
nltk==3.5
nose==1.3.7
notebook==6.2.0
Nuitka==0.6.12.3
numpy==1.20.1
openshot-qt==2.5.1
ordered-set==4.0.2
orjson @ file:///build/python-orjson/src/python-orjson-3.5.1/target/wheels/orjson-3.5.1-cp39-cp39-manylinux2010_x86_64.whl
packaging==20.9
pandas==1.2.3
pandocfilters==1.4.3
paramiko==2.7.2
parso==0.7.1
passlib==1.7.4
path==15.1.2
pathspec==0.8.1
patiencediff==0.2.1
pbr==5.5.1
pdfarranger==1.7.0
pep517==0.9.1
pexpect==4.8.0
pickleshare==0.7.5
pikepdf==2.8.0.post2
Pillow==8.1.0
pluggy==0.13.1
ply==3.11
precis-i18n==1.0.3
progress==1.5
progressbar2==3.53.1
prometheus-client==0.9.0
prompt-toolkit==3.0.17
protobuf==3.12.4
psutil==5.8.0
psycopg2==2.8.6
ptyprocess==0.7.0
pudb==2020.1
pwquality==1.4.4
py==1.10.0
pyaml==20.4.0
pyasn1==0.4.8
pyasn1-modules==0.2.8
PyAudio==0.2.11
pybind11==2.6.2
pycairo==1.20.0
pycodestyle==2.6.0
pycountry==20.7.3
pycparser==2.20
pydocstyle==5.1.1
pyenchant==3.2.0
pyflakes==2.2.0
Pygments==2.8.1
PyGObject==3.38.0
PyHamcrest==1.9.0
pyinotify==0.9.6
pymediainfo==5.0.3
PyNaCl==1.4.0
PyOpenGL==3.1.5
pyOpenSSL==20.0.1
pyparsing==2.4.7
pyPEG2==2.15.2
PyQt5==5.15.4
PyQt5-sip==12.8.1
PyQtWebEngine==5.15.4
pyrsistent==0.17.3
PySocks==1.7.1
pytest==6.2.2
python-dateutil==2.8.1
python-dotenv==0.15.0
python-editor==1.0.4
python-Levenshtein==0.12.2
python-mimeparse==1.6.0
python-utils==2.5.6
python-xlib==0.29
pytoml==0.1.21
pytz==2021.1
pyxdg==0.26
PyYAML==5.3.1
pyzmq==20.0.0
questionary==1.9.0
qutebrowser==2.1.0
Reflector==2021.1.10.0.6.34
regex==2020.11.13
requests==2.25.1
requests-toolbelt==0.9.1
requirements-parser==0.2.0
resolvelib==0.5.4
retrying==1.3.3
s3cmd==2.1.0
schema==0.7.4
scikit-learn==0.24.1
scipy==1.6.1
scons==3.1.2
screenkey==1.4
SecretStorage==3.3.1
Send2Trash==1.5.0
service-identity==18.1.0
sh==1.14.1
shortuuid==1.0.1
simplejson==3.17.2
sip==4.19.25
six==1.15.0
snowballstemmer==2.1.0
soupsieve==2.2
speaklater==1.3
Sphinx==3.5.2
sphinx-rtd-theme==0.5.1
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==1.0.3
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.4
sqlacodegen==2.3.0
SQLAlchemy==1.3.23
sqlparse==0.4.1
sshtunnel==0.1.5
subdownloader==2.1.0
systemd-python==234
team==1.0
termcolor==1.1.0
terminado==0.9.2
terminator==2.1.0
testpath==0.4.4
testtools==2.4.0
texttable==1.6.3
threadpoolctl==2.1.0
tinycss2==1.1.0
tlsh==0.2.0
toml==0.10.2
tornado==6.1
traitlets==5.0.5
treq==21.1.0
Twisted==20.3.0
txaio==21.2.1
typed-ast==1.4.2
typing-extensions==3.7.4.3
tzlocal==2.1
urllib3==1.26.3
urwid==2.1.1
validate==5.1.0.dev0
virtualenv==20.4.2
waitress==1.4.4
wcwidth==0.2.5
webencodings==0.5.1
websocket-client==0.58.0
Werkzeug==1.0.1
Whoosh==2.7.4
widgetsnbextension==3.5.1
wsaccel==0.6.3
WTForms==2.2.1
xcffib==0.11.1
youtube-dl==2021.3.3
zipp==3.4.1
zope.interface==5.2.0
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 20 Mar 2021 14:26:33 +0100 |
parents | 3c9ba4a694ef |
children | 203755bbe0fe |
rev | line source |
---|---|
404
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client |
461 | 5 # Copyright (C) 2016-2021 Jérôme Poisson (goffi@goffi.org) |
404
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 # (at your option) any later version. |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 # GNU Affero General Public License for more details. |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 from kivy import properties |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 from kivy.animation import Animation |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from kivy.clock import Clock |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from kivy_garden import modernmenu |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from functools import partial |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 class TouchMenu(modernmenu.ModernMenu): |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 pass |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 class TouchMenuItemBehavior: |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 """Class to use on every item where a menu may appear |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 main_wid attribute must be set to the class inheriting from TouchMenuBehavior |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 do_item_action is the method called on simple click |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 getMenuChoices must return a list of menus for long press |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 menus there are dict as expected by ModernMenu |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 (translated text, index and callback) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 """ |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 main_wid = properties.ObjectProperty() |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 click_timeout = properties.NumericProperty(0.4) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 def on_touch_down(self, touch): |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 if not self.collide_point(*touch.pos): |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 return |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 t = partial(self.open_menu, touch) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 touch.ud['menu_timeout'] = t |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 Clock.schedule_once(t, self.click_timeout) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 return super(TouchMenuItemBehavior, self).on_touch_down(touch) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 def do_item_action(self, touch): |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 pass |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 def on_touch_up(self, touch): |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 if touch.ud.get('menu_timeout'): |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 Clock.unschedule(touch.ud['menu_timeout']) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 if self.collide_point(*touch.pos) and self.main_wid.menu is None: |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 self.do_item_action(touch) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 return super(TouchMenuItemBehavior, self).on_touch_up(touch) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 def open_menu(self, touch, dt): |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 self.main_wid.open_menu(self, touch) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 del touch.ud['menu_timeout'] |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 def getMenuChoices(self): |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 """return choice adapted to selected item |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 @return (list[dict]): choices ad expected by ModernMenu |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 """ |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 return [] |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 class TouchMenuBehavior: |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 """Class to handle a menu appearing on long press on items |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 classes using this behaviour need to have a float_layout property |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 pointing the main FloatLayout. |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 """ |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 float_layout = properties.ObjectProperty() |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 def __init__(self, *args, **kwargs): |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 super(TouchMenuBehavior, self).__init__(*args, **kwargs) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 self.menu = None |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 self.menu_item = None |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 ## menu methods ## |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 def clean_fl_children(self, layout, children): |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 """insure that self.menu and self.menu_item are None when menu is dimissed""" |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 if self.menu is not None and self.menu not in children: |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 self.menu = self.menu_item = None |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 def clear_menu(self): |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 """remove menu if there is one""" |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 if self.menu is not None: |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 self.menu.dismiss() |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 self.menu = None |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 self.menu_item = None |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 def open_menu(self, item, touch): |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 """open menu for item |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 @param item(PathWidget): item when the menu has been requested |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 @param touch(kivy.input.MotionEvent): touch data |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 """ |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 if self.menu_item == item: |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 return |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 self.clear_menu() |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 pos = self.to_widget(*touch.pos) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 choices = item.getMenuChoices() |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 if not choices: |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 return |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 self.menu = TouchMenu(choices=choices, |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 center=pos, |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 size_hint=(None, None)) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 self.float_layout.add_widget(self.menu) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 self.menu.start_display(touch) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 self.menu_item = item |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 def on_float_layout(self, wid, float_layout): |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 float_layout.bind(children=self.clean_fl_children) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 class FilterBehavior(object): |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 """class to handle items filtering with animation""" |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 def __init__(self, *args, **kwargs): |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 super(FilterBehavior, self).__init__(*args, **kwargs) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 self._filter_last = {} |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 self._filter_anim = Animation(width = 0, |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 height = 0, |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 opacity = 0, |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 d = 0.5) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 def do_filter(self, parent, text, get_child_text, width_cb, height_cb, |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 continue_tests=None): |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 """filter the children |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 filtered children will have a animation to set width, height and opacity to 0 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 @param parent(kivy.uix.widget.Widget): parent layout of the widgets to filter |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 @param text(unicode): filter text (if this text is not present in a child, |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 the child is filtered out) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 @param get_child_text(callable): must retrieve child text |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 child is used as sole argument |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 @param width_cb(callable, int, None): method to retrieve width when opened |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 child is used as sole argument, int can be used instead of callable |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 @param height_cb(callable, int, None): method to retrieve height when opened |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 child is used as sole argument, int can be used instead of callable |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 @param continue_tests(list[callable]): list of test to skip the item |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 all callables take child as sole argument. |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 if any of the callable return True, the child is skipped (i.e. not filtered) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 """ |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 text = text.strip().lower() |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 filtering = len(text)>len(self._filter_last.get(parent, '')) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 self._filter_last[parent] = text |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 for child in parent.children: |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 if continue_tests is not None and any((t(child) for t in continue_tests)): |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 continue |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 if text in get_child_text(child).lower(): |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 self._filter_anim.cancel(child) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 for key, method in (('width', width_cb), |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 ('height', height_cb), |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 ('opacity', lambda c: 1)): |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 try: |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 setattr(child, key, method(child)) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 except TypeError: |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 # method is not a callable, must be an int |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 setattr(child, key, method) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 elif (filtering |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 and child.opacity > 0 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 and not self._filter_anim.have_properties_to_animate(child)): |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 self._filter_anim.start(child) |