Mercurial > libervia-backend
comparison frontends/src/quick_frontend/quick_widgets.py @ 1322:1f13a837e4b2 frontends_multi_profiles
quick_frontend (quick_widgets): revert commit 1319
author | souliane <souliane@mailoo.org> |
---|---|
date | Tue, 10 Feb 2015 10:33:54 +0100 |
parents | e9888db0eb0c |
children | 273b044fde6d |
comparison
equal
deleted
inserted
replaced
1321:e9888db0eb0c | 1322:1f13a837e4b2 |
---|---|
103 @param kwargs(dict): optional kwargs to create a new instance of class_ | 103 @param kwargs(dict): optional kwargs to create a new instance of class_ |
104 if 'profile' key is present, it will be popped and put in 'profiles' | 104 if 'profile' key is present, it will be popped and put in 'profiles' |
105 if there is neither 'profile' nor 'profiles', None will be used for 'profiles' | 105 if there is neither 'profile' nor 'profiles', None will be used for 'profiles' |
106 if 'on_new_widget' is present it can have the following values: | 106 if 'on_new_widget' is present it can have the following values: |
107 C.WIDGET_NEW [default]: self.host.newWidget will be called on widget creation | 107 C.WIDGET_NEW [default]: self.host.newWidget will be called on widget creation |
108 [callable]: this method will be called instead of self.host.newWidget, | 108 [callable]: this method will be called instead of self.host.newWidget |
109 and can return another widget to modify the result of the present method | |
110 None: do nothing | 109 None: do nothing |
111 if 'on_existing_widget' is present it can have the following values: | 110 if 'on_existing_widget' is present it can have the following values: |
112 C.WIDGET_KEEP [default]: return the existing widget | 111 C.WIDGET_KEEP [default]: return the existing widget |
113 C.WIDGET_RAISE: raise WidgetAlreadyExistsError | 112 C.WIDGET_RAISE: raise WidgetAlreadyExistsError |
114 C.WIDGET_RECREATE: create a new widget *WITH A NEW HASH* | 113 C.WIDGET_RECREATE: create a new widget *WITH A NEW HASH* |
115 [callable]: this method will be called with existing widget as argument, | 114 [callable]: this method will be called with existing widget as argument |
116 and can return another widget to modify the result of the present method | |
117 if 'force_hash' is present, the hash given in value will be used instead of the one returned by class_.getWidgetHash | 115 if 'force_hash' is present, the hash given in value will be used instead of the one returned by class_.getWidgetHash |
118 other keys will be used to instanciate class_ if the case happen (e.g. if type_ is present and class_ is a QuickChat subclass, | 116 other keys will be used to instanciate class_ if the case happen (e.g. if type_ is present and class_ is a QuickChat subclass, |
119 it will be used to create a new QuickChat instance). | 117 it will be used to create a new QuickChat instance). |
120 @return: a class_ instance, either new or already existing | 118 @return: a class_ instance, either new or already existing |
121 """ | 119 """ |
169 widgets_map[hash_] = widget | 167 widgets_map[hash_] = widget |
170 | 168 |
171 if on_new_widget == C.WIDGET_NEW: | 169 if on_new_widget == C.WIDGET_NEW: |
172 self.host.newWidget(widget) | 170 self.host.newWidget(widget) |
173 elif callable(on_new_widget): | 171 elif callable(on_new_widget): |
174 result = on_new_widget(widget) | 172 on_new_widget(widget) |
175 if isinstance(result, QuickWidget): | |
176 widget = result | |
177 else: | 173 else: |
178 assert on_new_widget is None | 174 assert on_new_widget is None |
179 else: | 175 else: |
180 # the widget already exists | 176 # the widget already exists |
181 if on_existing_widget == C.WIDGET_KEEP: | 177 if on_existing_widget == C.WIDGET_KEEP: |
205 hash_idx += 1 | 201 hash_idx += 1 |
206 else: | 202 else: |
207 log.debug(u"Widget already exists, a new one has been recreated with hash {}".format(new_kwargs['force_hash'])) | 203 log.debug(u"Widget already exists, a new one has been recreated with hash {}".format(new_kwargs['force_hash'])) |
208 break | 204 break |
209 elif callable(on_existing_widget): | 205 elif callable(on_existing_widget): |
210 result = on_existing_widget(widget) | 206 on_existing_widget(widget) |
211 if isinstance(result, QuickWidget): | |
212 widget = result | |
213 else: | 207 else: |
214 raise exceptions.InternalError("Unexpected on_existing_widget value ({})".format(on_existing_widget)) | 208 raise exceptions.InternalError("Unexpected on_existing_widget value ({})".format(on_existing_widget)) |
215 | 209 |
216 return widget | 210 return widget |
217 | 211 |