comparison frontends/wix/xmlui.py @ 107:5ae370c71803

CS: message sending is now working - xmltools/xmlui: buttons can now send fields of the ui when used - xmltools/xmlui: new textbox element, to write a large text (used for messages in CS plugin) - xmltools/xmlui: list have now an attribute multi for selecting several options - xmltools/xmlui: window title can now be specified in the xml (attribute title) - CS_plugin: message sending interface & management
author Goffi <goffi@goffi.org>
date Mon, 28 Jun 2010 15:18:59 +0800
parents 138d82f64b6f
children 7452ac3818e7
comparison
equal deleted inserted replaced
106:138d82f64b6f 107:5ae370c71803
36 super(XMLUI, self).__init__(None, title=title, style=style) 36 super(XMLUI, self).__init__(None, title=title, style=style)
37 37
38 self.host = host 38 self.host = host
39 self.options = options 39 self.options = options
40 self.misc = misc 40 self.misc = misc
41 self.ctl_list = [] # usefull to access ctrl 41 self.ctrl_list = {} # usefull to access ctrl
42 42
43 self.sizer = wx.BoxSizer(wx.VERTICAL) 43 self.sizer = wx.BoxSizer(wx.VERTICAL)
44 self.SetSizer(self.sizer) 44 self.SetSizer(self.sizer)
45 self.SetAutoLayout(True) 45 self.SetAutoLayout(True)
46 46
76 ctrl = wx.StaticText(parent, -1, value) 76 ctrl = wx.StaticText(parent, -1, value)
77 elif type=="label": 77 elif type=="label":
78 ctrl = wx.StaticText(parent, -1, value+": ") 78 ctrl = wx.StaticText(parent, -1, value+": ")
79 elif type=="string": 79 elif type=="string":
80 ctrl = wx.TextCtrl(parent, -1, value) 80 ctrl = wx.TextCtrl(parent, -1, value)
81 self.ctl_list.append({'name':name, 'type':type, 'control':ctrl}) 81 self.ctrl_list[name] = ({'type':type, 'control':ctrl})
82 _proportion = 1 82 _proportion = 1
83 elif type=="password": 83 elif type=="password":
84 ctrl = wx.TextCtrl(parent, -1, value, style=wx.TE_PASSWORD) 84 ctrl = wx.TextCtrl(parent, -1, value, style=wx.TE_PASSWORD)
85 self.ctl_list.append({'name':name, 'type':type, 'control':ctrl}) 85 self.ctrl_list[name] = ({'type':type, 'control':ctrl})
86 _proportion = 1
87 elif type=="textbox":
88 ctrl = wx.TextCtrl(parent, -1, value, style=wx.TE_MULTILINE)
89 self.ctrl_list[name] = ({'type':type, 'control':ctrl})
86 _proportion = 1 90 _proportion = 1
87 elif type=="list": 91 elif type=="list":
88 ctrl = wx.ListBox(parent, -1, choices=[option.getAttribute("value") for option in elem.getElementsByTagName("option")], style=wx.LB_SINGLE) 92 style=wx.LB_MULTIPLE if elem.getAttribute("multi")=='yes' else wx.LB_SINGLE
89 self.ctl_list.append({'name':name, 'type':type, 'control':ctrl}) 93 ctrl = wx.ListBox(parent, -1, choices=[option.getAttribute("value") for option in elem.getElementsByTagName("option")], style=style)
94 self.ctrl_list[name] = ({'type':type, 'control':ctrl})
90 _proportion = 1 95 _proportion = 1
91 elif type=="button": 96 elif type=="button":
92 callback_id = elem.getAttribute("callback_id") 97 callback_id = elem.getAttribute("callback_id")
93 ctrl = wx.Button(parent, -1, value) 98 ctrl = wx.Button(parent, -1, value)
94 ctrl.param_id = callback_id 99 ctrl.param_id = (callback_id,[field.getAttribute('name') for field in elem.getElementsByTagName("field_back")])
95 parent.Bind(wx.EVT_BUTTON, self.onButtonClicked, ctrl) 100 parent.Bind(wx.EVT_BUTTON, self.onButtonClicked, ctrl)
96 else: 101 else:
97 error(_("FIXME FIXME FIXME: type [%s] is not implemented") % type) #FIXME ! 102 error(_("FIXME FIXME FIXME: type [%s] is not implemented") % type) #FIXME !
98 raise NotImplementedError 103 raise NotImplementedError
99 parent.sizer.Add(ctrl, _proportion, flag=wx.EXPAND) 104 parent.sizer.Add(ctrl, _proportion, flag=wx.EXPAND)
153 panel.sizer = wx.BoxSizer(wx.VERTICAL) 158 panel.sizer = wx.BoxSizer(wx.VERTICAL)
154 159
155 cat_dom = minidom.parseString(xml_data.encode('utf-8')) 160 cat_dom = minidom.parseString(xml_data.encode('utf-8'))
156 top= cat_dom.documentElement 161 top= cat_dom.documentElement
157 self.type = top.getAttribute("type") 162 self.type = top.getAttribute("type")
163 self.title = top .getAttribute("title")
164 if self.title:
165 self.SetTitle(self.title)
158 if top.nodeName != "sat_xmlui" or not self.type in ['form', 'param', 'window']: 166 if top.nodeName != "sat_xmlui" or not self.type in ['form', 'param', 'window']:
159 raise Exception("Invalid XMLUI") #TODO: make a custom exception 167 raise Exception("Invalid XMLUI") #TODO: make a custom exception
160 168
161 self.__parseChilds(panel, None, cat_dom.documentElement) 169 self.__parseChilds(panel, None, cat_dom.documentElement)
162 170
180 188
181 ###events 189 ###events
182 190
183 def onButtonClicked(self, event): 191 def onButtonClicked(self, event):
184 """Called when a button is pushed""" 192 """Called when a button is pushed"""
185 callback_id = event.GetEventObject().param_id 193 callback_id, fields = event.GetEventObject().param_id
186 data = {"callback_id":callback_id} 194 data = {"callback_id":callback_id}
195 for field in fields:
196 ctrl = self.ctrl_list[field]
197 if isinstance(ctrl['control'], wx.ListBox):
198 data[field] = '\t'.join([ctrl['control'].GetString(idx) for idx in ctrl['control'].GetSelections()])
199 else:
200 data[field] = ctrl['control'].GetValue()
201
187 id = self.host.bridge.launchAction("button", data) 202 id = self.host.bridge.launchAction("button", data)
188 self.host.current_action_ids.add(id) 203 self.host.current_action_ids.add(id)
189 event.Skip() 204 event.Skip()
190 205
191 def onFormSubmitted(self, event): 206 def onFormSubmitted(self, event):
192 """Called when submit button is clicked""" 207 """Called when submit button is clicked"""
193 debug(_("Submitting form")) 208 debug(_("Submitting form"))
194 data = [] 209 data = []
195 for ctrl in self.ctl_list: 210 for ctrl_name in self.ctrl_list:
211 ctrl = self.ctrl_list[ctrl_name]
196 if isinstance(ctrl['control'], wx.ListBox): 212 if isinstance(ctrl['control'], wx.ListBox):
197 data.append((ctrl['name'], ctrl['control'].GetStringSelection())) 213 data.append((ctrl_name, ctrl['control'].GetStringSelection()))
198 else: 214 else:
199 data.append((ctrl["name"], ctrl["control"].GetValue())) 215 data.append((ctrl_name, ctrl['control'].GetValue()))
200 if self.misc.has_key('action_back'): #FIXME FIXME FIXME: WTF ! Must be cleaned 216 if self.misc.has_key('action_back'): #FIXME FIXME FIXME: WTF ! Must be cleaned
201 id = self.misc['action_back']("SUBMIT",self.misc['target'], data) 217 id = self.misc['action_back']("SUBMIT",self.misc['target'], data)
202 self.host.current_action_ids.add(id) 218 self.host.current_action_ids.add(id)
203 elif self.misc.has_key('callback'): 219 elif self.misc.has_key('callback'):
204 self.misc['callback'](data) 220 self.misc['callback'](data)