Mercurial > libervia-backend
comparison sat_frontends/quick_frontend/quick_widgets.py @ 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 |
parents | 6901a425d882 |
children | e3803ae89fbc |
comparison
equal
deleted
inserted
replaced
2854:eb9fa72eb62b | 2855:ef65dbce313b |
---|---|
91 | 91 |
92 This is a helper method which call getWidgets | 92 This is a helper method which call getWidgets |
93 @param widget(QuickWidget): retrieve instances of this widget | 93 @param widget(QuickWidget): retrieve instances of this widget |
94 @return: iterator on widgets | 94 @return: iterator on widgets |
95 """ | 95 """ |
96 try: | 96 return self.getWidgets(widget.__class__, widget.target, widget.profiles) |
97 target = widget.target | |
98 except AttributeError: | |
99 target = next(iter(widget.targets)) | |
100 return self.getWidgets(widget.__class__, target, widget.profiles) | |
101 | 97 |
102 def getWidgets(self, class_, target=None, profiles=None): | 98 def getWidgets(self, class_, target=None, profiles=None): |
103 """Get all subclassed widgets instances | 99 """Get all subclassed widgets instances |
104 | 100 |
105 @param class_: subclass of QuickWidget, same parameter as used in | 101 @param class_: subclass of QuickWidget, same parameter as used in |
323 .format(cls=class_, widget_hash=widget_hash)) | 319 .format(cls=class_, widget_hash=widget_hash)) |
324 | 320 |
325 | 321 |
326 class QuickWidget(object): | 322 class QuickWidget(object): |
327 """generic widget base""" | 323 """generic widget base""" |
324 # FIXME: sometime a single target is used, sometimes several ones | |
325 # This should be sorted out in the same way as for profiles: a single | |
326 # target should be possible when appropriate attribute is set. | |
327 # methods using target(s) and hash should be fixed accordingly | |
328 | 328 |
329 SINGLE = True # if True, there can be only one widget per target(s) | 329 SINGLE = True # if True, there can be only one widget per target(s) |
330 PROFILES_MULTIPLE = False # If True, this widget can handle several profiles at once | 330 PROFILES_MULTIPLE = False # If True, this widget can handle several profiles at once |
331 PROFILES_ALLOW_NONE = False # If True, this widget can be used without profile | 331 PROFILES_ALLOW_NONE = False # If True, this widget can be used without profile |
332 | 332 |
363 and not self.PROFILES_MULTIPLE | 363 and not self.PROFILES_MULTIPLE |
364 and not self.PROFILES_ALLOW_NONE | 364 and not self.PROFILES_ALLOW_NONE |
365 ) | 365 ) |
366 return list(self.profiles)[0] | 366 return list(self.profiles)[0] |
367 | 367 |
368 @property | |
369 def target(self): | |
370 """Return main target | |
371 | |
372 A random target is returned when several targets are available | |
373 """ | |
374 return next(iter(self.targets)) | |
375 | |
368 # synchronisation state | 376 # synchronisation state |
369 | 377 |
370 @property | 378 @property |
371 def sync(self): | 379 def sync(self): |
372 return self._sync | 380 return self._sync |