changeset 2855:ef65dbce313b

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.
author Goffi <goffi@goffi.org>
date Sun, 10 Mar 2019 18:04:27 +0100 (2019-03-10)
parents eb9fa72eb62b
children 26d6ac4e4a66
files sat_frontends/quick_frontend/quick_widgets.py
diffstat 1 files changed, 13 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/sat_frontends/quick_frontend/quick_widgets.py	Sun Mar 10 18:04:01 2019 +0100
+++ b/sat_frontends/quick_frontend/quick_widgets.py	Sun Mar 10 18:04:27 2019 +0100
@@ -93,11 +93,7 @@
         @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 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 @@
         )
         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