From 4ca9acadf90502506c9fa0a9c77528f1acae74d0 Mon Sep 17 00:00:00 2001 From: Goffi Date: Sun, 10 Mar 2019 18:04:27 +0100 Subject: [PATCH] quick frontend(widgets): added QuickWidget.target property as a helper method to get a single target: a single target is the most common case, but QuickWidget handle multiple targets. When a single target is requested and multiple exist, a random one is returned. This is a temporary situation, targetting should be improved in a future version to manage multiple targets in hash. --- sat_frontends/quick_frontend/quick_widgets.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/sat_frontends/quick_frontend/quick_widgets.py b/sat_frontends/quick_frontend/quick_widgets.py index a7171ea1..0cdd74c6 100644 --- a/sat_frontends/quick_frontend/quick_widgets.py +++ b/sat_frontends/quick_frontend/quick_widgets.py @@ -93,11 +93,7 @@ class QuickWidgetsManager(object): @param widget(QuickWidget): retrieve instances of this widget @return: iterator on widgets """ - try: - target = widget.target - except AttributeError: - target = next(iter(widget.targets)) - return self.getWidgets(widget.__class__, target, widget.profiles) + return self.getWidgets(widget.__class__, widget.target, widget.profiles) def getWidgets(self, class_, target=None, profiles=None): """Get all subclassed widgets instances @@ -325,6 +321,10 @@ class QuickWidgetsManager(object): class QuickWidget(object): """generic widget base""" + # FIXME: sometime a single target is used, sometimes several ones + # This should be sorted out in the same way as for profiles: a single + # target should be possible when appropriate attribute is set. + # methods using target(s) and hash should be fixed accordingly SINGLE = True # if True, there can be only one widget per target(s) PROFILES_MULTIPLE = False # If True, this widget can handle several profiles at once @@ -365,6 +365,14 @@ class QuickWidget(object): ) return list(self.profiles)[0] + @property + def target(self): + """Return main target + + A random target is returned when several targets are available + """ + return next(iter(self.targets)) + # synchronisation state @property