comparison frontends/src/quick_frontend/quick_widgets.py @ 1349:273b044fde6d frontends_multi_profiles

quick_frontend: add a method getWidget to return a widget without creating it if it doesn't exist
author souliane <souliane@mailoo.org>
date Wed, 04 Mar 2015 14:17:38 +0100
parents 1f13a837e4b2
children 069ad98b360d
comparison
equal deleted inserted replaced
1348:a39d2db03c80 1349:273b044fde6d
90 widgets_map = self._widgets[class_.__name__] 90 widgets_map = self._widgets[class_.__name__]
91 except KeyError: 91 except KeyError:
92 return iter([]) 92 return iter([])
93 else: 93 else:
94 return widgets_map.itervalues() 94 return widgets_map.itervalues()
95
96 def getWidget(self, class_, target, profile):
97 """Get a widget without creating it if it doesn't exist.
98
99 @param class_(class): class of the widget to create
100 @param target: target depending of the widget, usually a JID instance
101 @param profile (unicode): %(doc_profile)s
102 @return: a class_ instance or None if the widget doesn't exist
103 """
104 class_ = self.getRealClass(class_)
105 hash_ = class_.getWidgetHash(target, profile)
106 try:
107 return self._widgets[class_.__name__][hash_]
108 except KeyError:
109 return None
95 110
96 def getOrCreateWidget(self, class_, target, *args, **kwargs): 111 def getOrCreateWidget(self, class_, target, *args, **kwargs):
97 """Get an existing widget or create a new one when necessary 112 """Get an existing widget or create a new one when necessary
98 113
99 If the widget is new, self.host.newWidget will be called with it. 114 If the widget is new, self.host.newWidget will be called with it.