Mercurial > libervia-backend
diff frontends/src/primitivus/xmlui.py @ 760:73a0077f80cc
backend, frontends: XMLUI refactoring:
- session_id is resent in result data if found in incoming data
- list now use distinct labels and values (label is the one displayed, value is the one used for everything else)
- misc refactoring
/!\ urwid SàtExt must be updated ! /!\
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 24 Dec 2013 15:19:18 +0100 |
parents | 93bd868b8fb6 |
children | aed7d99276b8 |
line wrap: on
line diff
--- a/frontends/src/primitivus/xmlui.py Tue Dec 24 15:19:08 2013 +0100 +++ b/frontends/src/primitivus/xmlui.py Tue Dec 24 15:19:18 2013 +0100 @@ -105,7 +105,7 @@ 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, on_change=self.onParamChange if self.type == "param" else None) + ctrl = sat_widgets.List(options=[(option.getAttribute("value"), option.getAttribute("label")) for option in elem.getElementsByTagName("option")], style=style, on_change=self.onParamChange if self.type == "param" else None) ctrl.selectValue(elem.getAttribute("value")) self.ctrl_list[name] = ({'type':type_, 'control':ctrl}) elif type_=="button": @@ -178,6 +178,7 @@ top=cat_dom.documentElement self.type = top.getAttribute("type") self.title = top.getAttribute("title") or self.title + self.session_id = top.getAttribute("session_id") or None self.submit_id = top.getAttribute("submit") or None if top.nodeName != "sat_xmlui" or not self.type in ['form', 'param', 'window']: raise InvalidXMLUI @@ -251,24 +252,27 @@ self.param_changed.add(widget) def onFormSubmitted(self, button): - data = [] + selected_values = [] for ctrl_name in self.ctrl_list: ctrl = self.ctrl_list[ctrl_name] if isinstance(ctrl['control'], sat_widgets.List): - data.append((ctrl_name, u'\t'.join(ctrl['control'].getSelectedValues()))) + selected_values.append((ctrl_name, u'\t'.join([option.value for option in ctrl['control'].getSelectedValues()]))) elif isinstance(ctrl['control'], urwid.CheckBox): - data.append((ctrl_name, "true" if ctrl['control'].get_state() else "false")) + selected_values.append((ctrl_name, "true" if ctrl['control'].get_state() else "false")) else: - data.append((ctrl_name, ctrl['control'].get_edit_text())) + selected_values.append((ctrl_name, ctrl['control'].get_edit_text())) if self.misc.has_key('action_back'): #FIXME FIXME FIXME: WTF ! Must be cleaned raise NotImplementedError elif 'callback' in self.misc: # FIXME: this part is not needed anymore try: - self.misc['callback'](data, submit_id=self.submit_id, *self.misc['callback_args']) + self.misc['callback'](selected_values, submit_id=self.submit_id, *self.misc['callback_args']) except KeyError: - self.misc['callback'](data, submit_id=self.submit_id) + self.misc['callback'](selected_values, submit_id=self.submit_id) elif self.submit_id is not None: - self.host.launchAction(self.submit_id, dict(data), profile_key=self.host.profile) + data = dict(selected_values) + if self.session_id is not None: + data["session_id"] = self.session_id + self.host.launchAction(self.submit_id, data, profile_key=self.host.profile) else: warning (_("The form data is not sent back, the type is not managed properly"))