comparison src/tools/xml_tools.py @ 1475:7ac073d2e7e0

core(xmlui): removed useless parenthesis around assert
author Goffi <goffi@goffi.org>
date Tue, 18 Aug 2015 10:52:18 +0200
parents 675e0e9f1653
children 48706f4ff19c
comparison
equal deleted inserted replaced
1474:c2a498dce4b4 1475:7ac073d2e7e0
336 """Create a container element 336 """Create a container element
337 337
338 @param xmlui: XMLUI instance 338 @param xmlui: XMLUI instance
339 @parent: parent element 339 @parent: parent element
340 """ 340 """
341 assert(self.type) is not None 341 assert self.type is not None
342 if not hasattr(self, 'elem'): 342 if not hasattr(self, 'elem'):
343 self.elem = parent.xmlui.doc.createElement(self.type) 343 self.elem = parent.xmlui.doc.createElement(self.type)
344 self.xmlui = xmlui 344 self.xmlui = xmlui
345 if parent is not None: 345 if parent is not None:
346 parent.append(self) 346 parent.append(self)
375 class FieldBackElement(Element): 375 class FieldBackElement(Element):
376 """ Used by ButtonWidget to indicate which field have to be sent back """ 376 """ Used by ButtonWidget to indicate which field have to be sent back """
377 type = 'field_back' 377 type = 'field_back'
378 378
379 def __init__(self, parent, name): 379 def __init__(self, parent, name):
380 assert(isinstance(parent, ButtonWidget)) 380 assert isinstance(parent, ButtonWidget)
381 super(FieldBackElement, self).__init__(parent.xmlui, parent) 381 super(FieldBackElement, self).__init__(parent.xmlui, parent)
382 self.elem.setAttribute('name', name) 382 self.elem.setAttribute('name', name)
383 383
384 384
385 class InternalFieldElement(Element): 385 class InternalFieldElement(Element):
395 """ Used by internal callbacks to retrieve extra data """ 395 """ Used by internal callbacks to retrieve extra data """
396 type = 'internal_data' 396 type = 'internal_data'
397 397
398 def __init__(self, parent, children): 398 def __init__(self, parent, children):
399 super(InternalDataElement, self).__init__(parent.xmlui, parent) 399 super(InternalDataElement, self).__init__(parent.xmlui, parent)
400 assert(isinstance(children, list)) 400 assert isinstance(children, list)
401 for child in children: 401 for child in children:
402 self.elem.childNodes.append(child) 402 self.elem.childNodes.append(child)
403 403
404 404
405 class OptionElement(Element): 405 class OptionElement(Element):
411 411
412 @param parent 412 @param parent
413 @param option (string, tuple) 413 @param option (string, tuple)
414 @param selected (boolean) 414 @param selected (boolean)
415 """ 415 """
416 assert(isinstance(parent, ListWidget)) 416 assert isinstance(parent, ListWidget)
417 super(OptionElement, self).__init__(parent.xmlui, parent) 417 super(OptionElement, self).__init__(parent.xmlui, parent)
418 if isinstance(option, basestring): 418 if isinstance(option, basestring):
419 value, label = option, option 419 value, label = option, option
420 elif isinstance(option, tuple): 420 elif isinstance(option, tuple):
421 value, label = option 421 value, label = option
430 class RowElement(Element): 430 class RowElement(Element):
431 """" Used by AdvancedListContainer """ 431 """" Used by AdvancedListContainer """
432 type = 'row' 432 type = 'row'
433 433
434 def __init__(self, parent): 434 def __init__(self, parent):
435 assert(isinstance(parent, AdvancedListContainer)) 435 assert isinstance(parent, AdvancedListContainer)
436 super(RowElement, self).__init__(parent.xmlui, parent) 436 super(RowElement, self).__init__(parent.xmlui, parent)
437 if parent.next_row_idx is not None: 437 if parent.next_row_idx is not None:
438 if parent.auto_index: 438 if parent.auto_index:
439 raise exceptions.DataError(_("Can't set row index if auto_index is True")) 439 raise exceptions.DataError(_("Can't set row index if auto_index is True"))
440 self.elem.setAttribute('index', parent.next_row_idx) 440 self.elem.setAttribute('index', parent.next_row_idx)
450 @param parent: AdvancedListContainer instance 450 @param parent: AdvancedListContainer instance
451 @param name: name of the container 451 @param name: name of the container
452 @param label: label to be displayed in columns 452 @param label: label to be displayed in columns
453 @param description: long descriptive text 453 @param description: long descriptive text
454 """ 454 """
455 assert(isinstance(parent, AdvancedListContainer)) 455 assert isinstance(parent, AdvancedListContainer)
456 super(HeaderElement, self).__init__(parent.xmlui, parent) 456 super(HeaderElement, self).__init__(parent.xmlui, parent)
457 if name: 457 if name:
458 self.elem.setAttribute('name', name) 458 self.elem.setAttribute('name', name)
459 if label: 459 if label:
460 self.elem.setAttribute('label', label) 460 self.elem.setAttribute('label', label)
828 if isinstance(selected, basestring): 828 if isinstance(selected, basestring):
829 selected = [selected] 829 selected = [selected]
830 else: 830 else:
831 selected = [] 831 selected = []
832 for option in options: 832 for option in options:
833 assert(isinstance(option, basestring) or isinstance(option, tuple)) 833 assert isinstance(option, basestring) or isinstance(option, tuple)
834 value = option if isinstance(option, basestring) else option[0] 834 value = option if isinstance(option, basestring) else option[0]
835 OptionElement(self, option, value in selected) 835 OptionElement(self, option, value in selected)
836 836
837 837
838 ## Dialog Elements ## 838 ## Dialog Elements ##
1071 or an Container instance""" 1071 or an Container instance"""
1072 if isinstance(container, basestring): 1072 if isinstance(container, basestring):
1073 self.current_container = self._createContainer(container, self.current_container.getParentContainer() or self.main_container, **kwargs) 1073 self.current_container = self._createContainer(container, self.current_container.getParentContainer() or self.main_container, **kwargs)
1074 else: 1074 else:
1075 self.current_container = self.main_container if container is None else container 1075 self.current_container = self.main_container if container is None else container
1076 assert(isinstance(self.current_container, Container)) 1076 assert isinstance(self.current_container, Container)
1077 return self.current_container 1077 return self.current_container
1078 1078
1079 def addWidget(self, type_, *args, **kwargs): 1079 def addWidget(self, type_, *args, **kwargs):
1080 """Convenience method to add an element""" 1080 """Convenience method to add an element"""
1081 if type_ not in self._widgets: 1081 if type_ not in self._widgets: