comparison sat/tools/common/template_xmlui.py @ 3546:185601bc0cd3

tools (common/template_xmlui: add `multi` and `value` propertied to OptionsWidget
author Goffi <goffi@goffi.org>
date Fri, 04 Jun 2021 14:44:33 +0200
parents be6d91572633
children 524856bd7b19
comparison
equal deleted inserted replaced
3545:31cbcdd096a2 3546:185601bc0cd3
88 def values(self): 88 def values(self):
89 for value, label in self.items: 89 for value, label in self.items:
90 yield value 90 yield value
91 91
92 @property 92 @property
93 def value(self):
94 if self.multi or self.no_select or len(self.selected) != 1:
95 raise ValueError(
96 "Can't get value for list with multiple selections or nothing selected"
97 )
98 return self.selected[0]
99
100 @property
93 def labels(self): 101 def labels(self):
94 """return only labels from self.items""" 102 """return only labels from self.items"""
95 for value, label in self.items: 103 for value, label in self.items:
96 yield label 104 yield label
97 105
109 117
110 @property 118 @property
111 def no_select(self): 119 def no_select(self):
112 return "noselect" in self.style 120 return "noselect" in self.style
113 121
122 @property
123 def multi(self):
124 return "multi" in self.style
125
114 126
115 class EmptyWidget(xmlui.EmptyWidget, Widget): 127 class EmptyWidget(xmlui.EmptyWidget, Widget):
116 def __init__(self, _xmlui_parent): 128 def __init__(self, _xmlui_parent):
117 Widget.__init__(self) 129 Widget.__init__(self)
118 130