Mercurial > libervia-web
changeset 620:ac5881d683d3 frontends_multi_profiles
browser_side: move SatWebFrontend.addTab to MainTabPanel.addWidgetsTab and rename MainTabPanel.add to MainTabPanel.addTab
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 20 Feb 2015 19:38:11 +0100 |
parents | 11a0a32144a5 |
children | b77e1070035c |
files | src/browser/libervia_main.py src/browser/sat_browser/base_widget.py src/browser/sat_browser/panels.py |
diffstat | 3 files changed, 37 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/src/browser/libervia_main.py Fri Feb 20 19:50:00 2015 +0100 +++ b/src/browser/libervia_main.py Fri Feb 20 19:38:11 2015 +0100 @@ -80,7 +80,6 @@ self.uni_box = None # FIXME: to be removed self.status_panel = HTML('<br />') self.panel = panels.MainPanel(self) - self.discuss_panel = self.panel.discuss_panel self.tab_panel = self.panel.tab_panel self.tab_panel.addTabListener(self) self._register_box = None @@ -234,25 +233,6 @@ lib_wid.refresh() self.resize() - def addTab(self, label, wid=None, select=False): - """Create a new tab and eventually add a widget to it. - - @param label (unicode): label of the tab - @param wid (LiberviaWidget): optional widget to add - @param select (bool): True to select the added tab - @return: WidgetsPanel - """ - widgets_panel = base_widget.WidgetsPanel(self) - self.tab_panel.add(widgets_panel, label) - tab_index = self.tab_panel.getWidgetCount() - 1 - if wid is not None: - self.addWidget(wid, tab_index) - if select: - self.tab_panel.selectTab(tab_index) - if wid is not None: - self.setSelected(wid) - return widgets_panel - def addWidget(self, wid, tab_index=None): """ Add a widget at the bottom of the current or specified tab @@ -606,7 +586,8 @@ kwargs['on_new_widget'] = None kwargs['on_existing_widget'] = C.WIDGET_RECREATE wid = self.widgets.getOrCreateWidget(class_, target, *args, **kwargs) - self.addTab(new_tab, wid) + self.tab_panel.addWidgetsTab(new_tab) + self.addWidget(wid) return wid kwargs['on_existing_widget'] = C.WIDGET_RAISE
--- a/src/browser/sat_browser/base_widget.py Fri Feb 20 19:50:00 2015 +0100 +++ b/src/browser/sat_browser/base_widget.py Fri Feb 20 19:38:11 2015 +0100 @@ -587,10 +587,17 @@ class WidgetsPanel(ScrollPanelWrapper): def __init__(self, host, locked=False): + """ + + @param host (SatWebFrontend): host instance + @param locked (bool): If True, the tab containing self will not be + removed when there are no more widget inside self. If False, the + tab will be removed with self's last widget. + """ ScrollPanelWrapper.__init__(self) self.setSize('100%', '100%') self.host = host - self.locked = locked # if True: tab will not be removed when there are no more widgets inside + self.locked = locked self.selected = None self.flextable = FlexTable() self.flextable.setSize('100%', '100%') @@ -831,7 +838,7 @@ label = default_label except: # this happens when the user prevents the page to open the prompt dialog label = default_label - self.host.addTab(label, select=True) + self.addWidgetsTab(label, select=True) def getCurrentPanel(self): """ Get the panel of the currently selected tab @@ -853,9 +860,30 @@ self.setWidth("%s%s" % (ideal_width, "px")) self.setHeight("%s%s" % (ideal_height, "px")) - def add(self, widget, text=''): - tab = DropTab(self, text) - TabPanel.add(self, widget, tab, False) + def addTab(self, widget, label, select=False): + """Create a new tab for the given widget. + + @param widget (Widget): widget to associate to the tab + @param label (unicode): label of the tab + @param select (bool): True to select the added tab + """ + TabPanel.add(self, widget, DropTab(self, label), False) + if select: + self.selectTab(self.getWidgetCount() - 1) + + def addWidgetsTab(self, label, select=False, locked=False): + """Create a new tab for containing LiberviaWidgets. + + @param label (unicode): label of the tab + @param select (bool): True to select the added tab + @param locked (bool): If True, the tab will not be removed when there + are no more widget inside. If False, the tab will be removed with + the last widget. + @return: WidgetsPanel + """ + widgets_panel = WidgetsPanel(self, locked=locked) + self.addTab(widgets_panel, label) + return widgets_panel def onWidgetPanelRemove(self, panel): """ Called when a child WidgetsPanel is empty and need to be removed """
--- a/src/browser/sat_browser/panels.py Fri Feb 20 19:50:00 2015 +0100 +++ b/src/browser/sat_browser/panels.py Fri Feb 20 19:38:11 2015 +0100 @@ -21,6 +21,7 @@ from sat.core.log import getLogger log = getLogger(__name__) +from sat.core.i18n import _ from sat_frontends.tools.strings import addURLToText from pyjamas.ui.AbsolutePanel import AbsolutePanel @@ -509,9 +510,7 @@ # tabs self.tab_panel = base_widget.MainTabPanel(host) - self.discuss_panel = base_widget.WidgetsPanel(self.host, locked=True) - self.tab_panel.add(self.discuss_panel, "Discussions") - self.tab_panel.selectTab(0) + self.tab_panel.addWidgetsTab(_(u"Discussions"), select=True, locked=True) self.header = AbsolutePanel() self.header.add(self.menu)