Mercurial > libervia-backend
comparison frontends/src/primitivus/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 | af0d08a84cc6 |
children | 73a0077f80cc |
comparison
equal
deleted
inserted
replaced
758:86224a13cc1d | 759:93bd868b8fb6 |
---|---|
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") 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_id") | 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) |
114 ctrl.param_id = (callback_id,[field.getAttribute('name') for field in elem.getElementsByTagName("field_back")]) | 114 ctrl.param_id = (callback_id,[field.getAttribute('name') for field in elem.getElementsByTagName("field_back")]) |
115 elif type_=="advanced_list": | 115 elif type_=="advanced_list": |
116 ctrl = sat_widgets.List(options=[getText(txt_elt) for txt_elt in elem.getElementsByTagName("text")], style=['can_select_none'], max_height=20, on_change=self.onParamChange) | 116 ctrl = sat_widgets.List(options=[getText(txt_elt) for txt_elt in elem.getElementsByTagName("text")], style=['can_select_none'], max_height=20, on_change=self.onParamChange) |
117 ctrl.selectValue(elem.getAttribute("value")) | 117 ctrl.selectValue(elem.getAttribute("value")) |
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.submit_id = top.getAttribute("submit") or None | |
181 if top.nodeName != "sat_xmlui" or not self.type in ['form', 'param', 'window']: | 182 if top.nodeName != "sat_xmlui" or not self.type in ['form', 'param', 'window']: |
182 raise InvalidXMLUI | 183 raise InvalidXMLUI |
183 | 184 |
184 if self.type == 'param': | 185 if self.type == 'param': |
185 self.param_changed = set() | 186 self.param_changed = set() |
232 | 233 |
233 ##EVENTS## | 234 ##EVENTS## |
234 | 235 |
235 def onButtonPress(self, button): | 236 def onButtonPress(self, button): |
236 callback_id, fields = button.param_id | 237 callback_id, fields = button.param_id |
237 data = {"callback_id":callback_id} | 238 data = {} |
238 for field in fields: | 239 for field in fields: |
239 ctrl = self.ctrl_list[field] | 240 ctrl = self.ctrl_list[field] |
240 if isinstance(ctrl['control'],sat_widgets.List): | 241 if isinstance(ctrl['control'],sat_widgets.List): |
241 data[field] = u'\t'.join(ctrl['control'].getSelectedValues()) | 242 data[field] = u'\t'.join(ctrl['control'].getSelectedValues()) |
242 else: | 243 else: |
243 data[field] = ctrl['control'].getValue() | 244 data[field] = ctrl['control'].getValue() |
244 | 245 |
245 id = self.host.bridge.launchAction("button", data, profile_key = self.host.profile) | 246 self.host.launchAction(callback_id, data, profile_key = self.host.profile) |
246 self.host.current_action_ids.add(id) | |
247 | 247 |
248 def onParamChange(self, widget, extra=None): | 248 def onParamChange(self, widget, extra=None): |
249 """Called when type is param and a widget to save is modified""" | 249 """Called when type is param and a widget to save is modified""" |
250 assert(self.type == "param") | 250 assert(self.type == "param") |
251 self.param_changed.add(widget) | 251 self.param_changed.add(widget) |
260 data.append((ctrl_name, "true" if ctrl['control'].get_state() else "false")) | 260 data.append((ctrl_name, "true" if ctrl['control'].get_state() else "false")) |
261 else: | 261 else: |
262 data.append((ctrl_name, ctrl['control'].get_edit_text())) | 262 data.append((ctrl_name, ctrl['control'].get_edit_text())) |
263 if self.misc.has_key('action_back'): #FIXME FIXME FIXME: WTF ! Must be cleaned | 263 if self.misc.has_key('action_back'): #FIXME FIXME FIXME: WTF ! Must be cleaned |
264 raise NotImplementedError | 264 raise NotImplementedError |
265 self.host.debug() | 265 elif 'callback' in self.misc: # FIXME: this part is not needed anymore |
266 elif 'callback' in self.misc: | |
267 try: | 266 try: |
268 self.misc['callback'](data, *self.misc['callback_args']) | 267 self.misc['callback'](data, submit_id=self.submit_id, *self.misc['callback_args']) |
269 except KeyError: | 268 except KeyError: |
270 self.misc['callback'](data) | 269 self.misc['callback'](data, submit_id=self.submit_id) |
270 elif self.submit_id is not None: | |
271 self.host.launchAction(self.submit_id, dict(data), profile_key=self.host.profile) | |
271 | 272 |
272 else: | 273 else: |
273 warning (_("The form data is not sent back, the type is not managed properly")) | 274 warning (_("The form data is not sent back, the type is not managed properly")) |
274 self.host.removePopUp() | 275 self.host.removePopUp() |
275 | 276 |