Mercurial > libervia-desktop-kivy
changeset 41:7cac2d1a6f20
core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 28 Aug 2016 16:11:07 +0200 |
parents | a1ec6cb57a1b |
children | 286865bc013a |
files | src/cagou/core/cagou_main.py src/cagou/plugins/plugin_wid_chat.py |
diffstat | 2 files changed, 18 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/cagou/core/cagou_main.py Sun Aug 28 15:37:22 2016 +0200 +++ b/src/cagou/core/cagou_main.py Sun Aug 28 16:11:07 2016 +0200 @@ -306,13 +306,29 @@ @param except_cls(None, class): if not None, widgets from this class will be excluded - @return (list[dict]): available widgets plugin infos + @return (iter[dict]): available widgets plugin infos """ for plugin_data in self._plg_wids: if plugin_data['main'] == except_cls: continue yield plugin_data + def getPluginInfo(self, **kwargs): + """get first plugin info corresponding to filters + + @param **kwargs: filter(s) to use, each key present here must also + exist and be of the same value in requested plugin info + @return (dict, None): found plugin info or None + """ + for plugin_info in self._plg_wids: + for k, w in kwargs.iteritems(): + try: + if plugin_info[k] != w: + continue + except KeyError: + continue + return plugin_info + ## widgets handling def getParentHandler(self, widget):
--- a/src/cagou/plugins/plugin_wid_chat.py Sun Aug 28 15:37:22 2016 +0200 +++ b/src/cagou/plugins/plugin_wid_chat.py Sun Aug 28 16:11:07 2016 +0200 @@ -155,7 +155,7 @@ raise NotImplementedError(u"MUC not implemented yet") # G.host.bridge.MUCJoin(unicode(jid_), "", "", self.profile) else: - plugin_info = [p for p in G.host.getPluggedWidgets() if p["factory"] == self.factory][0] # FIXME: Q&D way, need a proper method in host + plugin_info = G.host.getPluginInfo(main=Chat) factory = plugin_info['factory'] G.host.switchWidget(self, factory(plugin_info, jid_, profiles=[self.profile])) self.header_input.text = ''