Mercurial > libervia-desktop-kivy
diff 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 |
line wrap: on
line diff
--- a/src/cagou/core/menu.py Thu Dec 29 23:47:04 2016 +0100 +++ b/src/cagou/core/menu.py Thu Dec 29 23:47:07 2016 +0100 @@ -159,55 +159,78 @@ about.open() -class UploadMenu(contextmenu.ContextMenu): - """upload menu which handle display and callbacks""" - # callback will be called with path to file to upload +class TransferItem(BoxLayout): + plug_info = properties.DictProperty() + + def on_touch_up(self, touch): + if not self.collide_point(*touch.pos): + return super(TransferItem, self).on_touch_up(touch) + else: + transfer_menu = self.parent + while not isinstance(transfer_menu, TransferMenu): + transfer_menu = transfer_menu.parent + transfer_menu.do_callback(self.plug_info) + return True + + +class TransferMenu(BoxLayout): + """transfer menu which handle display and callbacks""" + # callback will be called with path to file to transfer callback = properties.ObjectProperty() # cancel callback need to remove the widget for UI # will be called with the widget to remove as argument cancel_cb = properties.ObjectProperty() - # profiles if set will be sent to upload widget, may be used to get specific files + # profiles if set will be sent to transfer widget, may be used to get specific files profiles = properties.ObjectProperty() + 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") + send_txt = _(u"The file will be sent unencrypted directly to your contact (without transiting by the server), except in some cases") + items_layout = properties.ObjectProperty() def __init__(self, **kwargs): - super(UploadMenu, self).__init__(**kwargs) + super(TransferMenu, self).__init__(**kwargs) if self.cancel_cb is None: - self.cancel_cb = self.onUploadCancelled + self.cancel_cb = self.onTransferCancelled if self.profiles is None: self.profiles = iter(G.host.profiles) - for plug_info in G.host.getPluggedWidgets(type_=C.PLUG_TYPE_UPLOAD): - item = contextmenu.ContextMenuTextItem( - text = plug_info['name'], - on_release = lambda dummy, plug_info=plug_info: self.do_callback(plug_info) + for plug_info in G.host.getPluggedWidgets(type_=C.PLUG_TYPE_TRANSFER): + item = TransferItem( + plug_info = plug_info ) - self.add_widget(item) + self.items_layout.add_widget(item) def show(self, caller_wid=None): - if caller_wid is not None: - pos = caller_wid.x, caller_wid.top + self.get_height() + self.visible = True + G.host.app.root.add_widget(self) + + def on_touch_down(self, touch): + # we remove the menu if we click outside + # else we want to handle the event, but not + # transmit it to parents + if not self.collide_point(*touch.pos): + self.parent.remove_widget(self) else: - pos = G.host.app.root_window.mouse_pos - super(UploadMenu, self).show(*pos) + return super(TransferMenu, self).on_touch_down(touch) + return True def _closeUI(self, wid): G.host.closeUI() - def onUploadCancelled(self, wid, cleaning_cb=None): + def onTransferCancelled(self, wid, cleaning_cb=None): self._closeUI(wid) if cleaning_cb is not None: cleaning_cb() def do_callback(self, plug_info): - self.hide() + self.parent.remove_widget(self) if self.callback is None: - log.warning(u"UploadMenu callback is not set") + log.warning(u"TransferMenu callback is not set") else: wid = None external = plug_info.get('external', False) - def onUploadCb(file_path, cleaning_cb=None): + def onTransferCb(file_path, cleaning_cb=None): if not external: self._closeUI(wid) self.callback(file_path, cleaning_cb) - wid = plug_info['factory'](plug_info, onUploadCb, self.cancel_cb, self.profiles) + wid = plug_info['factory'](plug_info, onTransferCb, self.cancel_cb, self.profiles) if not external: G.host.showExtraUI(wid)