diff frontends/src/primitivus/xmlui.py @ 655:56f8a9c99194

core, primitivus: better support for parameter of type list
author souliane <souliane@mailoo.org>
date Wed, 02 Oct 2013 17:38:29 +0200
parents 49587e170f53
children af0d08a84cc6
line wrap: on
line diff
--- a/frontends/src/primitivus/xmlui.py	Thu Sep 26 10:44:57 2013 +0200
+++ b/frontends/src/primitivus/xmlui.py	Wed Oct 02 17:38:29 2013 +0200
@@ -105,22 +105,29 @@
                 self.ctrl_list[name] = ({'type':type_, 'control':ctrl})
             elif type_=="list":
                 style=[] if elem.getAttribute("multi")=='yes' else ['single']
-                ctrl = sat_widgets.List(options=[option.getAttribute("value") for option in elem.getElementsByTagName("option")], style=style)
+                ctrl = sat_widgets.List(options=[option.getAttribute("value") for option in elem.getElementsByTagName("option")], style=style, on_change=self.onParamChange)
+                ctrl.selectValue(elem.getAttribute("value"))
                 self.ctrl_list[name] = ({'type':type_, 'control':ctrl})
             elif type_=="button":
                 callback_id = elem.getAttribute("callback_id")
                 ctrl = sat_widgets.CustomButton(value, on_press=self.onButtonPress)
                 ctrl.param_id = (callback_id,[field.getAttribute('name') for field in elem.getElementsByTagName("field_back")])
             elif type_=="advanced_list":
-                ctrl = sat_widgets.List(options=[getText(txt_elt) for txt_elt in elem.getElementsByTagName("text")], style=['can_select_none'], max_height=20)
-
+                ctrl = sat_widgets.List(options=[getText(txt_elt) for txt_elt in elem.getElementsByTagName("text")], style=['can_select_none'], max_height=20, on_change=self.onParamChange)
+                ctrl.selectValue(elem.getAttribute("value"))
                 self.ctrl_list[name] = ({'type':type_, 'control':ctrl})
             else:
                 error(_("FIXME FIXME FIXME: type [%s] is not implemented") % type_)  #FIXME !
                 raise NotImplementedError
             if self.type == 'param':
-                if isinstance(ctrl,urwid.Edit) or isinstance(ctrl,urwid.CheckBox):
+                if isinstance(ctrl, urwid.Edit) or isinstance(ctrl, urwid.CheckBox):
                     urwid.connect_signal(ctrl,'change',self.onParamChange)
+                elif isinstance(ctrl, sat_widgets.List):
+                    # the GenericList member triggers the events, not List itself
+                    # TODO: create a method GenericList.setParamData() for that,
+                    # or later in onSaveParams do something like ctrl.getParent()
+                    ctrl.genericList._param_category = self._current_category
+                    ctrl.genericList._param_name = name
                 ctrl._param_category = self._current_category
                 ctrl._param_name = name
             parent.append(ctrl)
@@ -228,7 +235,7 @@
         for field in fields:
             ctrl = self.ctrl_list[field]
             if isinstance(ctrl['control'],sat_widgets.List):
-                data[field] = '\t'.join(ctrl['control'].getSelectedValues())
+                data[field] = u'\t'.join(ctrl['control'].getSelectedValues())
             else:
                 data[field] = ctrl['control'].getValue()
 
@@ -245,7 +252,7 @@
         for ctrl_name in self.ctrl_list:
             ctrl = self.ctrl_list[ctrl_name]
             if isinstance(ctrl['control'], sat_widgets.List):
-                data.append((ctrl_name, ctrl['control'].getSelectedValue()))
+                data.append((ctrl_name, u'\t'.join(ctrl['control'].getSelectedValues())))
             elif isinstance(ctrl['control'], urwid.CheckBox):
                 data.append((ctrl_name, "true" if ctrl['control'].get_state() else "false"))
             else:
@@ -273,6 +280,8 @@
         for ctrl in self.param_changed:
             if isinstance(ctrl, urwid.CheckBox):
                 value = "true" if ctrl.get_state() else "false"
+            elif isinstance(ctrl, sat_widgets.GenericList):
+                value = u'\t'.join(ctrl.getSelectedValues())
             else:
                 value = ctrl.get_edit_text()
             self.host.bridge.setParam(ctrl._param_name, value, ctrl._param_category,