comparison frontends/src/quick_frontend/quick_widgets.py @ 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 7f5e344938c1
children 8b37a62336c3
comparison
equal deleted inserted replaced
2061:748e539c5feb 2062:e22ab34c68f6
148 None: do nothing 148 None: do nothing
149 if 'on_existing_widget' is present it can have the following values: 149 if 'on_existing_widget' is present it can have the following values:
150 C.WIDGET_KEEP [default]: return the existing widget 150 C.WIDGET_KEEP [default]: return the existing widget
151 C.WIDGET_RAISE: raise WidgetAlreadyExistsError 151 C.WIDGET_RAISE: raise WidgetAlreadyExistsError
152 C.WIDGET_RECREATE: create a new widget *WITH A NEW HASH* 152 C.WIDGET_RECREATE: create a new widget *WITH A NEW HASH*
153 if the existing widget has a "recreateArgs" method, it will be called with args list and kwargs dict
154 so the values can be completed to create correctly the new instance
153 [callable]: this method will be called with existing widget as argument 155 [callable]: this method will be called with existing widget as argument
154 if 'force_hash' is present, the hash given in value will be used instead of the one returned by class_.getWidgetHash 156 if 'force_hash' is present, the hash given in value will be used instead of the one returned by class_.getWidgetHash
155 other keys will be used to instanciate class_ if the case happen (e.g. if type_ is present and class_ is a QuickChat subclass, 157 other keys will be used to instanciate class_ if the case happen (e.g. if type_ is present and class_ is a QuickChat subclass,
156 it will be used to create a new QuickChat instance). 158 it will be used to create a new QuickChat instance).
157 @return: a class_ instance, either new or already existing 159 @return: a class_ instance, either new or already existing
231 233
232 new_kwargs['on_new_widget'] = on_new_widget 234 new_kwargs['on_new_widget'] = on_new_widget
233 235
234 # XXX: keep up-to-date if new special kwargs are added (i.e.: delete these keys here) 236 # XXX: keep up-to-date if new special kwargs are added (i.e.: delete these keys here)
235 new_kwargs['on_existing_widget'] = C.WIDGET_RAISE 237 new_kwargs['on_existing_widget'] = C.WIDGET_RAISE
238 try:
239 recreateArgs = widget.recreateArgs
240 except AttributeError:
241 pass
242 else:
243 recreateArgs(args, new_kwargs)
236 hash_idx = 1 244 hash_idx = 1
237 while True: 245 while True:
238 new_kwargs['force_hash'] = "{}{}{}".format(hash_, NEW_INSTANCE_SUFF, hash_idx) 246 new_kwargs['force_hash'] = "{}{}{}".format(hash_, NEW_INSTANCE_SUFF, hash_idx)
239 try: 247 try:
240 widget = self.getOrCreateWidget(class_, target, *args, **new_kwargs) 248 widget = self.getOrCreateWidget(class_, target, *args, **new_kwargs)