# HG changeset patch # User Goffi # Date 1473458073 -7200 # Node ID e22ab34c68f63fb24c3a3fa6e9f0defbec1427d7 # Parent 748e539c5feb1b94531853e75abb00ff16821649 quick fronten (widgets): if a widget is recreated, "recreateArgs" method can be implemented to specify arguments to clone it correctly diff -r 748e539c5feb -r e22ab34c68f6 frontends/src/quick_frontend/quick_widgets.py --- a/frontends/src/quick_frontend/quick_widgets.py Fri Sep 09 23:54:33 2016 +0200 +++ b/frontends/src/quick_frontend/quick_widgets.py Fri Sep 09 23:54:33 2016 +0200 @@ -150,6 +150,8 @@ C.WIDGET_KEEP [default]: return the existing widget C.WIDGET_RAISE: raise WidgetAlreadyExistsError C.WIDGET_RECREATE: create a new widget *WITH A NEW HASH* + if the existing widget has a "recreateArgs" method, it will be called with args list and kwargs dict + so the values can be completed to create correctly the new instance [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, @@ -233,6 +235,12 @@ # XXX: keep up-to-date if new special kwargs are added (i.e.: delete these keys here) new_kwargs['on_existing_widget'] = C.WIDGET_RAISE + try: + recreateArgs = widget.recreateArgs + except AttributeError: + pass + else: + recreateArgs(args, new_kwargs) hash_idx = 1 while True: new_kwargs['force_hash'] = "{}{}{}".format(hash_, NEW_INSTANCE_SUFF, hash_idx)