frontends (xmlui): add setter methods + fixes:
- add _xmluiSetValue for all widgets + _xmluiAddValues for ListWidget
- fix popup dialog OK button + _xmluiOnClick for ButtonWidget
This commit is contained in:
parent
ec579aff81
commit
35d66de820
1 changed files with 64 additions and 10 deletions
|
|
@ -42,6 +42,10 @@ class WixWidget(object):
|
|||
|
||||
|
||||
class ValueWidget(WixWidget):
|
||||
|
||||
def _xmluiSetValue(self, value):
|
||||
self.SetValue(value)
|
||||
|
||||
def _xmluiGetValue(self):
|
||||
return self.GetValue()
|
||||
|
||||
|
|
@ -106,6 +110,9 @@ class BoolWidget(EventWidget, ValueWidget, xmlui.BoolWidget, wx.CheckBox):
|
|||
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 @@ class ButtonWidget(EventWidget, WixWidget, xmlui.ButtonWidget, wx.Button):
|
|||
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 @@ class ListWidget(EventWidget, WixWidget, xmlui.ListWidget, wx.ListBox):
|
|||
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 @@ class ListWidget(EventWidget, WixWidget, xmlui.ListWidget, wx.ListBox):
|
|||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue