Mercurial > libervia-backend
comparison frontends/src/wix/xmlui.py @ 968:75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
- we need to update urwid_satext to revision 79
- no more "value" attribute value in the "list" element, use
HTML-style "select" attribute in the "option" elements instead
- /!\ param saving do not handle multiple values yet!
author | souliane <souliane@mailoo.org> |
---|---|
date | Tue, 01 Apr 2014 21:21:13 +0200 |
parents | 3ee2ec7ec010 |
children | 5c7707c958d8 |
comparison
equal
deleted
inserted
replaced
967:242bd4fc654c | 968:75f3b3b430ff |
---|---|
120 | 120 |
121 def _xmluiOnClick(self, event): | 121 def _xmluiOnClick(self, event): |
122 self._xmlui_click_callback(event.GetEventObject()) | 122 self._xmlui_click_callback(event.GetEventObject()) |
123 event.Skip() | 123 event.Skip() |
124 | 124 |
125 | |
125 class ListWidget(EventWidget, WixWidget, xmlui.ListWidget, wx.ListBox): | 126 class ListWidget(EventWidget, WixWidget, xmlui.ListWidget, wx.ListBox): |
126 _xmlui_change_event = wx.EVT_LISTBOX | 127 _xmlui_change_event = wx.EVT_LISTBOX |
127 | 128 |
128 def __init__(self, parent, options, flags): | 129 def __init__(self, parent, options, selected, flags): |
129 styles = wx.LB_MULTIPLE if not 'single' in flags else wx.LB_SINGLE | 130 styles = wx.LB_MULTIPLE if not 'single' in flags else wx.LB_SINGLE |
130 wx.ListBox.__init__(self, parent, -1, choices=[option[1] for option in options], style=styles) | 131 wx.ListBox.__init__(self, parent, -1, choices=[option[1] for option in options], style=styles) |
131 self._xmlui_attr_map = {label: value for value, label in options} | 132 self._xmlui_attr_map = {label: value for value, label in options} |
132 self._xmlui_proportion = 1 | 133 self._xmlui_proportion = 1 |
134 self._xmluiSelectValues(selected) | |
133 | 135 |
134 def _xmluiSelectValue(self, value): | 136 def _xmluiSelectValue(self, value): |
135 try: | 137 try: |
136 label = [label for label, _value in self._xmlui_attr_map.items() if _value == value][0] | 138 label = [label for label, _value in self._xmlui_attr_map.items() if _value == value][0] |
137 except IndexError: | 139 except IndexError: |
138 warning(_("Can't find value [%s] to select" % value)) | 140 warning(_("Can't find value [%s] to select" % value)) |
139 return | 141 return |
140 for idx in xrange(self.GetCount()): | 142 for idx in xrange(self.GetCount()): |
141 self.SetSelection(idx, self.GetString(idx) == label) | 143 self.SetSelection(idx, self.GetString(idx) == label) |
144 | |
145 def _xmluiSelectValues(self, values): | |
146 for value in values: | |
147 self._xmluiSelectValue(value) | |
142 | 148 |
143 def _xmluiGetSelectedValues(self): | 149 def _xmluiGetSelectedValues(self): |
144 ret = [] | 150 ret = [] |
145 labels = [self.GetString(idx) for idx in self.GetSelections()] | 151 labels = [self.GetString(idx) for idx in self.GetSelections()] |
146 for label in labels: | 152 for label in labels: |