comparison frontends/src/wix/xmlui.py @ 976:68faf7d77a42

frontends (xmlui): add setter methods + fixes: - add _xmluiSetValue for all widgets + _xmluiAddValues for ListWidget - fix popup dialog OK button + _xmluiOnClick for ButtonWidget
author souliane <souliane@mailoo.org>
date Thu, 03 Apr 2014 14:49:05 +0200
parents b37b1d183ac3
children 5a6354ff468c
comparison
equal deleted inserted replaced
975:b37b1d183ac3 976:68faf7d77a42
40 class WixWidget(object): 40 class WixWidget(object):
41 _xmlui_proportion = 0 41 _xmlui_proportion = 0
42 42
43 43
44 class ValueWidget(WixWidget): 44 class ValueWidget(WixWidget):
45
46 def _xmluiSetValue(self, value):
47 self.SetValue(value)
48
45 def _xmluiGetValue(self): 49 def _xmluiGetValue(self):
46 return self.GetValue() 50 return self.GetValue()
47 51
48 52
49 class EmptyWidget(WixWidget, xmlui.EmptyWidget, wx.Window): 53 class EmptyWidget(WixWidget, xmlui.EmptyWidget, wx.Window):
103 107
104 def __init__(self, parent, state): 108 def __init__(self, parent, state):
105 wx.CheckBox.__init__(self, parent, -1, "", style=wx.CHK_2STATE) 109 wx.CheckBox.__init__(self, parent, -1, "", style=wx.CHK_2STATE)
106 self.SetValue(state) 110 self.SetValue(state)
107 self._xmlui_proportion = 1 111 self._xmlui_proportion = 1
112
113 def _xmluiSetValue(self, value):
114 self.SetValue(value == 'true')
108 115
109 def _xmluiGetValue(self): 116 def _xmluiGetValue(self):
110 return "true" if self.GetValue() else "false" 117 return "true" if self.GetValue() else "false"
111 118
112 119
115 122
116 def __init__(self, parent, value, click_callback): 123 def __init__(self, parent, value, click_callback):
117 wx.Button.__init__(self, parent, -1, value) 124 wx.Button.__init__(self, parent, -1, value)
118 self._xmlui_click_callback = click_callback 125 self._xmlui_click_callback = click_callback
119 parent.Bind(wx.EVT_BUTTON, lambda evt: click_callback(evt.GetEventObject()), self) 126 parent.Bind(wx.EVT_BUTTON, lambda evt: click_callback(evt.GetEventObject()), self)
120 127 self.parent = parent
121 def _xmluiOnClick(self, event): 128
122 self._xmlui_click_callback(event.GetEventObject()) 129 def _xmluiOnClick(self, callback):
123 event.Skip() 130 self.parent.Bind(wx.EVT_BUTTON, lambda evt: callback(evt.GetEventObject()), self)
124 131
125 132
126 class ListWidget(EventWidget, WixWidget, xmlui.ListWidget, wx.ListBox): 133 class ListWidget(EventWidget, WixWidget, xmlui.ListWidget, wx.ListBox):
127 _xmlui_change_event = wx.EVT_LISTBOX 134 _xmlui_change_event = wx.EVT_LISTBOX
128 135
141 return 148 return
142 for idx in xrange(self.GetCount()): 149 for idx in xrange(self.GetCount()):
143 self.SetSelection(idx, self.GetString(idx) == label) 150 self.SetSelection(idx, self.GetString(idx) == label)
144 151
145 def _xmluiSelectValues(self, values): 152 def _xmluiSelectValues(self, values):
146 for value in values: 153 labels = [label for label, _value in self._xmlui_attr_map.items() if _value in values]
147 self._xmluiSelectValue(value) 154 for idx in xrange(self.GetCount()):
155 self.SetSelection(idx, self.GetString(idx) in labels)
148 156
149 def _xmluiGetSelectedValues(self): 157 def _xmluiGetSelectedValues(self):
150 ret = [] 158 ret = []
151 labels = [self.GetString(idx) for idx in self.GetSelections()] 159 labels = [self.GetString(idx) for idx in self.GetSelections()]
152 for label in labels: 160 for label in labels:
153 ret.append(self._xmlui_attr_map[label]) 161 ret.append(self._xmlui_attr_map[label])
154 return ret 162 return ret
163
164 def _xmluiAddValues(self, values, select=True):
165 selected = self._xmluiGetSelectedValues()
166 for value in values:
167 if value not in self._xmlui_attr_map.values():
168 wx.ListBox.Append(self, value)
169 self._xmlui_attr_map[value] = value
170 if value not in selected:
171 selected.append(value)
172 self._xmluiSelectValues(selected)
155 173
156 174
157 class WixContainer(object): 175 class WixContainer(object):
158 _xmlui_proportion = 1 176 _xmlui_proportion = 1
159 177