Mercurial > libervia-backend
diff sat_frontends/quick_frontend/quick_widgets.py @ 3115:3018d153a615
quick frontend (widgets): some more errors handling in getOrCreateWidget
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 17 Jan 2020 18:47:02 +0100 |
parents | 060ac43627fc |
children | 328a6cea3802 |
line wrap: on
line diff
--- a/sat_frontends/quick_frontend/quick_widgets.py Fri Jan 17 17:55:57 2020 +0100 +++ b/sat_frontends/quick_frontend/quick_widgets.py Fri Jan 17 18:47:02 2020 +0100 @@ -255,6 +255,10 @@ if widget is None: raise exceptions.InternalError( "on_existing_widget method must return the widget to use") + if widget not in widgets_map[hash_]: + log.debug( + "the widget returned by on_existing_widget is new, adding it") + widgets_map[hash_].append(widget) else: raise exceptions.InternalError( "Unexpected on_existing_widget value ({})".format(on_existing_widget)) @@ -299,7 +303,11 @@ return widget_hash = str(class_.getWidgetHash(widget_to_delete.target, widget_to_delete.profiles)) - widget_instances = widgets_map[widget_hash] + try: + widget_instances = widgets_map[widget_hash] + except KeyError: + log.error(f"no instance of {class_.__name__} found with hash {widget_hash!r}") + return if all_instances: widget_instances.clear() else: @@ -315,7 +323,7 @@ # all instances with this hash have been deleted # we remove the hash itself del widgets_map[widget_hash] - log.debug("All instances of {cls} with hash {widget_hash} have been deleted" + log.debug("All instances of {cls} with hash {widget_hash!r} have been deleted" .format(cls=class_, widget_hash=widget_hash))