diff 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
line wrap: on
line diff
--- 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