comparison 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
comparison
equal deleted inserted replaced
759:93bd868b8fb6 760:73a0077f80cc
103 elif type_=="bool": 103 elif type_=="bool":
104 ctrl = urwid.CheckBox('', state = value=="true") 104 ctrl = urwid.CheckBox('', state = value=="true")
105 self.ctrl_list[name] = ({'type':type_, 'control':ctrl}) 105 self.ctrl_list[name] = ({'type':type_, 'control':ctrl})
106 elif type_=="list": 106 elif type_=="list":
107 style=[] if elem.getAttribute("multi")=='yes' else ['single'] 107 style=[] if elem.getAttribute("multi")=='yes' else ['single']
108 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) 108 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)
109 ctrl.selectValue(elem.getAttribute("value")) 109 ctrl.selectValue(elem.getAttribute("value"))
110 self.ctrl_list[name] = ({'type':type_, 'control':ctrl}) 110 self.ctrl_list[name] = ({'type':type_, 'control':ctrl})
111 elif type_=="button": 111 elif type_=="button":
112 callback_id = elem.getAttribute("callback") 112 callback_id = elem.getAttribute("callback")
113 ctrl = sat_widgets.CustomButton(value, on_press=self.onButtonPress) 113 ctrl = sat_widgets.CustomButton(value, on_press=self.onButtonPress)
176 176
177 cat_dom = minidom.parseString(xml_data.encode('utf-8')) 177 cat_dom = minidom.parseString(xml_data.encode('utf-8'))
178 top=cat_dom.documentElement 178 top=cat_dom.documentElement
179 self.type = top.getAttribute("type") 179 self.type = top.getAttribute("type")
180 self.title = top.getAttribute("title") or self.title 180 self.title = top.getAttribute("title") or self.title
181 self.session_id = top.getAttribute("session_id") or None
181 self.submit_id = top.getAttribute("submit") or None 182 self.submit_id = top.getAttribute("submit") or None
182 if top.nodeName != "sat_xmlui" or not self.type in ['form', 'param', 'window']: 183 if top.nodeName != "sat_xmlui" or not self.type in ['form', 'param', 'window']:
183 raise InvalidXMLUI 184 raise InvalidXMLUI
184 185
185 if self.type == 'param': 186 if self.type == 'param':
249 """Called when type is param and a widget to save is modified""" 250 """Called when type is param and a widget to save is modified"""
250 assert(self.type == "param") 251 assert(self.type == "param")
251 self.param_changed.add(widget) 252 self.param_changed.add(widget)
252 253
253 def onFormSubmitted(self, button): 254 def onFormSubmitted(self, button):
254 data = [] 255 selected_values = []
255 for ctrl_name in self.ctrl_list: 256 for ctrl_name in self.ctrl_list:
256 ctrl = self.ctrl_list[ctrl_name] 257 ctrl = self.ctrl_list[ctrl_name]
257 if isinstance(ctrl['control'], sat_widgets.List): 258 if isinstance(ctrl['control'], sat_widgets.List):
258 data.append((ctrl_name, u'\t'.join(ctrl['control'].getSelectedValues()))) 259 selected_values.append((ctrl_name, u'\t'.join([option.value for option in ctrl['control'].getSelectedValues()])))
259 elif isinstance(ctrl['control'], urwid.CheckBox): 260 elif isinstance(ctrl['control'], urwid.CheckBox):
260 data.append((ctrl_name, "true" if ctrl['control'].get_state() else "false")) 261 selected_values.append((ctrl_name, "true" if ctrl['control'].get_state() else "false"))
261 else: 262 else:
262 data.append((ctrl_name, ctrl['control'].get_edit_text())) 263 selected_values.append((ctrl_name, ctrl['control'].get_edit_text()))
263 if self.misc.has_key('action_back'): #FIXME FIXME FIXME: WTF ! Must be cleaned 264 if self.misc.has_key('action_back'): #FIXME FIXME FIXME: WTF ! Must be cleaned
264 raise NotImplementedError 265 raise NotImplementedError
265 elif 'callback' in self.misc: # FIXME: this part is not needed anymore 266 elif 'callback' in self.misc: # FIXME: this part is not needed anymore
266 try: 267 try:
267 self.misc['callback'](data, submit_id=self.submit_id, *self.misc['callback_args']) 268 self.misc['callback'](selected_values, submit_id=self.submit_id, *self.misc['callback_args'])
268 except KeyError: 269 except KeyError:
269 self.misc['callback'](data, submit_id=self.submit_id) 270 self.misc['callback'](selected_values, submit_id=self.submit_id)
270 elif self.submit_id is not None: 271 elif self.submit_id is not None:
271 self.host.launchAction(self.submit_id, dict(data), profile_key=self.host.profile) 272 data = dict(selected_values)
273 if self.session_id is not None:
274 data["session_id"] = self.session_id
275 self.host.launchAction(self.submit_id, data, profile_key=self.host.profile)
272 276
273 else: 277 else:
274 warning (_("The form data is not sent back, the type is not managed properly")) 278 warning (_("The form data is not sent back, the type is not managed properly"))
275 self.host.removePopUp() 279 self.host.removePopUp()
276 280