# HG changeset patch # User Goffi # Date 1423251808 -3600 # Node ID f079e6ed1e69d1df44161afe4ea38ec83982e178 # Parent 9512590dc3d72ad784ca8deffcb5ba0c4973c01f quick frontend(quick widgets): added the ability to use a callable with getOrCreateWidget's on_existing_widget diff -r 9512590dc3d7 -r f079e6ed1e69 frontends/src/quick_frontend/quick_widgets.py --- a/frontends/src/quick_frontend/quick_widgets.py Fri Feb 06 20:09:01 2015 +0100 +++ b/frontends/src/quick_frontend/quick_widgets.py Fri Feb 06 20:43:28 2015 +0100 @@ -111,6 +111,7 @@ 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 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). @@ -173,6 +174,8 @@ assert on_new_widget is None else: # the widget already exists + if on_existing_widget == C.WIDGET_KEEP: + pass if on_existing_widget == C.WIDGET_RAISE: raise WidgetAlreadyExistsError(hash_) elif on_existing_widget == C.WIDGET_RECREATE: @@ -200,6 +203,11 @@ else: 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) + else: + raise exceptions.InternalError("Unexpected on_existing_widget value ({})".format(on_existing_widget)) + return widget def deleteWidget(self, widget_to_delete):