comparison frontends/src/tools/xmlui.py @ 1085:7a39ae3950f7

frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
author Goffi <goffi@goffi.org>
date Wed, 25 Jun 2014 14:01:56 +0200
parents d2e612a45e76
children 2cb30f46e560
comparison
equal deleted inserted replaced
1084:03dcb6ca7e49 1085:7a39ae3950f7
188 @main_cont.setter 188 @main_cont.setter
189 def main_cont(self, value): 189 def main_cont(self, value):
190 if self._main_cont is not None: 190 if self._main_cont is not None:
191 raise ValueError(_("XMLUI can have only one main container")) 191 raise ValueError(_("XMLUI can have only one main container"))
192 self._main_cont = value 192 self._main_cont = value
193
194 def _isAttrSet(self, name, node):
195 """Returnw widget boolean attribute status
196
197 @param name: name of the attribute (e.g. "read_only")
198 @param node: Node instance
199 @return (bool): True if widget's attribute is set ("true")
200 """
201 read_only = node.getAttribute(name) or "false"
202 return read_only.lower().strip() == "true"
193 203
194 def _parseChilds(self, parent, current_node, wanted = ('container',), data = None): 204 def _parseChilds(self, parent, current_node, wanted = ('container',), data = None):
195 """ Recursively parse childNodes of an elemen 205 """ Recursively parse childNodes of an elemen
196 @param parent: widget container with '_xmluiAppend' method 206 @param parent: widget container with '_xmluiAppend' method
197 @param current_node: element from which childs will be parsed 207 @param current_node: element from which childs will be parsed
287 ctrl = self.widget_factory.createJidWidget(parent, value) 297 ctrl = self.widget_factory.createJidWidget(parent, value)
288 elif type_=="divider": 298 elif type_=="divider":
289 style = node.getAttribute("style") or 'line' 299 style = node.getAttribute("style") or 'line'
290 ctrl = self.widget_factory.createDividerWidget(parent, style) 300 ctrl = self.widget_factory.createDividerWidget(parent, style)
291 elif type_=="string": 301 elif type_=="string":
292 ctrl = self.widget_factory.createStringWidget(parent, value) 302 ctrl = self.widget_factory.createStringWidget(parent, value, self._isAttrSet("read_only", node))
293 self.ctrl_list[name] = ({'type':type_, 'control':ctrl}) 303 self.ctrl_list[name] = ({'type':type_, 'control':ctrl})
294 elif type_=="password": 304 elif type_=="password":
295 ctrl = self.widget_factory.createPasswordWidget(parent, value) 305 ctrl = self.widget_factory.createPasswordWidget(parent, value, self._isAttrSet("read_only", node))
296 self.ctrl_list[name] = ({'type':type_, 'control':ctrl}) 306 self.ctrl_list[name] = ({'type':type_, 'control':ctrl})
297 elif type_=="textbox": 307 elif type_=="textbox":
298 ctrl = self.widget_factory.createTextBoxWidget(parent, value) 308 ctrl = self.widget_factory.createTextBoxWidget(parent, value, self._isAttrSet("read_only", node))
299 self.ctrl_list[name] = ({'type':type_, 'control':ctrl}) 309 self.ctrl_list[name] = ({'type':type_, 'control':ctrl})
300 elif type_=="bool": 310 elif type_=="bool":
301 ctrl = self.widget_factory.createBoolWidget(parent, value=='true') 311 ctrl = self.widget_factory.createBoolWidget(parent, value=='true', self._isAttrSet("read_only", node))
302 self.ctrl_list[name] = ({'type':type_, 'control':ctrl}) 312 self.ctrl_list[name] = ({'type':type_, 'control':ctrl})
303 elif type_ == "list": 313 elif type_ == "list":
304 style = [] if node.getAttribute("multi") == 'yes' else ['single'] 314 style = [] if node.getAttribute("multi") == 'yes' else ['single']
305 _options = [(option.getAttribute("value"), option.getAttribute("label")) for option in node.getElementsByTagName("option")] 315 _options = [(option.getAttribute("value"), option.getAttribute("label")) for option in node.getElementsByTagName("option")]
306 _selected = [option.getAttribute("value") for option in node.getElementsByTagName("option") if option.getAttribute('selected') == 'true'] 316 _selected = [option.getAttribute("value") for option in node.getElementsByTagName("option") if option.getAttribute('selected') == 'true']