diff frontends/wix/param.py @ 18:6928e3cb73a8

refactoring: using xml params part II
author Goffi <goffi@goffi.org>
date Fri, 06 Nov 2009 23:31:00 +0100
parents c4bc297b82f0
children 633c5ed65701
line wrap: on
line diff
--- a/frontends/wix/param.py	Fri Nov 06 19:48:57 2009 +0100
+++ b/frontends/wix/param.py	Fri Nov 06 23:31:00 2009 +0100
@@ -23,17 +23,15 @@
 
 import wx
 import pdb
+from xml.dom import minidom
 from logging import debug, info, error
 
 
 class Param(wx.Frame):
-    def __init__(self, setParam, getParam, getParams, getParamsCategories, title="Configuration"):
+    def __init__(self, bridge, title="Configuration"):
         super(Param, self).__init__(None, title=title)
 
-        self.setParam=setParam
-        self.getParam=getParam
-        self.getParams=getParams
-        self.getParamsCategories=getParamsCategories
+        self.bridge = bridge
 
         self.modified={}  # dict of modified data (i.e. what we have to save)
 
@@ -48,7 +46,7 @@
         
         self.MakeModal()
 
-        for category in self.getParamsCategories():
+        for category in self.bridge.getParamsCategories():
             self.addCategory(category)
         
         self.Show()
@@ -57,17 +55,22 @@
         panel=wx.Panel(self.notebook)
         panel.sizer = wx.BoxSizer(wx.VERTICAL)
 
-        for param in self.getParams(category):
+        cat_dom = minidom.parseString(self.bridge.getParamsForCategory(category))
+        
+        for param in cat_dom.documentElement.getElementsByTagName("param"):
+            name = param.getAttribute("name")
+            type = param.getAttribute("type")
+            value = param.getAttribute("value")
             sizer = wx.BoxSizer(wx.HORIZONTAL)
-            label=wx.StaticText(panel, -1, param[0]+" ")
-            if param[2]=="string":
-                ctrl = wx.TextCtrl(panel, -1, param[1])
-            elif param[2]=="password":
-                ctrl = wx.TextCtrl(panel, -1, param[1], style=wx.TE_PASSWORD)
+            label=wx.StaticText(panel, -1, name+" ")
+            if type=="string":
+                ctrl = wx.TextCtrl(panel, -1, value)
+            elif type=="password":
+                ctrl = wx.TextCtrl(panel, -1, value, style=wx.TE_PASSWORD)
             else:
                 error("FIXME FIXME FIXME")  #FIXME !
                 raise NotImplementedError
-            ctrl.param_id=(param[0], category)
+            ctrl.param_id=(name, category)
             sizer.Add(label)
             sizer.Add(ctrl, 1, flag=wx.EXPAND)
             panel.sizer.Add(sizer, flag=wx.EXPAND)
@@ -76,6 +79,7 @@
         panel.SetSizer(panel.sizer)
         panel.SetAutoLayout(True)
         self.notebook.AddPage(panel, category)
+        cat_dom.unlink()
 
     def onTextChanged(self, event):
         """Called when a paramated is modified"""
@@ -88,7 +92,7 @@
         debug("close")
         #now we save the modifier params
         for param in self.modified:
-            self.setParam(param[0], self.modified[param], param[1])
+            self.bridge.setParam(param[0], self.modified[param], param[1])
 
         self.MakeModal(False)
         event.Skip()