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 ! /!\
This commit is contained in:
parent
069a250b04
commit
80a7423f02
2 changed files with 46 additions and 21 deletions
|
|
@ -105,7 +105,7 @@ class XMLUI(urwid.WidgetWrap):
|
|||
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 @@ class XMLUI(urwid.WidgetWrap):
|
|||
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 @@ class XMLUI(urwid.WidgetWrap):
|
|||
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"))
|
||||
|
|
|
|||
|
|
@ -95,8 +95,10 @@ class XMLUI(wx.Frame):
|
|||
_proportion = 1
|
||||
elif type=="list":
|
||||
style=wx.LB_MULTIPLE if elem.getAttribute("multi")=='yes' else wx.LB_SINGLE
|
||||
ctrl = wx.ListBox(parent, -1, choices=[option.getAttribute("value") for option in elem.getElementsByTagName("option")], style=style)
|
||||
self.ctrl_list[name] = ({'type':type, 'control':ctrl})
|
||||
_options = [(option.getAttribute("label"), option.getAttribute("value")) for option in elem.getElementsByTagName("option")]
|
||||
attr_map = {label: value for label, value in _options}
|
||||
ctrl = wx.ListBox(parent, -1, choices=[option[0] for option in _options], style=style)
|
||||
self.ctrl_list[name] = ({'type':type, 'control':ctrl, 'attr_map': attr_map})
|
||||
_proportion = 1
|
||||
elif type=="button":
|
||||
callback_id = elem.getAttribute("callback_id")
|
||||
|
|
@ -167,6 +169,7 @@ class XMLUI(wx.Frame):
|
|||
top= cat_dom.documentElement
|
||||
self.type = top.getAttribute("type")
|
||||
self.title = top .getAttribute("title")
|
||||
self.session_id = top.getAttribute("session_id") or None
|
||||
self.submit_id = top.getAttribute("submit") or None
|
||||
if self.title:
|
||||
self.SetTitle(self.title)
|
||||
|
|
@ -211,23 +214,27 @@ class XMLUI(wx.Frame):
|
|||
def onFormSubmitted(self, event):
|
||||
"""Called when submit button is clicked"""
|
||||
debug(_("Submitting form"))
|
||||
data = []
|
||||
selected_values = []
|
||||
for ctrl_name in self.ctrl_list:
|
||||
ctrl = self.ctrl_list[ctrl_name]
|
||||
if isinstance(ctrl['control'], wx.ListBox):
|
||||
data.append((ctrl_name, ctrl['control'].GetStringSelection()))
|
||||
label = ctrl['control'].GetStringSelection()
|
||||
value = ctrl['attr_map'][label]
|
||||
selected_values.append((ctrl_name, value))
|
||||
elif isinstance(ctrl['control'], wx.CheckBox):
|
||||
data.append((ctrl_name, "true" if ctrl['control'].GetValue() else "false"))
|
||||
selected_values.append((ctrl_name, "true" if ctrl['control'].GetValue() else "false"))
|
||||
else:
|
||||
data.append((ctrl_name, ctrl['control'].GetValue()))
|
||||
selected_values.append((ctrl_name, ctrl['control'].GetValue()))
|
||||
if self.misc.has_key('action_back'): #FIXME FIXME FIXME: WTF ! Must be cleaned
|
||||
id = self.misc['action_back']("SUBMIT",self.misc['target'], data)
|
||||
id = self.misc['action_back']("SUBMIT",self.misc['target'], selected_values)
|
||||
self.host.current_action_ids.add(id)
|
||||
elif self.misc.has_key('callback'):
|
||||
self.misc['callback'](data)
|
||||
self.misc['callback'](selected_values)
|
||||
|
||||
elif self.submit_id is not None:
|
||||
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"))
|
||||
|
|
|
|||
Loading…
Reference in a new issue