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.
This commit is contained in:
Goffi 2019-03-10 18:04:27 +01:00
commit 4ca9acadf9

View file

@ -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