comparison src/cagou/core/menu.py @ 88:3dc526bb4a5a

upload: plugin android gallery, first draft: - added "external" key in PLUGIN_INFO which indicate that a plugin doesn't create a widget when set to True - callback and cancel_cb method in UploadMenu now use a cleaning_cb arguments which can be None. If set, the callback will be called without argument once the file is uploaded - the AndroidGallery plugin looks for images on Android, then save the content to a temporary file an upload it, then clean the file. This plugin is only active on android platform.
author Goffi <goffi@goffi.org>
date Sun, 25 Dec 2016 22:53:50 +0100
parents c711be670ecd
children 5d2289127bb7
comparison
equal deleted inserted replaced
87:17094a075fd2 88:3dc526bb4a5a
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 UploadMenu(contextmenu.ContextMenu):
163 """upload menu which handle display and callbacks"""
163 # callback will be called with path to file to upload 164 # callback will be called with path to file to upload
164 callback = properties.ObjectProperty() 165 callback = properties.ObjectProperty()
165 # cancel callback need to remove the widget for UI 166 # cancel callback need to remove the widget for UI
166 # will be called with the widget to remove as argument 167 # will be called with the widget to remove as argument
167 cancel_cb = properties.ObjectProperty() 168 cancel_cb = properties.ObjectProperty()
189 super(UploadMenu, self).show(*pos) 190 super(UploadMenu, self).show(*pos)
190 191
191 def _closeUI(self, wid): 192 def _closeUI(self, wid):
192 G.host.closeUI() 193 G.host.closeUI()
193 194
194 def onUploadCancelled(self, wid): 195 def onUploadCancelled(self, wid, cleaning_cb=None):
195 self._closeUI(wid) 196 self._closeUI(wid)
197 if cleaning_cb is not None:
198 cleaning_cb()
196 199
197 def do_callback(self, plug_info): 200 def do_callback(self, plug_info):
198 self.hide() 201 self.hide()
199 if self.callback is None: 202 if self.callback is None:
200 log.warning(u"UploadMenu callback is not set") 203 log.warning(u"UploadMenu callback is not set")
201 else: 204 else:
202 wid = None 205 wid = None
203 def onUploadCb(file_path): 206 external = plug_info.get('external', False)
204 self._closeUI(wid) 207 def onUploadCb(file_path, cleaning_cb=None):
205 self.callback(file_path) 208 if not external:
209 self._closeUI(wid)
210 self.callback(file_path, cleaning_cb)
206 wid = plug_info['factory'](plug_info, onUploadCb, self.cancel_cb, self.profiles) 211 wid = plug_info['factory'](plug_info, onUploadCb, self.cancel_cb, self.profiles)
207 G.host.showExtraUI(wid) 212 if not external:
213 G.host.showExtraUI(wid)