changeset 429:9283f9e5e5dd

browser_side (xmlui): added setter methods + manage multi-selection for list widgets
author souliane <souliane@mailoo.org>
date Tue, 01 Apr 2014 11:00:28 +0200
parents 0c4547587637
children a927a98b398d
files browser_side/xmlui.py
diffstat 1 files changed, 29 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/browser_side/xmlui.py	Tue Apr 01 12:14:31 2014 +0200
+++ b/browser_side/xmlui.py	Tue Apr 01 11:00:28 2014 +0200
@@ -83,6 +83,9 @@
         TextBox.__init__(self)
         self.setText(value)
 
+    def _xmluiSetValue(self, value):
+        self.setText(value)
+
     def _xmluiGetValue(self):
         return self.getText()
 
@@ -96,6 +99,9 @@
         PasswordTextBox.__init__(self)
         self.setText(value)
 
+    def _xmluiSetValue(self, value):
+        self.setText(value)
+
     def _xmluiGetValue(self):
         return self.getText()
 
@@ -109,6 +115,9 @@
         TextArea.__init__(self)
         self.setText(value)
 
+    def _xmluiSetValue(self, value):
+        self.setText(value)
+
     def _xmluiGetValue(self):
         return self.getText()
 
@@ -122,6 +131,9 @@
         CheckBox.__init__(self)
         self.setChecked(state)
 
+    def _xmluiSetValue(self, value):
+        self.setChecked(value == "true")
+
     def _xmluiGetValue(self):
         return "true" if self.isChecked() else "false"
 
@@ -132,7 +144,7 @@
 class ButtonWidget(xmlui.ButtonWidget, Button):
 
     def __init__(self, parent, value, click_callback):
-        Button.__init__(self, value)
+        Button.__init__(self, value, click_callback)
 
     def _xmluiOnClick(self, callback):
         self.addClickListener(callback)
@@ -140,14 +152,16 @@
 
 class ListWidget(xmlui.ListWidget, ListBox):
 
-    def __init__(self, parent, options, flags):
+    def __init__(self, parent, options, selected, flags):
         ListBox.__init__(self)
         self.setMultipleSelect('single' not in flags)
         for option in options:
             self.addItem(option[1])
         self._xmlui_attr_map = {label: value for value, label in options}
+        self._xmluiSelectValues(selected)
 
     def _xmluiSelectValue(self, value):
+        """Select a value checking its item"""
         try:
             label = [label for label, _value in self._xmlui_attr_map.items() if _value == value][0]
         except IndexError:
@@ -155,6 +169,10 @@
             return
         self.selectItem(label)
 
+    def _xmluiSelectValues(self, values):
+        """Select multiple values, ignore the items"""
+        self.setValueSelection(values)
+
     def _xmluiGetSelectedValues(self):
         ret = []
         for label in self.getSelectedItemText():
@@ -164,6 +182,15 @@
     def _xmluiOnChange(self, callback):
         self.addChangeListener(callback)
 
+    def _xmluiAddValues(self, values, select=True):
+        selected = self._xmluiGetSelectedValues()
+        for value in values:
+            self.addItem(value)
+            self._xmlui_attr_map[value] = value
+            if value not in selected:
+                selected.append(value)
+        self._xmluiSelectValues(selected)
+
 
 class LiberviaContainer(object):