Mercurial > libervia-backend
comparison src/tools/xml_tools.py @ 1486:a77217511afd
tools, frontends (xmlui): allow to select a tab when adding it
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 21 Aug 2015 14:17:41 +0200 |
parents | 48706f4ff19c |
children | 0df627d0b4ca |
comparison
equal
deleted
inserted
replaced
1485:9fcc16ef163a | 1486:a77217511afd |
---|---|
379 | 379 |
380 class TabElement(Element): | 380 class TabElement(Element): |
381 """ Used by TabsContainer to give name and label to tabs.""" | 381 """ Used by TabsContainer to give name and label to tabs.""" |
382 type = 'tab' | 382 type = 'tab' |
383 | 383 |
384 def __init__(self, parent, name, label): | 384 def __init__(self, parent, name, label, selected=False): |
385 """ | |
386 | |
387 @param parent (TabsContainer): parent container | |
388 @param name (unicode): tab name | |
389 @param label (unicode): tab label | |
390 @param selected (bool): set to True to select this tab | |
391 """ | |
385 if not isinstance(parent, TabsContainer): | 392 if not isinstance(parent, TabsContainer): |
386 raise exceptions.DataError(_("TabElement must be a child of TabsContainer")) | 393 raise exceptions.DataError(_("TabElement must be a child of TabsContainer")) |
387 super(TabElement, self).__init__(parent.xmlui, parent) | 394 super(TabElement, self).__init__(parent.xmlui, parent) |
388 self.elem.setAttribute('name', name) | 395 self.elem.setAttribute('name', name) |
389 self.elem.setAttribute('label', label) | 396 self.elem.setAttribute('label', label) |
397 if selected: | |
398 self.setSelected(selected) | |
399 | |
400 def setSelected(self, selected=False): | |
401 """Set the tab selected. | |
402 | |
403 @param selected (bool): set to True to select this tab | |
404 """ | |
405 self.elem.setAttribute('selected', 'true' if selected else 'false') | |
390 | 406 |
391 | 407 |
392 class FieldBackElement(Element): | 408 class FieldBackElement(Element): |
393 """ Used by ButtonWidget to indicate which field have to be sent back """ | 409 """ Used by ButtonWidget to indicate which field have to be sent back """ |
394 type = 'field_back' | 410 type = 'field_back' |
541 | 557 |
542 | 558 |
543 class TabsContainer(Container): | 559 class TabsContainer(Container): |
544 type = "tabs" | 560 type = "tabs" |
545 | 561 |
546 def addTab(self, name, label=None, container=VerticalContainer): | 562 def addTab(self, name, label=None, selected=None, container=VerticalContainer): |
547 """Add a tab""" | 563 """Add a tab. |
564 | |
565 @param name (unicode): tab name | |
566 @param label (unicode): tab label | |
567 @param selected (bool): set to True to select this tab | |
568 @param container (class): container class, inheriting from Container | |
569 @return: the container for the new tab | |
570 """ | |
548 if not label: | 571 if not label: |
549 label = name | 572 label = name |
550 tab_elt = TabElement(self, name, label) | 573 tab_elt = TabElement(self, name, label, selected) |
551 new_container = container(self.xmlui, tab_elt) | 574 new_container = container(self.xmlui, tab_elt) |
552 self.xmlui.changeContainer(new_container) | 575 return self.xmlui.changeContainer(new_container) |
553 | 576 |
554 def end(self): | 577 def end(self): |
555 """ Called when we have finished tabs | 578 """ Called when we have finished tabs |
556 | 579 |
557 change current container to first container parent | 580 change current container to first container parent |