From e8aaa9fd43bce206d69740b9205948f200a44c72 Mon Sep 17 00:00:00 2001 From: Goffi Date: Wed, 12 Feb 2020 19:38:32 +0100 Subject: [PATCH] quick frontend(widget): added `with_duplicates` argument to getWidgets: when this argument is False, widgets with the same widget_hash are filtered to only return first one. It is True by default to keep former behaviour. --- sat_frontends/quick_frontend/quick_widgets.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/sat_frontends/quick_frontend/quick_widgets.py b/sat_frontends/quick_frontend/quick_widgets.py index bec95073..d6b7cabe 100644 --- a/sat_frontends/quick_frontend/quick_widgets.py +++ b/sat_frontends/quick_frontend/quick_widgets.py @@ -95,7 +95,7 @@ class QuickWidgetsManager(object): """ return self.getWidgets(widget.__class__, widget.target, widget.profiles) - def getWidgets(self, class_, target=None, profiles=None): + def getWidgets(self, class_, target=None, profiles=None, with_duplicates=True): """Get all subclassed widgets instances @param class_: subclass of QuickWidget, same parameter as used in @@ -105,6 +105,8 @@ class QuickWidgetsManager(object): recreated widgets are handled @param profiles(iterable, None): if not None, filter on instances linked to these profiles + @param with_duplicates(bool): if False, only first widget with a given hash is + returned @return: iterator on widgets """ class_ = self.getRealClass(class_) @@ -120,10 +122,16 @@ class QuickWidgetsManager(object): if filter_hash is not None: for widget in widgets_map.get(filter_hash, []): yield widget + if not with_duplicates: + return else: for widget_instances in widgets_map.values(): for widget in widget_instances: yield widget + if not with_duplicates: + # widgets are set by hashes, so if don't want duplicates + # we only return the first widget of the list + break def getWidget(self, class_, target=None, profiles=None): """Get a widget without creating it if it doesn't exist.