# HG changeset patch # User Goffi # Date 1472393467 -7200 # Node ID 7cac2d1a6f20906b335c1f2b9bdb6e47e2a6ab7f # Parent a1ec6cb57a1bd253ad1b4a6df0b21b358652fe36 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s) diff -r a1ec6cb57a1b -r 7cac2d1a6f20 src/cagou/core/cagou_main.py --- 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): diff -r a1ec6cb57a1b -r 7cac2d1a6f20 src/cagou/plugins/plugin_wid_chat.py --- 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 = ''