comparison frontends/src/wix/param.py @ 545:8f88ae7ed886

wix: fixed parameters management
author Goffi <goffi@goffi.org>
date Wed, 14 Nov 2012 21:30:21 +0100
parents 2a072735e459
children ca13633d3b6b
comparison
equal deleted inserted replaced
544:899bd6fc7580 545:8f88ae7ed886
55 55
56 def addCategory(self, category): 56 def addCategory(self, category):
57 panel=wx.Panel(self.notebook) 57 panel=wx.Panel(self.notebook)
58 panel.sizer = wx.BoxSizer(wx.VERTICAL) 58 panel.sizer = wx.BoxSizer(wx.VERTICAL)
59 59
60 cat_dom = minidom.parseString(self.host.bridge.getParamsForCategory(category, profile_key = self.host.profile).encode('utf-8')) 60 def errorGettingParams(ignore):
61 61 wx.MessageDialog(self, _("Can't get parameters"), _("Parameters error"), wx.ICON_ERROR).ShowModal()
62 for param in cat_dom.documentElement.getElementsByTagName("param"):
63 name = param.getAttribute("name")
64 label = param.getAttribute("label")
65 type = param.getAttribute("type")
66 value = param.getAttribute("value")
67 sizer = wx.BoxSizer(wx.HORIZONTAL)
68 if type=="string":
69 label=wx.StaticText(panel, -1, (label or name)+" ")
70 ctrl = wx.TextCtrl(panel, -1, value)
71 sizer.Add(label)
72 elif type=="password":
73 label=wx.StaticText(panel, -1, (label or name)+" ")
74 ctrl = wx.TextCtrl(panel, -1, value, style=wx.TE_PASSWORD)
75 sizer.Add(label)
76 elif type=="bool":
77 ctrl = wx.CheckBox(panel, -1, label or name, style = wx.CHK_2STATE)
78 ctrl.SetValue(value=="true")
79 elif type=="button":
80 ctrl = wx.Button(panel, -1, value)
81 ctrl.callback_id = param.getAttribute("callback_id")
82 else:
83 error(_("FIXME FIXME FIXME")) #FIXME !
84 raise NotImplementedError
85 if name:
86 ctrl.param_id=(name, category)
87 self.ctl_list[(name, category)] = ctrl
88 sizer.Add(ctrl, 1, flag=wx.EXPAND)
89 panel.sizer.Add(sizer, flag=wx.EXPAND)
90 62
91 if type=="string" or type=="password": 63 def gotParams(result):
92 panel.Bind(wx.EVT_TEXT, self.onTextChanged, ctrl) 64 cat_dom = minidom.parseString(result.encode('utf-8'))
93 elif type=="bool": 65
94 panel.Bind(wx.EVT_CHECKBOX, self.onCheckBoxClicked, ctrl) 66 for param in cat_dom.documentElement.getElementsByTagName("param"):
95 elif type=="button": 67 name = param.getAttribute("name")
96 panel.Bind(wx.EVT_BUTTON, self.onButtonClicked, ctrl) 68 label = param.getAttribute("label")
69 type = param.getAttribute("type")
70 value = param.getAttribute("value")
71 sizer = wx.BoxSizer(wx.HORIZONTAL)
72 if type=="string":
73 label=wx.StaticText(panel, -1, (label or name)+" ")
74 ctrl = wx.TextCtrl(panel, -1, value)
75 sizer.Add(label)
76 elif type=="password":
77 label=wx.StaticText(panel, -1, (label or name)+" ")
78 ctrl = wx.TextCtrl(panel, -1, value, style=wx.TE_PASSWORD)
79 sizer.Add(label)
80 elif type=="bool":
81 ctrl = wx.CheckBox(panel, -1, label or name, style = wx.CHK_2STATE)
82 ctrl.SetValue(value=="true")
83 elif type=="button":
84 ctrl = wx.Button(panel, -1, value)
85 ctrl.callback_id = param.getAttribute("callback_id")
86 else:
87 error(_("FIXME FIXME FIXME")) #FIXME !
88 raise NotImplementedError
89 if name:
90 ctrl.param_id=(name, category)
91 self.ctl_list[(name, category)] = ctrl
92 sizer.Add(ctrl, 1, flag=wx.EXPAND)
93 panel.sizer.Add(sizer, flag=wx.EXPAND)
97 94
98 panel.SetSizer(panel.sizer) 95 if type=="string" or type=="password":
99 panel.SetAutoLayout(True) 96 panel.Bind(wx.EVT_TEXT, self.onTextChanged, ctrl)
100 self.notebook.AddPage(panel, category) 97 elif type=="bool":
101 cat_dom.unlink() 98 panel.Bind(wx.EVT_CHECKBOX, self.onCheckBoxClicked, ctrl)
99 elif type=="button":
100 panel.Bind(wx.EVT_BUTTON, self.onButtonClicked, ctrl)
101
102 panel.SetSizer(panel.sizer)
103 panel.SetAutoLayout(True)
104 self.notebook.AddPage(panel, category)
105 cat_dom.unlink()
106
107 self.host.bridge.getParamsForCategory(category, profile_key = self.host.profile, callback = gotParams, errback = errorGettingParams)
102 108
103 def onTextChanged(self, event): 109 def onTextChanged(self, event):
104 """Called when a string paramater is modified""" 110 """Called when a string paramater is modified"""
105 self.modified[event.GetEventObject().param_id]=event.GetString() 111 self.modified[event.GetEventObject().param_id]=event.GetString()
106 112