Mercurial > libervia-desktop-kivy
comparison src/cagou/core/menu.py @ 97:5d2289127bb7
menu (upload): better menu using dedicated widget:
upload menu now use a decicated widget instead of context menu.
The menu take half the size of the main window, and show each upload option as an icon. Use can select upload or P2P sending, and a short text message explains how the file will be transmitted.
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 29 Dec 2016 23:47:07 +0100 |
parents | 3dc526bb4a5a |
children | 4d8c122b86a6 |
comparison
equal
deleted
inserted
replaced
96:641678ddc26c | 97:5d2289127bb7 |
---|---|
157 about.title = ABOUT_TITLE | 157 about.title = ABOUT_TITLE |
158 about.content = AboutContent(text=ABOUT_CONTENT, markup=True) | 158 about.content = AboutContent(text=ABOUT_CONTENT, markup=True) |
159 about.open() | 159 about.open() |
160 | 160 |
161 | 161 |
162 class UploadMenu(contextmenu.ContextMenu): | 162 class TransferItem(BoxLayout): |
163 """upload menu which handle display and callbacks""" | 163 plug_info = properties.DictProperty() |
164 # callback will be called with path to file to upload | 164 |
165 def on_touch_up(self, touch): | |
166 if not self.collide_point(*touch.pos): | |
167 return super(TransferItem, self).on_touch_up(touch) | |
168 else: | |
169 transfer_menu = self.parent | |
170 while not isinstance(transfer_menu, TransferMenu): | |
171 transfer_menu = transfer_menu.parent | |
172 transfer_menu.do_callback(self.plug_info) | |
173 return True | |
174 | |
175 | |
176 class TransferMenu(BoxLayout): | |
177 """transfer menu which handle display and callbacks""" | |
178 # callback will be called with path to file to transfer | |
165 callback = properties.ObjectProperty() | 179 callback = properties.ObjectProperty() |
166 # cancel callback need to remove the widget for UI | 180 # cancel callback need to remove the widget for UI |
167 # will be called with the widget to remove as argument | 181 # will be called with the widget to remove as argument |
168 cancel_cb = properties.ObjectProperty() | 182 cancel_cb = properties.ObjectProperty() |
169 # profiles if set will be sent to upload widget, may be used to get specific files | 183 # profiles if set will be sent to transfer widget, may be used to get specific files |
170 profiles = properties.ObjectProperty() | 184 profiles = properties.ObjectProperty() |
185 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") | |
186 send_txt = _(u"The file will be sent unencrypted directly to your contact (without transiting by the server), except in some cases") | |
187 items_layout = properties.ObjectProperty() | |
171 | 188 |
172 def __init__(self, **kwargs): | 189 def __init__(self, **kwargs): |
173 super(UploadMenu, self).__init__(**kwargs) | 190 super(TransferMenu, self).__init__(**kwargs) |
174 if self.cancel_cb is None: | 191 if self.cancel_cb is None: |
175 self.cancel_cb = self.onUploadCancelled | 192 self.cancel_cb = self.onTransferCancelled |
176 if self.profiles is None: | 193 if self.profiles is None: |
177 self.profiles = iter(G.host.profiles) | 194 self.profiles = iter(G.host.profiles) |
178 for plug_info in G.host.getPluggedWidgets(type_=C.PLUG_TYPE_UPLOAD): | 195 for plug_info in G.host.getPluggedWidgets(type_=C.PLUG_TYPE_TRANSFER): |
179 item = contextmenu.ContextMenuTextItem( | 196 item = TransferItem( |
180 text = plug_info['name'], | 197 plug_info = plug_info |
181 on_release = lambda dummy, plug_info=plug_info: self.do_callback(plug_info) | |
182 ) | 198 ) |
183 self.add_widget(item) | 199 self.items_layout.add_widget(item) |
184 | 200 |
185 def show(self, caller_wid=None): | 201 def show(self, caller_wid=None): |
186 if caller_wid is not None: | 202 self.visible = True |
187 pos = caller_wid.x, caller_wid.top + self.get_height() | 203 G.host.app.root.add_widget(self) |
188 else: | 204 |
189 pos = G.host.app.root_window.mouse_pos | 205 def on_touch_down(self, touch): |
190 super(UploadMenu, self).show(*pos) | 206 # we remove the menu if we click outside |
207 # else we want to handle the event, but not | |
208 # transmit it to parents | |
209 if not self.collide_point(*touch.pos): | |
210 self.parent.remove_widget(self) | |
211 else: | |
212 return super(TransferMenu, self).on_touch_down(touch) | |
213 return True | |
191 | 214 |
192 def _closeUI(self, wid): | 215 def _closeUI(self, wid): |
193 G.host.closeUI() | 216 G.host.closeUI() |
194 | 217 |
195 def onUploadCancelled(self, wid, cleaning_cb=None): | 218 def onTransferCancelled(self, wid, cleaning_cb=None): |
196 self._closeUI(wid) | 219 self._closeUI(wid) |
197 if cleaning_cb is not None: | 220 if cleaning_cb is not None: |
198 cleaning_cb() | 221 cleaning_cb() |
199 | 222 |
200 def do_callback(self, plug_info): | 223 def do_callback(self, plug_info): |
201 self.hide() | 224 self.parent.remove_widget(self) |
202 if self.callback is None: | 225 if self.callback is None: |
203 log.warning(u"UploadMenu callback is not set") | 226 log.warning(u"TransferMenu callback is not set") |
204 else: | 227 else: |
205 wid = None | 228 wid = None |
206 external = plug_info.get('external', False) | 229 external = plug_info.get('external', False) |
207 def onUploadCb(file_path, cleaning_cb=None): | 230 def onTransferCb(file_path, cleaning_cb=None): |
208 if not external: | 231 if not external: |
209 self._closeUI(wid) | 232 self._closeUI(wid) |
210 self.callback(file_path, cleaning_cb) | 233 self.callback(file_path, cleaning_cb) |
211 wid = plug_info['factory'](plug_info, onUploadCb, self.cancel_cb, self.profiles) | 234 wid = plug_info['factory'](plug_info, onTransferCb, self.cancel_cb, self.profiles) |
212 if not external: | 235 if not external: |
213 G.host.showExtraUI(wid) | 236 G.host.showExtraUI(wid) |