diff 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
line wrap: on
line diff
--- a/frontends/src/primitivus/xmlui.py	Tue Dec 24 15:19:08 2013 +0100
+++ b/frontends/src/primitivus/xmlui.py	Tue Dec 24 15:19:08 2013 +0100
@@ -109,7 +109,7 @@
                 ctrl.selectValue(elem.getAttribute("value"))
                 self.ctrl_list[name] = ({'type':type_, 'control':ctrl})
             elif type_=="button":
-                callback_id = elem.getAttribute("callback_id")
+                callback_id = elem.getAttribute("callback")
                 ctrl = sat_widgets.CustomButton(value, on_press=self.onButtonPress)
                 ctrl.param_id = (callback_id,[field.getAttribute('name') for field in elem.getElementsByTagName("field_back")])
             elif type_=="advanced_list":
@@ -178,6 +178,7 @@
         top=cat_dom.documentElement
         self.type = top.getAttribute("type")
         self.title = top.getAttribute("title") or self.title
+        self.submit_id = top.getAttribute("submit") or None
         if top.nodeName != "sat_xmlui" or not self.type in ['form', 'param', 'window']:
             raise InvalidXMLUI
 
@@ -234,7 +235,7 @@
 
     def onButtonPress(self, button):
         callback_id, fields = button.param_id
-        data = {"callback_id":callback_id}
+        data = {}
         for field in fields:
             ctrl = self.ctrl_list[field]
             if isinstance(ctrl['control'],sat_widgets.List):
@@ -242,8 +243,7 @@
             else:
                 data[field] = ctrl['control'].getValue()
 
-        id = self.host.bridge.launchAction("button", data, profile_key = self.host.profile)
-        self.host.current_action_ids.add(id)
+        self.host.launchAction(callback_id, data, profile_key = self.host.profile)
 
     def onParamChange(self, widget, extra=None):
         """Called when type is param and a widget to save is modified"""
@@ -262,12 +262,13 @@
                 data.append((ctrl_name, ctrl['control'].get_edit_text()))
         if self.misc.has_key('action_back'): #FIXME FIXME FIXME: WTF ! Must be cleaned
             raise NotImplementedError
-            self.host.debug()
-        elif 'callback' in self.misc:
+        elif 'callback' in self.misc: # FIXME: this part is not needed anymore
             try:
-                self.misc['callback'](data, *self.misc['callback_args'])
+                self.misc['callback'](data, submit_id=self.submit_id, *self.misc['callback_args'])
             except KeyError:
-                self.misc['callback'](data)
+                self.misc['callback'](data, submit_id=self.submit_id)
+        elif self.submit_id is not None:
+            self.host.launchAction(self.submit_id, dict(data), profile_key=self.host.profile)
 
         else:
             warning (_("The form data is not sent back, the type is not managed properly"))