comparison src/cagou/core/menu.py @ 86:c711be670ecd

core, chat: upload plugin system: - extented plugin system so it's not only used with main widget. It is also used for upload widgets and can be extended more - plugin file name is used to detect the type: plugin_wid_* for main widgets, plugin_upload_* for upload widget plugins - a new UploadMenu class allows to easily add an upload button which will use loaded plugins - plugin_info can now specify a list of allowed platforms in "platforms" key - file upload in chat has been moved to a plugin
author Goffi <goffi@goffi.org>
date Sun, 25 Dec 2016 16:41:21 +0100
parents c2a7234d13d2
children 3dc526bb4a5a
comparison
equal deleted inserted replaced
85:c2a7234d13d2 86:c711be670ecd
155 def onAbout(self): 155 def onAbout(self):
156 about = AboutPopup() 156 about = AboutPopup()
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
161
162 class UploadMenu(contextmenu.ContextMenu):
163 # callback will be called with path to file to upload
164 callback = properties.ObjectProperty()
165 # cancel callback need to remove the widget for UI
166 # will be called with the widget to remove as argument
167 cancel_cb = properties.ObjectProperty()
168 # profiles if set will be sent to upload widget, may be used to get specific files
169 profiles = properties.ObjectProperty()
170
171 def __init__(self, **kwargs):
172 super(UploadMenu, self).__init__(**kwargs)
173 if self.cancel_cb is None:
174 self.cancel_cb = self.onUploadCancelled
175 if self.profiles is None:
176 self.profiles = iter(G.host.profiles)
177 for plug_info in G.host.getPluggedWidgets(type_=C.PLUG_TYPE_UPLOAD):
178 item = contextmenu.ContextMenuTextItem(
179 text = plug_info['name'],
180 on_release = lambda dummy, plug_info=plug_info: self.do_callback(plug_info)
181 )
182 self.add_widget(item)
183
184 def show(self, caller_wid=None):
185 if caller_wid is not None:
186 pos = caller_wid.x, caller_wid.top + self.get_height()
187 else:
188 pos = G.host.app.root_window.mouse_pos
189 super(UploadMenu, self).show(*pos)
190
191 def _closeUI(self, wid):
192 G.host.closeUI()
193
194 def onUploadCancelled(self, wid):
195 self._closeUI(wid)
196
197 def do_callback(self, plug_info):
198 self.hide()
199 if self.callback is None:
200 log.warning(u"UploadMenu callback is not set")
201 else:
202 wid = None
203 def onUploadCb(file_path):
204 self._closeUI(wid)
205 self.callback(file_path)
206 wid = plug_info['factory'](plug_info, onUploadCb, self.cancel_cb, self.profiles)
207 G.host.showExtraUI(wid)