Mercurial > libervia-backend
changeset 1312:9e904f8a094e frontends_multi_profiles
quick_frontend: getOrCreateWidget callbacks can return another widget
author | souliane <souliane@mailoo.org> |
---|---|
date | Mon, 09 Feb 2015 09:19:30 +0100 (2015-02-09) |
parents | 4895e1e092fb |
children | 3012c2f15dae |
files | frontends/src/quick_frontend/quick_widgets.py |
diffstat | 1 files changed, 11 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_widgets.py Sat Feb 07 14:47:23 2015 +0100 +++ b/frontends/src/quick_frontend/quick_widgets.py Mon Feb 09 09:19:30 2015 +0100 @@ -100,18 +100,20 @@ @param class_(class): class of the widget to create @param target: target depending of the widget, usually a JID instance @param args(list): optional args to create a new instance of class_ - @param kwargs(list): optional kwargs to create anew instance of class_ + @param kwargs(dict): optional kwargs to create a new instance of class_ if 'profile' key is present, it will be popped and put in 'profiles' if there is neither 'profile' nor 'profiles', None will be used for 'profiles' if 'on_new_widget' is present it can have the following values: C.WIDGET_NEW [default]: self.host.newWidget will be called on widget creation - [callable]: this method will be called instead of self.host.newWidget + [callable]: this method will be called instead of self.host.newWidget, + and can return another widget to modify the result of the present method None: do nothing if 'on_existing_widget' is present it can have the following values: C.WIDGET_KEEP [default]: return the existing widget C.WIDGET_RAISE: raise WidgetAlreadyExistsError C.WIDGET_RECREATE: create a new widget *WITH A NEW HASH* - [callable]: this method will be called with existing widget as argument + [callable]: this method will be called with existing widget as argument, + and can return another widget to modify the result of the present method if 'force_hash' is present, the hash given in value will be used instead of the one returned by class_.getWidgetHash other keys will be used to instanciate class_ if the case happen (e.g. if type_ is present and class_ is a QuickChat subclass, it will be used to create a new QuickChat instance). @@ -169,7 +171,9 @@ if on_new_widget == C.WIDGET_NEW: self.host.newWidget(widget) elif callable(on_new_widget): - on_new_widget(widget) + result = on_new_widget(widget) + if isinstance(result, QuickWidget): + widget = result else: assert on_new_widget is None else: @@ -204,7 +208,9 @@ log.debug(u"Widget already exists, a new one has been recreated with hash {}".format(new_kwargs['force_hash'])) break elif callable(on_existing_widget): - on_existing_widget(widget) + result = on_existing_widget(widget) + if isinstance(result, QuickWidget): + widget = result else: raise exceptions.InternalError("Unexpected on_existing_widget value ({})".format(on_existing_widget))