# HG changeset patch # User souliane # Date 1425475058 -3600 # Node ID 273b044fde6defe2c1ad52f7db66cee6c2398b56 # Parent a39d2db03c80a898b3383e4a245546d67acf28cf quick_frontend: add a method getWidget to return a widget without creating it if it doesn't exist diff -r a39d2db03c80 -r 273b044fde6d frontends/src/quick_frontend/quick_widgets.py --- a/frontends/src/quick_frontend/quick_widgets.py Tue Mar 03 22:17:57 2015 +0100 +++ b/frontends/src/quick_frontend/quick_widgets.py Wed Mar 04 14:17:38 2015 +0100 @@ -93,6 +93,21 @@ 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