From b160e3d92c999e7e22211c2887d2e0fea3c21132 Mon Sep 17 00:00:00 2001 From: souliane Date: Wed, 4 Mar 2015 14:17:38 +0100 Subject: [PATCH] quick_frontend: add a method getWidget to return a widget without creating it if it doesn't exist --- frontends/src/quick_frontend/quick_widgets.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/frontends/src/quick_frontend/quick_widgets.py b/frontends/src/quick_frontend/quick_widgets.py index 0cbc4a4d..adf8cd17 100644 --- a/frontends/src/quick_frontend/quick_widgets.py +++ b/frontends/src/quick_frontend/quick_widgets.py @@ -93,6 +93,21 @@ class QuickWidgetsManager(object): else: return widgets_map.itervalues() + def getWidget(self, class_, target, profile): + """Get a widget without creating it if it doesn't exist. + + @param class_(class): class of the widget to create + @param target: target depending of the widget, usually a JID instance + @param profile (unicode): %(doc_profile)s + @return: a class_ instance or None if the widget doesn't exist + """ + class_ = self.getRealClass(class_) + hash_ = class_.getWidgetHash(target, profile) + try: + return self._widgets[class_.__name__][hash_] + except KeyError: + return None + def getOrCreateWidget(self, class_, target, *args, **kwargs): """Get an existing widget or create a new one when necessary