# HG changeset patch # User souliane # Date 1380728309 -7200 # Node ID 56f8a9c991944ad8aa7acb63ea7f5a414d8fe6be # Parent 5c5cf5bca240c05282b51bcefb315ff7e5b88ec2 core, primitivus: better support for parameter of type list diff -r 5c5cf5bca240 -r 56f8a9c99194 frontends/src/primitivus/xmlui.py --- 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, diff -r 5c5cf5bca240 -r 56f8a9c99194 src/tools/xml_tools.py --- a/src/tools/xml_tools.py Thu Sep 26 10:44:57 2013 +0200 +++ b/src/tools/xml_tools.py Wed Oct 02 17:38:29 2013 +0200 @@ -148,16 +148,30 @@ assert(False) type_ = param.getAttribute('type') value = param.getAttribute('value') or None + options = getOptions(param) callback_id = param.getAttribute('callback_id') or None if type_ == "button": param_ui.addEmpty() else: param_ui.addLabel(label or name) - param_ui.addElement(name=name, type_=type_, value=value, callback_id=callback_id) + param_ui.addElement(name=name, type_=type_, value=value, options=options, callback_id=callback_id) return param_ui.toXml() +def getOptions(param): + """Retrieve the options for list element. Allow listing the