diff 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
line wrap: on
line diff
--- a/frontends/src/wix/xmlui.py	Tue Dec 24 15:19:08 2013 +0100
+++ b/frontends/src/wix/xmlui.py	Tue Dec 24 15:19:18 2013 +0100
@@ -95,8 +95,10 @@
                 _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 @@
         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 @@
     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"))