diff frontends/src/tools/xmlui.py @ 808:d035c662b357

frontends: some modifications to ease the the use of the new sat_frontends.tools.xmlui.XMLUI class in Libervia
author Goffi <goffi@goffi.org>
date Tue, 04 Feb 2014 18:32:33 +0100
parents 7c05c39156a2
children 1fe00f0c9a91
line wrap: on
line diff
--- a/frontends/src/tools/xmlui.py	Tue Feb 04 18:26:03 2014 +0100
+++ b/frontends/src/tools/xmlui.py	Tue Feb 04 18:32:33 2014 +0100
@@ -242,7 +242,7 @@
                     self._parseChilds(cont, node, ('widget', 'container'))
                 try:
                     parent._xmluiAppend(cont)
-                except AttributeError:
+                except (AttributeError, TypeError): # XXX: TypeError is here because pyjamas raise a TypeError instead of an AttributeError
                     if parent is self:
                         self.main_cont = cont
                     else:
@@ -279,7 +279,8 @@
                     try:
                         value = node.childNodes[0].wholeText
                     except IndexError:
-                        warning (_("text node has no child !"))
+                        # warning (_("text node has no child !"))
+                        pass # FIXME proper warning (this one is not OK with Libervia)
                     ctrl = self.widget_factory.createTextWidget(parent, value)
                 elif type_=="label":
                     ctrl = self.widget_factory.createLabelWidget(parent, value)
@@ -318,8 +319,8 @@
                     try:
                         ctrl._xmluiOnChange(self.onParamChange)
                         ctrl._param_category = self._current_category
-                    except AttributeError:
-                        if not isinstance(ctrl, (EmptyWidget, TextWidget)):
+                    except (AttributeError, TypeError): # XXX: TypeError is here because pyjamas raise a TypeError instead of an AttributeError
+                        if not isinstance(ctrl, (EmptyWidget, TextWidget, LabelWidget, JidWidget)):
                             warning(_("No change listener on [%s]" % ctrl))
 
                 ctrl._xmlui_name = name
@@ -360,6 +361,12 @@
         """
         raise NotImplementedError
 
+    def _xmluiLaunchAction(self, action_id, data):
+        self.host.launchAction(action_id, data, profile_key = self.host.profile)
+
+    def _xmluiSetParam(self, name, value, category):
+        self.host.bridge.setParam(name, value, category, profile_key=self.host.profile)
+
     ##EVENTS##
 
     def onParamChange(self, ctrl):
@@ -378,7 +385,7 @@
                 name = self.escape(wid._xmlui_name)
                 value = wid._xmluiGetValue()
                 ret[name] = value
-            except AttributeError:
+            except (AttributeError, TypeError): # XXX: TypeError is here because pyjamas raise a TypeError instead of an AttributeError
                 pass
         idx = ctrl._xmluiGetSelectedIndex()
         if idx is not None:
@@ -387,7 +394,7 @@
         if callback_id is None:
             warning(_("No callback_id found"))
             return
-        self.host.launchAction(callback_id, data, profile_key = self.host.profile)
+        self._xmluiLaunchAction(callback_id, data)
 
     def onButtonPress(self, button):
         """ Called when an XMLUI button is clicked
@@ -404,7 +411,7 @@
                 data[escaped] = u'\t'.join(ctrl['control']._xmluiGetSelected())
             else:
                 data[escaped] = ctrl['control']._xmluiGetValue()
-        self.host.launchAction(callback_id, data, profile_key = self.host.profile)
+        self._xmluiLaunchAction(callback_id, data)
 
     def onFormSubmitted(self, ignore=None):
         """ An XMLUI form has been submited
@@ -423,7 +430,7 @@
             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)
+            self._xmluiLaunchAction(self.submit_id, data)
 
         else:
             warning (_("The form data is not sent back, the type is not managed properly"))
@@ -446,7 +453,7 @@
                 value = u'\t'.join(ctrl._xmluiGetSelectedValues())
             else:
                 value = ctrl._xmluiGetValue()
-            param_name = ctr._xmlui_name.split(Const.SAT_PARAM_SEPARATOR)[1]
-            self.host.bridge.setParam(param_name, value, ctrl._param_category,
-                                      profile_key=self.host.profile)
+            param_name = ctrl._xmlui_name.split(Const.SAT_PARAM_SEPARATOR)[1]
+            self._xmluiSetParam(param_name, value, ctrl._param_category)
+
         self._xmluiClose()