Mercurial > libervia-backend
comparison tools/xml_tools.py @ 183:9ee4a1d0d7fb
Added auto(dis)connect params + misc
- parameters,xmlui: "bool" type is now managed
- parameters,xmlui: categories now use label in addition of name
- QuickFrontend: auto(dis)connection management
- plugin XEP-0045: an error dialog is now show in frontend if room cannot be joined
- Wix: fixed unproper close event management
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 18 Aug 2010 15:57:26 +0800 |
parents | f494cba56a9e |
children | e178e8f6d13a |
comparison
equal
deleted
inserted
replaced
182:556c2bd7c344 | 183:9ee4a1d0d7fb |
---|---|
79 error(_('INTERNAL ERROR: parameters xml not valid')) | 79 error(_('INTERNAL ERROR: parameters xml not valid')) |
80 assert(False) | 80 assert(False) |
81 param_ui = XMLUI("param", "tabs") | 81 param_ui = XMLUI("param", "tabs") |
82 for category in top.getElementsByTagName("category"): | 82 for category in top.getElementsByTagName("category"): |
83 name = category.getAttribute('name') | 83 name = category.getAttribute('name') |
84 label = category.getAttribute('label') | |
84 if not name: | 85 if not name: |
85 error(_('INTERNAL ERROR: params categories must have a name')) | 86 error(_('INTERNAL ERROR: params categories must have a name')) |
86 assert(False) | 87 assert(False) |
87 param_ui.addCategory(name, 'pairs') | 88 param_ui.addCategory(name, 'pairs', label=label) |
88 for param in category.getElementsByTagName("param"): | 89 for param in category.getElementsByTagName("param"): |
89 name = param.getAttribute('name') | 90 name = param.getAttribute('name') |
91 label = param.getAttribute('label') | |
90 if not name: | 92 if not name: |
91 error(_('INTERNAL ERROR: params must have a name')) | 93 error(_('INTERNAL ERROR: params must have a name')) |
92 assert(False) | 94 assert(False) |
93 type = param.getAttribute('type') | 95 type = param.getAttribute('type') |
94 value = param.getAttribute('value') or None | 96 value = param.getAttribute('value') or None |
95 callback_id = param.getAttribute('callback_id') or None | 97 callback_id = param.getAttribute('callback_id') or None |
96 if type == "button": | 98 if type == "button": |
97 param_ui.addEmpty() | 99 param_ui.addEmpty() |
98 else: | 100 else: |
99 param_ui.addLabel(name) | 101 param_ui.addLabel(label or name) |
100 param_ui.addElement(name=name, type=type, value=value, callback_id=callback_id) | 102 param_ui.addElement(name=name, type=type, value=value, callback_id=callback_id) |
101 | 103 |
102 return param_ui.toXml() | 104 return param_ui.toXml() |
103 | 105 |
104 | 106 |
207 """Add a string box""" | 209 """Add a string box""" |
208 elem = self.__createElem('textbox', name, self.currentLayout) | 210 elem = self.__createElem('textbox', name, self.currentLayout) |
209 if value: | 211 if value: |
210 elem.setAttribute('value', value) | 212 elem.setAttribute('value', value) |
211 | 213 |
214 def addBool(self, name=None, value="true"): | |
215 """Add a string box""" | |
216 assert value in ["true","false"] | |
217 elem = self.__createElem('bool', name, self.currentLayout) | |
218 elem.setAttribute('value', value) | |
219 | |
212 def addList(self, options, name=None, value=None, style=set()): | 220 def addList(self, options, name=None, value=None, style=set()): |
213 """Add a list of choices""" | 221 """Add a list of choices""" |
214 styles = set(style) | 222 styles = set(style) |
215 assert (options) | 223 assert (options) |
216 assert (styles.issubset(['multi'])) | 224 assert (styles.issubset(['multi'])) |
251 self.addString(name, value) | 259 self.addString(name, value) |
252 elif type == 'password': | 260 elif type == 'password': |
253 self.addPassword(name, value) | 261 self.addPassword(name, value) |
254 elif type == 'textbox': | 262 elif type == 'textbox': |
255 self.addTextBox(name, value) | 263 self.addTextBox(name, value) |
264 elif type == 'bool': | |
265 if not value: | |
266 value = "true" | |
267 self.addBool(name, value) | |
256 elif type == 'list': | 268 elif type == 'list': |
257 self.addList(options, name, value) | 269 self.addList(options, name, value) |
258 elif type == 'button': | 270 elif type == 'button': |
259 assert(callback_id and value) | 271 assert(callback_id and value) |
260 self.addButton(callback_id, name, value) | 272 self.addButton(callback_id, name, value) |
265 for option in options: | 277 for option in options: |
266 opt = self.doc.createElement('option') | 278 opt = self.doc.createElement('option') |
267 opt.setAttribute('value', option) | 279 opt.setAttribute('value', option) |
268 parent.appendChild(opt) | 280 parent.appendChild(opt) |
269 | 281 |
270 def addCategory(self, name, layout): | 282 def addCategory(self, name, layout, label=None): |
271 """Add a category to current layout (must be a tabs layout)""" | 283 """Add a category to current layout (must be a tabs layout)""" |
272 assert(layout != 'tabs') | 284 assert(layout != 'tabs') |
273 if not self.parentTabsLayout: | 285 if not self.parentTabsLayout: |
274 error(_("Trying to add a category without parent tabs layout")) | 286 error(_("Trying to add a category without parent tabs layout")) |
275 assert(False) | 287 assert(False) |
276 if self.parentTabsLayout.getAttribute('type') != 'tabs': | 288 if self.parentTabsLayout.getAttribute('type') != 'tabs': |
277 error(_("parent layout of a category is not tabs")) | 289 error(_("parent layout of a category is not tabs")) |
278 assert(False) | 290 assert(False) |
291 | |
292 if not label: | |
293 label = name | |
279 self.currentCategory = cat = self.doc.createElement('category') | 294 self.currentCategory = cat = self.doc.createElement('category') |
280 cat.setAttribute('name', name) | 295 cat.setAttribute('name', name) |
296 cat.setAttribute('label', label) | |
281 self.changeLayout(layout) | 297 self.changeLayout(layout) |
282 self.parentTabsLayout.appendChild(cat) | 298 self.parentTabsLayout.appendChild(cat) |
283 | 299 |
284 def toXml(self): | 300 def toXml(self): |
285 """return the XML representation of the panel""" | 301 """return the XML representation of the panel""" |