diff frontends/src/quick_frontend/quick_widgets.py @ 1938:011eff37e21d

quick frontend, primitivus: quickContactList refactored to handle several profiles at once
author Goffi <goffi@goffi.org>
date Mon, 18 Apr 2016 18:31:13 +0200
parents 2daf7b4c6756
children 633b5c21aefd
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_widgets.py	Sun Apr 17 18:07:55 2016 +0200
+++ b/frontends/src/quick_frontend/quick_widgets.py	Mon Apr 18 18:31:13 2016 +0200
@@ -93,16 +93,20 @@
         else:
             return widgets_map.itervalues()
 
-    def getWidget(self, class_, target, profile):
+    def getWidget(self, class_, target=None, profiles=None):
         """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
+        @param profiles (unicode, iterable[unicode], None): profile(s) to use (may or may not be
+            used, depending of the widget class)
         @return: a class_ instance or None if the widget doesn't exist
         """
+        assert (target is not None) or (profiles is not None)
+        if profiles is not None and isinstance(profiles, unicode):
+            profiles = [profiles]
         class_ = self.getRealClass(class_)
-        hash_ = class_.getWidgetHash(target, profile)
+        hash_ = class_.getWidgetHash(target, profiles)
         try:
             return self._widgets[class_.__name__][hash_]
         except KeyError:
@@ -140,7 +144,7 @@
         if 'profiles' in _kwargs and 'profile' in _kwargs:
             raise ValueError("You can't have 'profile' and 'profiles' keys at the same time")
         try:
-            _kwargs['profiles'] = _kwargs.pop('profile')
+            _kwargs['profiles'] = [_kwargs.pop('profile')]
         except KeyError:
             if not 'profiles' in _kwargs:
                 _kwargs['profiles'] = None
@@ -266,7 +270,7 @@
             if not self.PROFILES_ALLOW_NONE:
                 raise ValueError("profiles can't have a value of None")
         else:
-            if not self.PROFILES_MULTIPLE:
+            if not self.PROFILES_MULTIPLE and len(profiles) != 1:
                 raise ValueError("multiple profiles are not allowed")
             for profile in profiles:
                 self.addProfile(profile)