comparison src/cagou/core/cagou_main.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 520a9e1a659b
children d654bdfeb404
comparison
equal deleted inserted replaced
96:641678ddc26c 97:5d2289127bb7
293 self.app.host = self 293 self.app.host = self
294 self.media_dir = self.app.media_dir = config.getConfig(main_config, '', 'media_dir') 294 self.media_dir = self.app.media_dir = config.getConfig(main_config, '', 'media_dir')
295 self.app.default_avatar = os.path.join(self.media_dir, "misc/default_avatar.png") 295 self.app.default_avatar = os.path.join(self.media_dir, "misc/default_avatar.png")
296 self.app.icon = os.path.join(self.media_dir, "icons/muchoslava/png/cagou_profil_bleu_96.png") 296 self.app.icon = os.path.join(self.media_dir, "icons/muchoslava/png/cagou_profil_bleu_96.png")
297 self._plg_wids = [] # main widgets plugins 297 self._plg_wids = [] # main widgets plugins
298 self._plg_wids_upload = [] # upload widgets plugins 298 self._plg_wids_transfer = [] # transfer widgets plugins
299 self._import_plugins() 299 self._import_plugins()
300 self._visible_widgets = {} # visible widgets by classes 300 self._visible_widgets = {} # visible widgets by classes
301 301
302 @property 302 @property
303 def visible_widgets(self): 303 def visible_widgets(self):
355 @param profiles(iterable): list of profiles 355 @param profiles(iterable): list of profiles
356 """ 356 """
357 main_cls = plugin_info['main'] 357 main_cls = plugin_info['main']
358 return self.widgets.getOrCreateWidget(main_cls, target, on_new_widget=None, profiles=iter(self.profiles)) 358 return self.widgets.getOrCreateWidget(main_cls, target, on_new_widget=None, profiles=iter(self.profiles))
359 359
360 def _defaultFactoryUpload(self, plugin_info, callback, cancel_cb, profiles): 360 def _defaultFactoryTransfer(self, plugin_info, callback, cancel_cb, profiles):
361 """default factory used to create upload widgets instances 361 """default factory used to create transfer widgets instances
362 362
363 @param plugin_info(dict): plugin datas 363 @param plugin_info(dict): plugin datas
364 @param callback(callable): method to call with path to file to upload 364 @param callback(callable): method to call with path to file to transfer
365 @param cancel_cb(callable): call when upload is cancelled 365 @param cancel_cb(callable): call when transfer is cancelled
366 upload widget must be used as first argument 366 transfer widget must be used as first argument
367 @param profiles(iterable): list of profiles 367 @param profiles(iterable): list of profiles
368 None if not specified 368 None if not specified
369 """ 369 """
370 main_cls = plugin_info['main'] 370 main_cls = plugin_info['main']
371 return main_cls(callback=callback, cancel_cb=cancel_cb) 371 return main_cls(callback=callback, cancel_cb=cancel_cb)
385 plugins_path = os.path.dirname(cagou.plugins.__file__) 385 plugins_path = os.path.dirname(cagou.plugins.__file__)
386 plugin_glob = u"plugin*." + C.PLUGIN_EXT 386 plugin_glob = u"plugin*." + C.PLUGIN_EXT
387 plug_lst = [os.path.splitext(p)[0] for p in map(os.path.basename, glob.glob(os.path.join(plugins_path, plugin_glob)))] 387 plug_lst = [os.path.splitext(p)[0] for p in map(os.path.basename, glob.glob(os.path.join(plugins_path, plugin_glob)))]
388 388
389 imported_names_main = set() # used to avoid loading 2 times plugin with same import name 389 imported_names_main = set() # used to avoid loading 2 times plugin with same import name
390 imported_names_upload = set() 390 imported_names_transfer = set()
391 for plug in plug_lst: 391 for plug in plug_lst:
392 plugin_path = 'cagou.plugins.' + plug 392 plugin_path = 'cagou.plugins.' + plug
393 393
394 # we get type from plugin name 394 # we get type from plugin name
395 suff = plug[7:] 395 suff = plug[7:]
400 400
401 # and select the variable to use according to type 401 # and select the variable to use according to type
402 if plugin_type == C.PLUG_TYPE_WID: 402 if plugin_type == C.PLUG_TYPE_WID:
403 imported_names = imported_names_main 403 imported_names = imported_names_main
404 default_factory = self._defaultFactoryMain 404 default_factory = self._defaultFactoryMain
405 elif plugin_type == C.PLUG_TYPE_UPLOAD: 405 elif plugin_type == C.PLUG_TYPE_TRANSFER:
406 imported_names = imported_names_upload 406 imported_names = imported_names_transfer
407 default_factory = self._defaultFactoryUpload 407 default_factory = self._defaultFactoryTransfer
408 else: 408 else:
409 log.error(u"unknown plugin type {type_} for plugin {file_}, skipping".format( 409 log.error(u"unknown plugin type {type_} for plugin {file_}, skipping".format(
410 type_ = plugin_type, 410 type_ = plugin_type,
411 file_ = plug 411 file_ = plug
412 )) 412 ))
482 log.error(_(u"no widget plugin found")) 482 log.error(_(u"no widget plugin found"))
483 return 483 return
484 484
485 # we want widgets sorted by names 485 # we want widgets sorted by names
486 self._plg_wids.sort(key=lambda p: p['name'].lower()) 486 self._plg_wids.sort(key=lambda p: p['name'].lower())
487 self._plg_wids_upload.sort(key=lambda p: p['name'].lower()) 487 self._plg_wids_transfer.sort(key=lambda p: p['name'].lower())
488 488
489 if self.default_wid is None: 489 if self.default_wid is None:
490 # we have no selector widget, we use the first widget as default 490 # we have no selector widget, we use the first widget as default
491 self.default_wid = self._plg_wids[0] 491 self.default_wid = self._plg_wids[0]
492 492
493 def _getPluginsSet(self, type_): 493 def _getPluginsSet(self, type_):
494 if type_ == C.PLUG_TYPE_WID: 494 if type_ == C.PLUG_TYPE_WID:
495 return self._plg_wids 495 return self._plg_wids
496 elif type_ == C.PLUG_TYPE_UPLOAD: 496 elif type_ == C.PLUG_TYPE_TRANSFER:
497 return self._plg_wids_upload 497 return self._plg_wids_transfer
498 else: 498 else:
499 raise KeyError(u"{} plugin type is unknown".format(type_)) 499 raise KeyError(u"{} plugin type is unknown".format(type_))
500 500
501 def getPluggedWidgets(self, type_=C.PLUG_TYPE_WID, except_cls=None): 501 def getPluggedWidgets(self, type_=C.PLUG_TYPE_WID, except_cls=None):
502 """get available widgets plugin infos 502 """get available widgets plugin infos