changeset 2062:e22ab34c68f6

quick fronten (widgets): if a widget is recreated, "recreateArgs" method can be implemented to specify arguments to clone it correctly
author Goffi <goffi@goffi.org>
date Fri, 09 Sep 2016 23:54:33 +0200
parents 748e539c5feb
children 8fa0d95c2142
files frontends/src/quick_frontend/quick_widgets.py
diffstat 1 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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)