changeset 545:8f88ae7ed886

wix: fixed parameters management
author Goffi <goffi@goffi.org>
date Wed, 14 Nov 2012 21:30:21 +0100
parents 899bd6fc7580
children 9dd297c513b4
files frontends/src/wix/param.py
diffstat 1 files changed, 46 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/wix/param.py	Wed Nov 14 21:29:38 2012 +0100
+++ b/frontends/src/wix/param.py	Wed Nov 14 21:30:21 2012 +0100
@@ -57,48 +57,54 @@
         panel=wx.Panel(self.notebook)
         panel.sizer = wx.BoxSizer(wx.VERTICAL)
 
-        cat_dom = minidom.parseString(self.host.bridge.getParamsForCategory(category, profile_key = self.host.profile).encode('utf-8'))
-        
-        for param in cat_dom.documentElement.getElementsByTagName("param"):
-            name = param.getAttribute("name")
-            label = param.getAttribute("label")
-            type = param.getAttribute("type")
-            value = param.getAttribute("value")
-            sizer = wx.BoxSizer(wx.HORIZONTAL)
-            if type=="string":
-                label=wx.StaticText(panel, -1, (label or name)+" ")
-                ctrl = wx.TextCtrl(panel, -1, value)
-                sizer.Add(label)
-            elif type=="password":
-                label=wx.StaticText(panel, -1, (label or name)+" ")
-                ctrl = wx.TextCtrl(panel, -1, value, style=wx.TE_PASSWORD)
-                sizer.Add(label)
-            elif type=="bool":
-                ctrl = wx.CheckBox(panel, -1, label or name, style = wx.CHK_2STATE)
-                ctrl.SetValue(value=="true")
-            elif type=="button":
-                ctrl = wx.Button(panel, -1, value)
-                ctrl.callback_id = param.getAttribute("callback_id")
-            else:
-                error(_("FIXME FIXME FIXME"))  #FIXME !
-                raise NotImplementedError
-            if name:
-                ctrl.param_id=(name, category)
-                self.ctl_list[(name, category)] = ctrl
-            sizer.Add(ctrl, 1, flag=wx.EXPAND)
-            panel.sizer.Add(sizer, flag=wx.EXPAND)
+        def errorGettingParams(ignore):
+            wx.MessageDialog(self, _("Can't get parameters"), _("Parameters error"), wx.ICON_ERROR).ShowModal()
 
-            if type=="string" or type=="password":
-                panel.Bind(wx.EVT_TEXT, self.onTextChanged, ctrl)
-            elif type=="bool":
-                panel.Bind(wx.EVT_CHECKBOX, self.onCheckBoxClicked, ctrl)
-            elif type=="button":
-                panel.Bind(wx.EVT_BUTTON, self.onButtonClicked, ctrl)
+        def gotParams(result):
+            cat_dom = minidom.parseString(result.encode('utf-8'))
+            
+            for param in cat_dom.documentElement.getElementsByTagName("param"):
+                name = param.getAttribute("name")
+                label = param.getAttribute("label")
+                type = param.getAttribute("type")
+                value = param.getAttribute("value")
+                sizer = wx.BoxSizer(wx.HORIZONTAL)
+                if type=="string":
+                    label=wx.StaticText(panel, -1, (label or name)+" ")
+                    ctrl = wx.TextCtrl(panel, -1, value)
+                    sizer.Add(label)
+                elif type=="password":
+                    label=wx.StaticText(panel, -1, (label or name)+" ")
+                    ctrl = wx.TextCtrl(panel, -1, value, style=wx.TE_PASSWORD)
+                    sizer.Add(label)
+                elif type=="bool":
+                    ctrl = wx.CheckBox(panel, -1, label or name, style = wx.CHK_2STATE)
+                    ctrl.SetValue(value=="true")
+                elif type=="button":
+                    ctrl = wx.Button(panel, -1, value)
+                    ctrl.callback_id = param.getAttribute("callback_id")
+                else:
+                    error(_("FIXME FIXME FIXME"))  #FIXME !
+                    raise NotImplementedError
+                if name:
+                    ctrl.param_id=(name, category)
+                    self.ctl_list[(name, category)] = ctrl
+                sizer.Add(ctrl, 1, flag=wx.EXPAND)
+                panel.sizer.Add(sizer, flag=wx.EXPAND)
 
-        panel.SetSizer(panel.sizer)
-        panel.SetAutoLayout(True)
-        self.notebook.AddPage(panel, category)
-        cat_dom.unlink()
+                if type=="string" or type=="password":
+                    panel.Bind(wx.EVT_TEXT, self.onTextChanged, ctrl)
+                elif type=="bool":
+                    panel.Bind(wx.EVT_CHECKBOX, self.onCheckBoxClicked, ctrl)
+                elif type=="button":
+                    panel.Bind(wx.EVT_BUTTON, self.onButtonClicked, ctrl)
+
+            panel.SetSizer(panel.sizer)
+            panel.SetAutoLayout(True)
+            self.notebook.AddPage(panel, category)
+            cat_dom.unlink()
+
+        self.host.bridge.getParamsForCategory(category, profile_key = self.host.profile, callback = gotParams, errback = errorGettingParams)
 
     def onTextChanged(self, event):
         """Called when a string paramater is modified"""