Mercurial > libervia-desktop-kivy
annotate cagou/core/menu.py @ 373:5d994be1161b
core: removed root menus (i.e. global menu on top of window):
root menus were not really useful as most actions doable there are doable through others
widgets in Cagou. For actions without equivalent in widgets (like about screen), a new
menu, more discreet, will be added soon.
Kivy Garden's ContextMenu is not used anymore, so it has been removed from dependencies
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 27 Jan 2020 21:17:09 +0100 |
parents | 9c6fe392d623 |
children | 9ef01266e3fe |
rev | line source |
---|---|
51 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client | |
282 | 5 # Copyright (C) 2016-2019 Jérôme Poisson (goffi@goffi.org) |
51 | 6 |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 | |
21 from sat.core.i18n import _ | |
22 from sat.core import log as logging | |
23 from cagou.core.constants import Const as C | |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
24 from cagou.core.common import JidToggle |
85
c2a7234d13d2
menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents:
53
diff
changeset
|
25 from kivy.uix.boxlayout import BoxLayout |
51 | 26 from kivy.uix.label import Label |
27 from kivy.uix.popup import Popup | |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
28 from cagou.core.utils import FilterBehavior |
51 | 29 from kivy import properties |
373
5d994be1161b
core: removed root menus (i.e. global menu on top of window):
Goffi <goffi@goffi.org>
parents:
365
diff
changeset
|
30 from kivy_garden import modernmenu |
168
397f2fb67aab
core (menu): animate transfer menu opening/closing + close it on [ESC]/back
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
31 from kivy.core.window import Window |
397f2fb67aab
core (menu): animate transfer menu opening/closing + close it on [ESC]/back
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
32 from kivy.animation import Animation |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
33 from kivy.metrics import dp |
222 | 34 from kivy.clock import Clock |
51 | 35 from cagou import G |
222 | 36 from functools import partial |
51 | 37 import webbrowser |
38 | |
302
f55b60659ec1
core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
39 log = logging.getLogger(__name__) |
f55b60659ec1
core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
40 |
312 | 41 ABOUT_TITLE = _("About {}".format(C.APP_NAME)) |
42 ABOUT_CONTENT = _("""[b]Cagou (Salut à Toi)[/b] | |
302
f55b60659ec1
core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
43 |
f55b60659ec1
core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
44 [u]cagou version[/u]: |
f55b60659ec1
core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
45 {version} |
f55b60659ec1
core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
46 |
f55b60659ec1
core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
47 [u]backend version[/u]: |
f55b60659ec1
core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
48 {backend_version} |
51 | 49 |
50 Cagou is a libre communication tool based on libre standard XMPP. | |
51 | |
302
f55b60659ec1
core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
52 Cagou is part of the "Salut à Toi" project (desktop/mobile frontend) |
51 | 53 more informations at [color=5500ff][ref=website]salut-a-toi.org[/ref][/color] |
246 | 54 """) |
51 | 55 |
56 | |
57 class AboutContent(Label): | |
58 | |
59 def on_ref_press(self, value): | |
60 if value == "website": | |
61 webbrowser.open("https://salut-a-toi.org") | |
62 | |
63 | |
64 class AboutPopup(Popup): | |
65 | |
66 def on_touch_down(self, touch): | |
67 if self.collide_point(*touch.pos): | |
68 self.dismiss() | |
69 return super(AboutPopup, self).on_touch_down(touch) | |
70 | |
71 | |
97
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
72 class TransferItem(BoxLayout): |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
73 plug_info = properties.DictProperty() |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
74 |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
75 def on_touch_up(self, touch): |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
76 if not self.collide_point(*touch.pos): |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
77 return super(TransferItem, self).on_touch_up(touch) |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
78 else: |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
79 transfer_menu = self.parent |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
80 while not isinstance(transfer_menu, TransferMenu): |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
81 transfer_menu = transfer_menu.parent |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
82 transfer_menu.do_callback(self.plug_info) |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
83 return True |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
84 |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
85 |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
86 class SideMenu(BoxLayout): |
216
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
87 size_hint_close = (0, 1) |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
88 size_hint_open = (0.4, 1) |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
89 size_close = (100, 100) |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
90 size_open = (0, 0) |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
91 bg_color = properties.ListProperty([0, 0, 0, 1]) |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
92 # callback will be called with arguments relevant to menu |
86 | 93 callback = properties.ObjectProperty() |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
94 # call do_callback even when menu is cancelled |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
95 callback_on_close = properties.BooleanProperty(False) |
86 | 96 # cancel callback need to remove the widget for UI |
97 # will be called with the widget to remove as argument | |
98 cancel_cb = properties.ObjectProperty() | |
99 | |
100 def __init__(self, **kwargs): | |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
101 super(SideMenu, self).__init__(**kwargs) |
86 | 102 if self.cancel_cb is None: |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
103 self.cancel_cb = self.onMenuCancelled |
86 | 104 |
216
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
105 def _set_anim_kw(self, kw, size_hint, size): |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
106 """Set animation keywords |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
107 |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
108 for each value of size_hint it is used if not None, |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
109 else size is used. |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
110 If one value of size is bigger than the respective one of Window |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
111 the one of Window is used |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
112 """ |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
113 size_hint_x, size_hint_y = size_hint |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
114 width, height = size |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
115 if size_hint_x is not None: |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
116 kw['size_hint_x'] = size_hint_x |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
117 elif width is not None: |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
118 kw['width'] = min(width, Window.width) |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
119 |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
120 if size_hint_y is not None: |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
121 kw['size_hint_y'] = size_hint_y |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
122 elif height is not None: |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
123 kw['height'] = min(height, Window.height) |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
124 |
86 | 125 def show(self, caller_wid=None): |
168
397f2fb67aab
core (menu): animate transfer menu opening/closing + close it on [ESC]/back
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
126 Window.bind(on_keyboard=self.key_input) |
97
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
127 G.host.app.root.add_widget(self) |
216
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
128 kw = {'d': 0.3, 't': 'out_back'} |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
129 self._set_anim_kw(kw, self.size_hint_open, self.size_open) |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
130 Animation(**kw).start(self) |
168
397f2fb67aab
core (menu): animate transfer menu opening/closing + close it on [ESC]/back
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
131 |
397f2fb67aab
core (menu): animate transfer menu opening/closing + close it on [ESC]/back
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
132 def hide(self): |
397f2fb67aab
core (menu): animate transfer menu opening/closing + close it on [ESC]/back
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
133 Window.unbind(on_keyboard=self.key_input) |
216
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
134 kw = {'d': 0.2} |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
135 self._set_anim_kw(kw, self.size_hint_close, self.size_close) |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
136 anim = Animation(**kw) |
168
397f2fb67aab
core (menu): animate transfer menu opening/closing + close it on [ESC]/back
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
137 anim.bind(on_complete=lambda anim, menu: self.parent.remove_widget(self)) |
397f2fb67aab
core (menu): animate transfer menu opening/closing + close it on [ESC]/back
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
138 anim.start(self) |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
139 if self.callback_on_close: |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
140 self.do_callback() |
97
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
141 |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
142 def on_touch_down(self, touch): |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
143 # we remove the menu if we click outside |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
144 # else we want to handle the event, but not |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
145 # transmit it to parents |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
146 if not self.collide_point(*touch.pos): |
168
397f2fb67aab
core (menu): animate transfer menu opening/closing + close it on [ESC]/back
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
147 self.hide() |
86 | 148 else: |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
149 return super(SideMenu, self).on_touch_down(touch) |
97
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
150 return True |
86 | 151 |
168
397f2fb67aab
core (menu): animate transfer menu opening/closing + close it on [ESC]/back
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
152 def key_input(self, window, key, scancode, codepoint, modifier): |
397f2fb67aab
core (menu): animate transfer menu opening/closing + close it on [ESC]/back
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
153 if key == 27: |
397f2fb67aab
core (menu): animate transfer menu opening/closing + close it on [ESC]/back
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
154 self.hide() |
397f2fb67aab
core (menu): animate transfer menu opening/closing + close it on [ESC]/back
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
155 return True |
397f2fb67aab
core (menu): animate transfer menu opening/closing + close it on [ESC]/back
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
156 |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
157 def onMenuCancelled(self, wid, cleaning_cb=None): |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
158 self._closeUI(wid) |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
159 if cleaning_cb is not None: |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
160 cleaning_cb() |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
161 |
86 | 162 def _closeUI(self, wid): |
163 G.host.closeUI() | |
164 | |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
165 def do_callback(self, *args, **kwargs): |
312 | 166 log.warning("callback not implemented") |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
167 |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
168 |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
169 class TransferMenu(SideMenu): |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
170 """transfer menu which handle display and callbacks""" |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
171 # callback will be called with path to file to transfer |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
172 # profiles if set will be sent to transfer widget, may be used to get specific files |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
173 profiles = properties.ObjectProperty() |
312 | 174 transfer_txt = _("Beware! The file will be sent to your server and stay unencrypted " |
175 "there\nServer admin(s) can see the file, and they choose how, " | |
176 "when and if it will be deleted") | |
177 send_txt = _("The file will be sent unencrypted directly to your contact " | |
178 "(without transiting by the server), except in some cases") | |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
179 items_layout = properties.ObjectProperty() |
216
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
180 size_hint_close = (1, 0) |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
181 size_hint_open = (1, 0.5) |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
182 |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
183 def __init__(self, **kwargs): |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
184 super(TransferMenu, self).__init__(**kwargs) |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
185 if self.profiles is None: |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
186 self.profiles = iter(G.host.profiles) |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
187 for plug_info in G.host.getPluggedWidgets(type_=C.PLUG_TYPE_TRANSFER): |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
188 item = TransferItem( |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
189 plug_info = plug_info |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
190 ) |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
191 self.items_layout.add_widget(item) |
86 | 192 |
193 def do_callback(self, plug_info): | |
97
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
194 self.parent.remove_widget(self) |
86 | 195 if self.callback is None: |
312 | 196 log.warning("TransferMenu callback is not set") |
86 | 197 else: |
198 wid = None | |
88
3dc526bb4a5a
upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents:
86
diff
changeset
|
199 external = plug_info.get('external', False) |
97
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
200 def onTransferCb(file_path, cleaning_cb=None): |
88
3dc526bb4a5a
upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents:
86
diff
changeset
|
201 if not external: |
3dc526bb4a5a
upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents:
86
diff
changeset
|
202 self._closeUI(wid) |
98
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
203 self.callback( |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
204 file_path, |
222 | 205 transfer_type = (C.TRANSFER_UPLOAD |
322
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
312
diff
changeset
|
206 if self.ids['upload_btn'].state == "down" else C.TRANSFER_SEND), |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
312
diff
changeset
|
207 cleaning_cb=cleaning_cb, |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
312
diff
changeset
|
208 ) |
222 | 209 wid = plug_info['factory'](plug_info, |
210 onTransferCb, | |
211 self.cancel_cb, | |
212 self.profiles) | |
88
3dc526bb4a5a
upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents:
86
diff
changeset
|
213 if not external: |
3dc526bb4a5a
upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents:
86
diff
changeset
|
214 G.host.showExtraUI(wid) |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
215 |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
216 |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
217 class EntitiesSelectorMenu(SideMenu, FilterBehavior): |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
218 """allow to select entities from roster""" |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
219 profiles = properties.ObjectProperty() |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
220 layout = properties.ObjectProperty() |
312 | 221 instructions = properties.StringProperty(_("Please select entities")) |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
222 filter_input = properties.ObjectProperty() |
216
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
223 size_hint_close = (None, 1) |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
224 size_hint_open = (None, 1) |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
225 size_open = (dp(250), 100) |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
226 size_close = (0, 100) |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
227 |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
228 def __init__(self, **kwargs): |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
229 super(EntitiesSelectorMenu, self).__init__(**kwargs) |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
230 self.filter_input.bind(text=self.do_filter_input) |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
231 if self.profiles is None: |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
232 self.profiles = iter(G.host.profiles) |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
233 for profile in self.profiles: |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
234 for jid_, jid_data in G.host.contact_lists[profile].all_iter: |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
235 jid_wid = JidToggle( |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
236 jid=jid_, |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
237 profile=profile) |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
238 self.layout.add_widget(jid_wid) |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
239 |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
240 def do_callback(self): |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
241 if self.callback is not None: |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
242 jids = [c.jid for c in self.layout.children if c.state == 'down'] |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
243 self.callback(jids) |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
244 |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
245 def do_filter_input(self, filter_input, text): |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
246 self.layout.spacing = 0 if text else dp(5) |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
247 self.do_filter(self.layout.children, |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
248 text, |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
249 lambda c: c.jid, |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
250 width_cb=lambda c: c.width, |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
251 height_cb=lambda c: dp(70)) |
222 | 252 |
253 | |
254 class TouchMenu(modernmenu.ModernMenu): | |
255 pass | |
256 | |
257 | |
258 class TouchMenuItemBehaviour(object): | |
259 """Class to use on every item where a menu may appear | |
260 | |
261 main_wid attribute must be set to the class inheriting from TouchMenuBehaviour | |
262 do_item_action is the method called on simple click | |
263 getMenuChoices must return a list of menus for long press | |
264 menus there are dict as expected by ModernMenu | |
265 (translated text, index and callback) | |
266 """ | |
267 main_wid = properties.ObjectProperty() | |
268 click_timeout = properties.NumericProperty(0.4) | |
269 | |
270 def on_touch_down(self, touch): | |
271 if not self.collide_point(*touch.pos): | |
272 return | |
273 t = partial(self.open_menu, touch) | |
274 touch.ud['menu_timeout'] = t | |
275 Clock.schedule_once(t, self.click_timeout) | |
276 return super(TouchMenuItemBehaviour, self).on_touch_down(touch) | |
277 | |
278 def do_item_action(self, touch): | |
279 pass | |
280 | |
281 def on_touch_up(self, touch): | |
282 if touch.ud.get('menu_timeout'): | |
283 Clock.unschedule(touch.ud['menu_timeout']) | |
284 if self.collide_point(*touch.pos) and self.main_wid.menu is None: | |
285 self.do_item_action(touch) | |
286 return super(TouchMenuItemBehaviour, self).on_touch_up(touch) | |
287 | |
288 def open_menu(self, touch, dt): | |
289 self.main_wid.open_menu(self, touch) | |
290 del touch.ud['menu_timeout'] | |
291 | |
292 def getMenuChoices(self): | |
293 """return choice adapted to selected item | |
294 | |
295 @return (list[dict]): choices ad expected by ModernMenu | |
296 """ | |
297 return [] | |
298 | |
299 | |
300 class TouchMenuBehaviour(object): | |
301 """Class to handle a menu appearing on long press on items | |
302 | |
303 classes using this behaviour need to have a float_layout property | |
304 pointing the main FloatLayout. | |
305 """ | |
306 float_layout = properties.ObjectProperty() | |
307 | |
308 def __init__(self, *args, **kwargs): | |
309 super(TouchMenuBehaviour, self).__init__(*args, **kwargs) | |
310 self.menu = None | |
311 self.menu_item = None | |
312 | |
313 ## menu methods ## | |
314 | |
315 def clean_fl_children(self, layout, children): | |
316 """insure that self.menu and self.menu_item are None when menu is dimissed""" | |
317 if self.menu is not None and self.menu not in children: | |
318 self.menu = self.menu_item = None | |
319 | |
320 def clear_menu(self): | |
321 """remove menu if there is one""" | |
322 if self.menu is not None: | |
323 self.menu.dismiss() | |
324 self.menu = None | |
325 self.menu_item = None | |
326 | |
327 def open_menu(self, item, touch): | |
328 """open menu for item | |
329 | |
330 @param item(PathWidget): item when the menu has been requested | |
331 @param touch(kivy.input.MotionEvent): touch data | |
332 """ | |
333 if self.menu_item == item: | |
334 return | |
335 self.clear_menu() | |
336 pos = self.to_widget(*touch.pos) | |
337 choices = item.getMenuChoices() | |
338 if not choices: | |
339 return | |
340 self.menu = TouchMenu(choices=choices, | |
365
9c6fe392d623
core (widgets_handler): use a StencilView + BoxLayout instead of ScrollView as wrapper:
Goffi <goffi@goffi.org>
parents:
327
diff
changeset
|
341 center=pos, |
9c6fe392d623
core (widgets_handler): use a StencilView + BoxLayout instead of ScrollView as wrapper:
Goffi <goffi@goffi.org>
parents:
327
diff
changeset
|
342 size_hint=(None, None)) |
222 | 343 self.float_layout.add_widget(self.menu) |
344 self.menu.start_display(touch) | |
345 self.menu_item = item | |
346 | |
347 def on_float_layout(self, wid, float_layout): | |
348 float_layout.bind(children=self.clean_fl_children) |