Mercurial > libervia-backend
diff 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 |
line wrap: on
line diff
--- a/src/tools/xml_tools.py Fri Aug 21 19:23:14 2015 +0200 +++ b/src/tools/xml_tools.py Fri Aug 21 14:17:41 2015 +0200 @@ -381,12 +381,28 @@ """ Used by TabsContainer to give name and label to tabs.""" type = 'tab' - def __init__(self, parent, name, label): + def __init__(self, parent, name, label, selected=False): + """ + + @param parent (TabsContainer): parent container + @param name (unicode): tab name + @param label (unicode): tab label + @param selected (bool): set to True to select this tab + """ if not isinstance(parent, TabsContainer): raise exceptions.DataError(_("TabElement must be a child of TabsContainer")) super(TabElement, self).__init__(parent.xmlui, parent) self.elem.setAttribute('name', name) self.elem.setAttribute('label', label) + if selected: + self.setSelected(selected) + + def setSelected(self, selected=False): + """Set the tab selected. + + @param selected (bool): set to True to select this tab + """ + self.elem.setAttribute('selected', 'true' if selected else 'false') class FieldBackElement(Element): @@ -543,13 +559,20 @@ class TabsContainer(Container): type = "tabs" - def addTab(self, name, label=None, container=VerticalContainer): - """Add a tab""" + def addTab(self, name, label=None, selected=None, container=VerticalContainer): + """Add a tab. + + @param name (unicode): tab name + @param label (unicode): tab label + @param selected (bool): set to True to select this tab + @param container (class): container class, inheriting from Container + @return: the container for the new tab + """ if not label: label = name - tab_elt = TabElement(self, name, label) + tab_elt = TabElement(self, name, label, selected) new_container = container(self.xmlui, tab_elt) - self.xmlui.changeContainer(new_container) + return self.xmlui.changeContainer(new_container) def end(self): """ Called when we have finished tabs