quick fronten (widgets): if a widget is recreated, "recreateArgs" method can be implemented to specify arguments to clone it correctly
This commit is contained in:
parent
f992739212
commit
2808312c77
1 changed files with 8 additions and 0 deletions
|
|
@ -150,6 +150,8 @@ class QuickWidgetsManager(object):
|
|||
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 @@ class QuickWidgetsManager(object):
|
|||
|
||||
# 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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue