comparison tools/xml_tools.py @ 106:138d82f64b6f

plugin CS: friends parsing
author Goffi <goffi@goffi.org>
date Sat, 26 Jun 2010 15:33:16 +0800
parents d2630fba8dfd
children 5ae370c71803
comparison
equal deleted inserted replaced
105:d2630fba8dfd 106:138d82f64b6f
86 if not name: 86 if not name:
87 error(_('INTERNAL ERROR: params must have a name')) 87 error(_('INTERNAL ERROR: params must have a name'))
88 assert(False) 88 assert(False)
89 type = param.getAttribute('type') 89 type = param.getAttribute('type')
90 value = param.getAttribute('value') or None 90 value = param.getAttribute('value') or None
91 callback = param.getAttribute('callback') or None 91 callback_id = param.getAttribute('callback_id') or None
92 param_ui.addLabel(name) 92 if type == "button":
93 param_ui.addElement(name=name, type=type, value=value, callback=callback) 93 param_ui.addEmpty()
94 else:
95 param_ui.addLabel(name)
96 param_ui.addElement(name=name, type=type, value=value, callback_id=callback_id)
94 97
95 return param_ui.toXml() 98 return param_ui.toXml()
96 99
97 100
98 101
198 elem = self.__createElem('list', name, self.currentLayout) 201 elem = self.__createElem('list', name, self.currentLayout)
199 self.addOptions(options, elem) 202 self.addOptions(options, elem)
200 if value: 203 if value:
201 elem.setAttribute('value', value) 204 elem.setAttribute('value', value)
202 205
203 def addButton(self, callback, name): 206 def addButton(self, callback_id, name, value):
204 """Add a button 207 """Add a button
205 @param callback: callback which will be called if button is pressed 208 @param callback: callback which will be called if button is pressed
206 @param name: name shown on the button""" 209 @param name: name
210 @param value: label of the button"""
207 elem = self.__createElem('button', name, self.currentLayout) 211 elem = self.__createElem('button', name, self.currentLayout)
208 elem.setAttribute('callback', callback) 212 elem.setAttribute('callback_id', callback_id)
209 213 if value:
210 214 elem.setAttribute('value', value)
211 def addElement(self, type, name = None, content = None, value = None, options = None, callback = None): 215
216
217 def addElement(self, type, name = None, content = None, value = None, options = None, callback_id = None):
212 """Convenience method to add element, the params correspond to the ones in addSomething methods""" 218 """Convenience method to add element, the params correspond to the ones in addSomething methods"""
213 if type == 'empty': 219 if type == 'empty':
214 self.addEmpty(name) 220 self.addEmpty(name)
215 elif type == 'text': 221 elif type == 'text':
216 assert(content) 222 assert(content)
222 elif type == 'password': 228 elif type == 'password':
223 self.addPassword(name, value) 229 self.addPassword(name, value)
224 elif type == 'list': 230 elif type == 'list':
225 self.addList(options, name, value) 231 self.addList(options, name, value)
226 elif type == 'button': 232 elif type == 'button':
227 assert(callback and name) 233 assert(callback_id and value)
228 self.addButton(callback, name) 234 self.addButton(callback_id, name, value)
229 235
230 def addOptions(self, options, parent): 236 def addOptions(self, options, parent):
231 """Add options to a multi-values element (e.g. list) 237 """Add options to a multi-values element (e.g. list)
232 @param parent: multi-values element""" 238 @param parent: multi-values element"""
233 for option in options: 239 for option in options: