comparison 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
comparison
equal deleted inserted replaced
17:74a39f40eb6d 18:6928e3cb73a8
21 21
22 22
23 23
24 import wx 24 import wx
25 import pdb 25 import pdb
26 from xml.dom import minidom
26 from logging import debug, info, error 27 from logging import debug, info, error
27 28
28 29
29 class Param(wx.Frame): 30 class Param(wx.Frame):
30 def __init__(self, setParam, getParam, getParams, getParamsCategories, title="Configuration"): 31 def __init__(self, bridge, title="Configuration"):
31 super(Param, self).__init__(None, title=title) 32 super(Param, self).__init__(None, title=title)
32 33
33 self.setParam=setParam 34 self.bridge = bridge
34 self.getParam=getParam
35 self.getParams=getParams
36 self.getParamsCategories=getParamsCategories
37 35
38 self.modified={} # dict of modified data (i.e. what we have to save) 36 self.modified={} # dict of modified data (i.e. what we have to save)
39 37
40 self.sizer = wx.BoxSizer(wx.VERTICAL) 38 self.sizer = wx.BoxSizer(wx.VERTICAL)
41 self.notebook=wx.Notebook(self, -1, style=wx.NB_LEFT) 39 self.notebook=wx.Notebook(self, -1, style=wx.NB_LEFT)
46 #events 44 #events
47 self.Bind(wx.EVT_CLOSE, self.onClose, self) 45 self.Bind(wx.EVT_CLOSE, self.onClose, self)
48 46
49 self.MakeModal() 47 self.MakeModal()
50 48
51 for category in self.getParamsCategories(): 49 for category in self.bridge.getParamsCategories():
52 self.addCategory(category) 50 self.addCategory(category)
53 51
54 self.Show() 52 self.Show()
55 53
56 def addCategory(self, category): 54 def addCategory(self, category):
57 panel=wx.Panel(self.notebook) 55 panel=wx.Panel(self.notebook)
58 panel.sizer = wx.BoxSizer(wx.VERTICAL) 56 panel.sizer = wx.BoxSizer(wx.VERTICAL)
59 57
60 for param in self.getParams(category): 58 cat_dom = minidom.parseString(self.bridge.getParamsForCategory(category))
59
60 for param in cat_dom.documentElement.getElementsByTagName("param"):
61 name = param.getAttribute("name")
62 type = param.getAttribute("type")
63 value = param.getAttribute("value")
61 sizer = wx.BoxSizer(wx.HORIZONTAL) 64 sizer = wx.BoxSizer(wx.HORIZONTAL)
62 label=wx.StaticText(panel, -1, param[0]+" ") 65 label=wx.StaticText(panel, -1, name+" ")
63 if param[2]=="string": 66 if type=="string":
64 ctrl = wx.TextCtrl(panel, -1, param[1]) 67 ctrl = wx.TextCtrl(panel, -1, value)
65 elif param[2]=="password": 68 elif type=="password":
66 ctrl = wx.TextCtrl(panel, -1, param[1], style=wx.TE_PASSWORD) 69 ctrl = wx.TextCtrl(panel, -1, value, style=wx.TE_PASSWORD)
67 else: 70 else:
68 error("FIXME FIXME FIXME") #FIXME ! 71 error("FIXME FIXME FIXME") #FIXME !
69 raise NotImplementedError 72 raise NotImplementedError
70 ctrl.param_id=(param[0], category) 73 ctrl.param_id=(name, category)
71 sizer.Add(label) 74 sizer.Add(label)
72 sizer.Add(ctrl, 1, flag=wx.EXPAND) 75 sizer.Add(ctrl, 1, flag=wx.EXPAND)
73 panel.sizer.Add(sizer, flag=wx.EXPAND) 76 panel.sizer.Add(sizer, flag=wx.EXPAND)
74 77
75 panel.Bind(wx.EVT_TEXT, self.onTextChanged, ctrl) 78 panel.Bind(wx.EVT_TEXT, self.onTextChanged, ctrl)
76 panel.SetSizer(panel.sizer) 79 panel.SetSizer(panel.sizer)
77 panel.SetAutoLayout(True) 80 panel.SetAutoLayout(True)
78 self.notebook.AddPage(panel, category) 81 self.notebook.AddPage(panel, category)
82 cat_dom.unlink()
79 83
80 def onTextChanged(self, event): 84 def onTextChanged(self, event):
81 """Called when a paramated is modified""" 85 """Called when a paramated is modified"""
82 self.modified[event.GetEventObject().param_id]=event.GetString() 86 self.modified[event.GetEventObject().param_id]=event.GetString()
83 event.Skip() 87 event.Skip()
86 def onClose(self, event): 90 def onClose(self, event):
87 """Close event: we have to save the params.""" 91 """Close event: we have to save the params."""
88 debug("close") 92 debug("close")
89 #now we save the modifier params 93 #now we save the modifier params
90 for param in self.modified: 94 for param in self.modified:
91 self.setParam(param[0], self.modified[param], param[1]) 95 self.bridge.setParam(param[0], self.modified[param], param[1])
92 96
93 self.MakeModal(False) 97 self.MakeModal(False)
94 event.Skip() 98 event.Skip()
95 99