Mercurial > libervia-backend
comparison frontends/src/wix/xmlui.py @ 759:93bd868b8fb6
backend, frontends: callbacks refactoring:
- launchAction is now async, and return a dictionary for its result
- no more action_id, actionResult* are deprecated
- callback system is about to be unified
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 24 Dec 2013 15:19:08 +0100 |
parents | 84a6e83157c2 |
children | 73a0077f80cc |
comparison
equal
deleted
inserted
replaced
758:86224a13cc1d | 759:93bd868b8fb6 |
---|---|
28 | 28 |
29 class XMLUI(wx.Frame): | 29 class XMLUI(wx.Frame): |
30 """Create an user interface from a SàT xml""" | 30 """Create an user interface from a SàT xml""" |
31 | 31 |
32 def __init__(self, host, xml_data='', title="Form", options = None, misc = None): | 32 def __init__(self, host, xml_data='', title="Form", options = None, misc = None): |
33 style = wx.DEFAULT_FRAME_STYLE & ~wx.CLOSE_BOX if 'NO_CANCEL' in options else wx.DEFAULT_FRAME_STYLE #FIXME: gof: Q&D tmp hack | 33 if options is None: |
34 options = [] | |
35 style = wx.DEFAULT_FRAME_STYLE & ~wx.CLOSE_BOX if 'NO_CANCEL' in options else wx.DEFAULT_FRAME_STYLE #FIXME: Q&D tmp hack | |
34 super(XMLUI, self).__init__(None, title=title, style=style) | 36 super(XMLUI, self).__init__(None, title=title, style=style) |
35 | 37 |
36 self.host = host | 38 self.host = host |
37 self.options = options or [] | 39 self.options = options |
38 self.misc = misc or {} | 40 self.misc = misc or {} |
39 self.ctrl_list = {} # usefull to access ctrl | 41 self.ctrl_list = {} # usefull to access ctrl |
40 | 42 |
41 self.sizer = wx.BoxSizer(wx.VERTICAL) | 43 self.sizer = wx.BoxSizer(wx.VERTICAL) |
42 self.SetSizer(self.sizer) | 44 self.SetSizer(self.sizer) |
163 | 165 |
164 cat_dom = minidom.parseString(xml_data.encode('utf-8')) | 166 cat_dom = minidom.parseString(xml_data.encode('utf-8')) |
165 top= cat_dom.documentElement | 167 top= cat_dom.documentElement |
166 self.type = top.getAttribute("type") | 168 self.type = top.getAttribute("type") |
167 self.title = top .getAttribute("title") | 169 self.title = top .getAttribute("title") |
170 self.submit_id = top.getAttribute("submit") or None | |
168 if self.title: | 171 if self.title: |
169 self.SetTitle(self.title) | 172 self.SetTitle(self.title) |
170 if top.nodeName != "sat_xmlui" or not self.type in ['form', 'param', 'window']: | 173 if top.nodeName != "sat_xmlui" or not self.type in ['form', 'param', 'window']: |
171 raise Exception("Invalid XMLUI") #TODO: make a custom exception | 174 raise Exception("Invalid XMLUI") #TODO: make a custom exception |
172 | 175 |
193 ###events | 196 ###events |
194 | 197 |
195 def onButtonClicked(self, event): | 198 def onButtonClicked(self, event): |
196 """Called when a button is pushed""" | 199 """Called when a button is pushed""" |
197 callback_id, fields = event.GetEventObject().param_id | 200 callback_id, fields = event.GetEventObject().param_id |
198 data = {"callback_id":callback_id} | |
199 for field in fields: | 201 for field in fields: |
200 ctrl = self.ctrl_list[field] | 202 ctrl = self.ctrl_list[field] |
201 if isinstance(ctrl['control'], wx.ListBox): | 203 if isinstance(ctrl['control'], wx.ListBox): |
202 data[field] = '\t'.join([ctrl['control'].GetString(idx) for idx in ctrl['control'].GetSelections()]) | 204 data[field] = '\t'.join([ctrl['control'].GetString(idx) for idx in ctrl['control'].GetSelections()]) |
203 else: | 205 else: |
204 data[field] = ctrl['control'].GetValue() | 206 data[field] = ctrl['control'].GetValue() |
205 | 207 |
206 id = self.host.bridge.launchAction("button", data, profile_key = self.host.profile) | 208 self.host.launchAction(callback_id, None, profile_key = self.host.profile) |
207 self.host.current_action_ids.add(id) | |
208 event.Skip() | 209 event.Skip() |
209 | 210 |
210 def onFormSubmitted(self, event): | 211 def onFormSubmitted(self, event): |
211 """Called when submit button is clicked""" | 212 """Called when submit button is clicked""" |
212 debug(_("Submitting form")) | 213 debug(_("Submitting form")) |
222 if self.misc.has_key('action_back'): #FIXME FIXME FIXME: WTF ! Must be cleaned | 223 if self.misc.has_key('action_back'): #FIXME FIXME FIXME: WTF ! Must be cleaned |
223 id = self.misc['action_back']("SUBMIT",self.misc['target'], data) | 224 id = self.misc['action_back']("SUBMIT",self.misc['target'], data) |
224 self.host.current_action_ids.add(id) | 225 self.host.current_action_ids.add(id) |
225 elif self.misc.has_key('callback'): | 226 elif self.misc.has_key('callback'): |
226 self.misc['callback'](data) | 227 self.misc['callback'](data) |
228 | |
229 elif self.submit_id is not None: | |
230 data = dict(selected_values) | |
231 self.host.launchAction(self.submit_id, data, profile_key=self.host.profile) | |
227 else: | 232 else: |
228 warning (_("The form data is not sent back, the type is not managed properly")) | 233 warning (_("The form data is not sent back, the type is not managed properly")) |
229 self.MakeModal(False) | 234 self.MakeModal(False) |
230 self.Destroy() | 235 self.Destroy() |
231 | 236 |