diff src/browser/sat_browser/base_widget.py @ 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
line wrap: on
line diff
--- 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 """