Mercurial > libervia-backend
comparison frontends/src/primitivus/xmlui.py @ 1478:90130847a0a8
frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 20 Aug 2015 18:36:53 +0200 |
parents | 675e0e9f1653 |
children | a77217511afd |
comparison
equal
deleted
inserted
replaced
1477:ac522c4dab0e | 1478:90130847a0a8 |
---|---|
215 for value in values: | 215 for value in values: |
216 if value not in selected: | 216 if value not in selected: |
217 selected.append(value) | 217 selected.append(value) |
218 self._xmluiSelectValues(selected) | 218 self._xmluiSelectValues(selected) |
219 | 219 |
220 class PrimitivusJidsListWidget(xmlui.ListWidget, sat_widgets.List, PrimitivusEvents): | |
221 | |
222 def __init__(self, _xmlui_parent, jids, styles): | |
223 sat_widgets.List.__init__(self, options=jids+[''], # the empty field is here to add new jids if needed | |
224 option_type=lambda txt, align: sat_widgets.AdvancedEdit(edit_text=txt, align=align), | |
225 on_change=self._onChange) | |
226 self.delete=0 | |
227 | |
228 def _onChange(self, list_widget, jid_widget=None, text=None): | |
229 if jid_widget is not None: | |
230 if jid_widget != list_widget.contents[-1] and not text: | |
231 # if a field is empty, we delete the line (except for the last line) | |
232 list_widget.contents.remove(jid_widget) | |
233 elif jid_widget == list_widget.contents[-1] and text: | |
234 # we always want an empty field as last value to be able to add jids | |
235 list_widget.contents.append(sat_widgets.AdvancedEdit()) | |
236 | |
237 def _xmluiGetSelectedValues(self): | |
238 # XXX: there is not selection in this list, so we return all non empty values | |
239 return [jid_ for jid_ in self.getAllValues() if jid_] | |
240 | |
220 | 241 |
221 class PrimitivusAdvancedListContainer(xmlui.AdvancedListContainer, sat_widgets.TableContainer, PrimitivusEvents): | 242 class PrimitivusAdvancedListContainer(xmlui.AdvancedListContainer, sat_widgets.TableContainer, PrimitivusEvents): |
222 | 243 |
223 def __init__(self, _xmlui_parent, columns, selectable='no'): | 244 def __init__(self, _xmlui_parent, columns, selectable='no'): |
224 options = {'ADAPT':()} | 245 options = {'ADAPT':()} |
384 max_len = max([len(button.get_label()) for button in buttons]) | 405 max_len = max([len(button.get_label()) for button in buttons]) |
385 grid_wid = urwid.GridFlow(buttons, max_len + 4, 1, 0, 'center') | 406 grid_wid = urwid.GridFlow(buttons, max_len + 4, 1, 0, 'center') |
386 self.main_cont.body.append(grid_wid) | 407 self.main_cont.body.append(grid_wid) |
387 elif self.type == 'param': | 408 elif self.type == 'param': |
388 tabs_cont = self.main_cont.body[0].base_widget | 409 tabs_cont = self.main_cont.body[0].base_widget |
389 assert(isinstance(tabs_cont,sat_widgets.TabsContainer)) | 410 assert isinstance(tabs_cont,sat_widgets.TabsContainer) |
390 buttons = [] | 411 buttons = [] |
391 buttons.append(sat_widgets.CustomButton(_('Save'),self.onSaveParams)) | 412 buttons.append(sat_widgets.CustomButton(_('Save'),self.onSaveParams)) |
392 buttons.append(sat_widgets.CustomButton(_('Cancel'),lambda x:self.host.removeWindow())) | 413 buttons.append(sat_widgets.CustomButton(_('Cancel'),lambda x:self.host.removeWindow())) |
393 max_len = max([button.getSize() for button in buttons]) | 414 max_len = max([button.getSize() for button in buttons]) |
394 grid_wid = urwid.GridFlow(buttons,max_len,1,0,'center') | 415 grid_wid = urwid.GridFlow(buttons,max_len,1,0,'center') |
420 if show_type == 'popup': | 441 if show_type == 'popup': |
421 self.host.showPopUp(self, valign=valign) | 442 self.host.showPopUp(self, valign=valign) |
422 elif show_type == 'window': | 443 elif show_type == 'window': |
423 self.host.newWidget(self) | 444 self.host.newWidget(self) |
424 else: | 445 else: |
425 assert(False) | 446 assert False |
426 self.host.redraw() | 447 self.host.redraw() |
427 | 448 |
428 def _xmluiClose(self): | 449 def _xmluiClose(self): |
429 if self._dest == 'window': | 450 if self._dest == 'window': |
430 self.host.removeWindow() | 451 self.host.removeWindow() |