comparison browser_side/xmlui.py @ 430:a927a98b398d

browser_side (xmlui): fix multi-selection
author souliane <souliane@mailoo.org>
date Thu, 03 Apr 2014 15:49:01 +0200
parents 9283f9e5e5dd
children d52f529a6d42
comparison
equal deleted inserted replaced
429:9283f9e5e5dd 430:a927a98b398d
152 152
153 class ListWidget(xmlui.ListWidget, ListBox): 153 class ListWidget(xmlui.ListWidget, ListBox):
154 154
155 def __init__(self, parent, options, selected, flags): 155 def __init__(self, parent, options, selected, flags):
156 ListBox.__init__(self) 156 ListBox.__init__(self)
157 self.setMultipleSelect('single' not in flags) 157 multi_selection = 'single' not in flags
158 self.setMultipleSelect(multi_selection)
159 if multi_selection:
160 self.setVisibleItemCount(5)
158 for option in options: 161 for option in options:
159 self.addItem(option[1]) 162 self.addItem(option[1])
160 self._xmlui_attr_map = {label: value for value, label in options} 163 self._xmlui_attr_map = {label: value for value, label in options}
161 self._xmluiSelectValues(selected) 164 self._xmluiSelectValues(selected)
162 165
183 self.addChangeListener(callback) 186 self.addChangeListener(callback)
184 187
185 def _xmluiAddValues(self, values, select=True): 188 def _xmluiAddValues(self, values, select=True):
186 selected = self._xmluiGetSelectedValues() 189 selected = self._xmluiGetSelectedValues()
187 for value in values: 190 for value in values:
188 self.addItem(value) 191 if value not in self._xmlui_attr_map.values():
189 self._xmlui_attr_map[value] = value 192 self.addItem(value)
193 self._xmlui_attr_map[value] = value
190 if value not in selected: 194 if value not in selected:
191 selected.append(value) 195 selected.append(value)
192 self._xmluiSelectValues(selected) 196 self._xmluiSelectValues(selected)
193 197
194 198