# HG changeset patch # User Goffi # Date 1581532712 -3600 # Node ID 7699a08ba8fb798d740cca18746fa29cc761faf7 # Parent 9dc170635bee27a7d73c406833c8e79a97614850 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. diff -r 9dc170635bee -r 7699a08ba8fb sat_frontends/quick_frontend/quick_widgets.py --- a/sat_frontends/quick_frontend/quick_widgets.py Mon Feb 10 22:02:31 2020 +0100 +++ b/sat_frontends/quick_frontend/quick_widgets.py Wed Feb 12 19:38:32 2020 +0100 @@ -95,7 +95,7 @@ """ 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 @@ 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 @@ 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.