Mercurial > libervia-backend
comparison frontends/src/wix/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 |
---|---|
93 ctrl.SetValue(value=="true") | 93 ctrl.SetValue(value=="true") |
94 self.ctrl_list[name] = ({'type':type, 'control':ctrl}) | 94 self.ctrl_list[name] = ({'type':type, 'control':ctrl}) |
95 _proportion = 1 | 95 _proportion = 1 |
96 elif type=="list": | 96 elif type=="list": |
97 style=wx.LB_MULTIPLE if elem.getAttribute("multi")=='yes' else wx.LB_SINGLE | 97 style=wx.LB_MULTIPLE if elem.getAttribute("multi")=='yes' else wx.LB_SINGLE |
98 ctrl = wx.ListBox(parent, -1, choices=[option.getAttribute("value") for option in elem.getElementsByTagName("option")], style=style) | 98 _options = [(option.getAttribute("label"), option.getAttribute("value")) for option in elem.getElementsByTagName("option")] |
99 self.ctrl_list[name] = ({'type':type, 'control':ctrl}) | 99 attr_map = {label: value for label, value in _options} |
100 ctrl = wx.ListBox(parent, -1, choices=[option[0] for option in _options], style=style) | |
101 self.ctrl_list[name] = ({'type':type, 'control':ctrl, 'attr_map': attr_map}) | |
100 _proportion = 1 | 102 _proportion = 1 |
101 elif type=="button": | 103 elif type=="button": |
102 callback_id = elem.getAttribute("callback_id") | 104 callback_id = elem.getAttribute("callback_id") |
103 ctrl = wx.Button(parent, -1, value) | 105 ctrl = wx.Button(parent, -1, value) |
104 ctrl.param_id = (callback_id,[field.getAttribute('name') for field in elem.getElementsByTagName("field_back")]) | 106 ctrl.param_id = (callback_id,[field.getAttribute('name') for field in elem.getElementsByTagName("field_back")]) |
165 | 167 |
166 cat_dom = minidom.parseString(xml_data.encode('utf-8')) | 168 cat_dom = minidom.parseString(xml_data.encode('utf-8')) |
167 top= cat_dom.documentElement | 169 top= cat_dom.documentElement |
168 self.type = top.getAttribute("type") | 170 self.type = top.getAttribute("type") |
169 self.title = top .getAttribute("title") | 171 self.title = top .getAttribute("title") |
172 self.session_id = top.getAttribute("session_id") or None | |
170 self.submit_id = top.getAttribute("submit") or None | 173 self.submit_id = top.getAttribute("submit") or None |
171 if self.title: | 174 if self.title: |
172 self.SetTitle(self.title) | 175 self.SetTitle(self.title) |
173 if top.nodeName != "sat_xmlui" or not self.type in ['form', 'param', 'window']: | 176 if top.nodeName != "sat_xmlui" or not self.type in ['form', 'param', 'window']: |
174 raise Exception("Invalid XMLUI") #TODO: make a custom exception | 177 raise Exception("Invalid XMLUI") #TODO: make a custom exception |
209 event.Skip() | 212 event.Skip() |
210 | 213 |
211 def onFormSubmitted(self, event): | 214 def onFormSubmitted(self, event): |
212 """Called when submit button is clicked""" | 215 """Called when submit button is clicked""" |
213 debug(_("Submitting form")) | 216 debug(_("Submitting form")) |
214 data = [] | 217 selected_values = [] |
215 for ctrl_name in self.ctrl_list: | 218 for ctrl_name in self.ctrl_list: |
216 ctrl = self.ctrl_list[ctrl_name] | 219 ctrl = self.ctrl_list[ctrl_name] |
217 if isinstance(ctrl['control'], wx.ListBox): | 220 if isinstance(ctrl['control'], wx.ListBox): |
218 data.append((ctrl_name, ctrl['control'].GetStringSelection())) | 221 label = ctrl['control'].GetStringSelection() |
222 value = ctrl['attr_map'][label] | |
223 selected_values.append((ctrl_name, value)) | |
219 elif isinstance(ctrl['control'], wx.CheckBox): | 224 elif isinstance(ctrl['control'], wx.CheckBox): |
220 data.append((ctrl_name, "true" if ctrl['control'].GetValue() else "false")) | 225 selected_values.append((ctrl_name, "true" if ctrl['control'].GetValue() else "false")) |
221 else: | 226 else: |
222 data.append((ctrl_name, ctrl['control'].GetValue())) | 227 selected_values.append((ctrl_name, ctrl['control'].GetValue())) |
223 if self.misc.has_key('action_back'): #FIXME FIXME FIXME: WTF ! Must be cleaned | 228 if self.misc.has_key('action_back'): #FIXME FIXME FIXME: WTF ! Must be cleaned |
224 id = self.misc['action_back']("SUBMIT",self.misc['target'], data) | 229 id = self.misc['action_back']("SUBMIT",self.misc['target'], selected_values) |
225 self.host.current_action_ids.add(id) | 230 self.host.current_action_ids.add(id) |
226 elif self.misc.has_key('callback'): | 231 elif self.misc.has_key('callback'): |
227 self.misc['callback'](data) | 232 self.misc['callback'](selected_values) |
228 | 233 |
229 elif self.submit_id is not None: | 234 elif self.submit_id is not None: |
230 data = dict(selected_values) | 235 data = dict(selected_values) |
236 if self.session_id is not None: | |
237 data["session_id"] = self.session_id | |
231 self.host.launchAction(self.submit_id, data, profile_key=self.host.profile) | 238 self.host.launchAction(self.submit_id, data, profile_key=self.host.profile) |
232 else: | 239 else: |
233 warning (_("The form data is not sent back, the type is not managed properly")) | 240 warning (_("The form data is not sent back, the type is not managed properly")) |
234 self.MakeModal(False) | 241 self.MakeModal(False) |
235 self.Destroy() | 242 self.Destroy() |