# HG changeset patch # User Goffi # Date 1552237467 -3600 # Node ID ef65dbce313bfe13ff116f567a48c29aa960b837 # Parent eb9fa72eb62bdb83e1be5f8af7f263da986a3125 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. diff -r eb9fa72eb62b -r ef65dbce313b sat_frontends/quick_frontend/quick_widgets.py --- 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