# HG changeset patch # User souliane # Date 1396529345 -7200 # Node ID 68faf7d77a427151cf37a2e40ae4b0bc87dd383a # Parent b37b1d183ac3719314236af62a5175da2ae3b734 frontends (xmlui): add setter methods + fixes: - add _xmluiSetValue for all widgets + _xmluiAddValues for ListWidget - fix popup dialog OK button + _xmluiOnClick for ButtonWidget diff -r b37b1d183ac3 -r 68faf7d77a42 frontends/src/primitivus/xmlui.py --- a/frontends/src/primitivus/xmlui.py Thu Apr 03 14:38:48 2014 +0200 +++ b/frontends/src/primitivus/xmlui.py Thu Apr 03 14:49:05 2014 +0200 @@ -19,6 +19,7 @@ from sat.core.i18n import _ import urwid +import copy from urwid_satext import sat_widgets from logging import debug, info, warning, error from xml.dom import minidom @@ -78,11 +79,15 @@ urwid.Divider.__init__(self, div_char) + class PrimitivusStringWidget(xmlui.StringWidget, sat_widgets.AdvancedEdit, PrimitivusEvents): def __init__(self, parent, value): sat_widgets.AdvancedEdit.__init__(self, edit_text=value) + def _xmluiSetValue(self, value): + self.set_edit_text(value) + def _xmluiGetValue(self): return self.get_edit_text() @@ -92,6 +97,9 @@ def __init__(self, parent, value): sat_widgets.Password.__init__(self, edit_text=value) + def _xmluiSetValue(self, value): + self.set_edit_text(value) + def _xmluiGetValue(self): return self.get_edit_text() @@ -101,6 +109,9 @@ def __init__(self, parent, value): sat_widgets.AdvancedEdit.__init__(self, edit_text=value, multiline=True) + def _xmluiSetValue(self, value): + self.set_edit_text(value) + def _xmluiGetValue(self): return self.get_edit_text() @@ -110,6 +121,9 @@ def __init__(self, parent, state): urwid.CheckBox.__init__(self, '', state=state) + def _xmluiSetValue(self, value): + self.set_state(value == "true") + def _xmluiGetValue(self): return "true" if self.get_state() else "false" @@ -119,6 +133,9 @@ def __init__(self, parent, value, click_callback): sat_widgets.CustomButton.__init__(self, value, on_press=click_callback) + def _xmluiOnClick(self, callback): + urwid.connect_signal(self, 'click', callback) + class PrimitivusListWidget(xmlui.ListWidget, sat_widgets.List, PrimitivusEvents): @@ -135,6 +152,21 @@ def _xmluiGetSelectedValues(self): return [option.value for option in self.getSelectedValues()] + def _xmluiAddValues(self, values, select=True): + current_values = self.getAllValues() + new_values = copy.deepcopy(current_values) + for value in values: + if value not in current_values: + new_values.append(value) + if select: + selected = self._xmluiGetSelectedValues() + self.changeValues(new_values) + if select: + for value in values: + if value not in selected: + selected.append(value) + self._xmluiSelectValues(selected) + class PrimitivusAdvancedListContainer(xmlui.AdvancedListContainer, sat_widgets.TableContainer, PrimitivusEvents): @@ -160,6 +192,7 @@ """ Call callback with widget as only argument """ urwid.connect_signal(self, 'click', self._event_callback, callback) + class PrimitivusPairsContainer(xmlui.PairsContainer, sat_widgets.TableContainer): def __init__(self, parent): @@ -233,13 +266,16 @@ def postTreat(): assert self.main_cont.body - if self.type == 'form': + if self.type in ('form', 'popup'): buttons = [] - buttons.append(urwid.Button(_('Submit'),self.onFormSubmitted)) - if not 'NO_CANCEL' in self.flags: - buttons.append(urwid.Button(_('Cancel'),self.onFormCancelled)) + if self.type == 'form': + buttons.append(urwid.Button(_('Submit'), self.onFormSubmitted)) + if not 'NO_CANCEL' in self.flags: + buttons.append(urwid.Button(_('Cancel'), self.onFormCancelled)) + else: + buttons.append(urwid.Button(_('OK'), lambda dummy: self._xmluiClose())) max_len = max([len(button.get_label()) for button in buttons]) - grid_wid = urwid.GridFlow(buttons,max_len+4,1,0,'center') + grid_wid = urwid.GridFlow(buttons, max_len + 4, 1, 0, 'center') self.main_cont.body.append(grid_wid) elif self.type == 'param': tabs_cont = self.main_cont.body[0].base_widget diff -r b37b1d183ac3 -r 68faf7d77a42 frontends/src/wix/xmlui.py --- a/frontends/src/wix/xmlui.py Thu Apr 03 14:38:48 2014 +0200 +++ b/frontends/src/wix/xmlui.py Thu Apr 03 14:49:05 2014 +0200 @@ -42,6 +42,10 @@ class ValueWidget(WixWidget): + + def _xmluiSetValue(self, value): + self.SetValue(value) + def _xmluiGetValue(self): return self.GetValue() @@ -106,6 +110,9 @@ self.SetValue(state) self._xmlui_proportion = 1 + def _xmluiSetValue(self, value): + self.SetValue(value == 'true') + def _xmluiGetValue(self): return "true" if self.GetValue() else "false" @@ -117,10 +124,10 @@ wx.Button.__init__(self, parent, -1, value) self._xmlui_click_callback = click_callback parent.Bind(wx.EVT_BUTTON, lambda evt: click_callback(evt.GetEventObject()), self) + self.parent = parent - def _xmluiOnClick(self, event): - self._xmlui_click_callback(event.GetEventObject()) - event.Skip() + def _xmluiOnClick(self, callback): + self.parent.Bind(wx.EVT_BUTTON, lambda evt: callback(evt.GetEventObject()), self) class ListWidget(EventWidget, WixWidget, xmlui.ListWidget, wx.ListBox): @@ -143,8 +150,9 @@ self.SetSelection(idx, self.GetString(idx) == label) def _xmluiSelectValues(self, values): - for value in values: - self._xmluiSelectValue(value) + labels = [label for label, _value in self._xmlui_attr_map.items() if _value in values] + for idx in xrange(self.GetCount()): + self.SetSelection(idx, self.GetString(idx) in labels) def _xmluiGetSelectedValues(self): ret = [] @@ -153,6 +161,16 @@ ret.append(self._xmlui_attr_map[label]) return ret + def _xmluiAddValues(self, values, select=True): + selected = self._xmluiGetSelectedValues() + for value in values: + if value not in self._xmlui_attr_map.values(): + wx.ListBox.Append(self, value) + self._xmlui_attr_map[value] = value + if value not in selected: + selected.append(value) + self._xmluiSelectValues(selected) + class WixContainer(object): _xmlui_proportion = 1