Mercurial > libervia-web
comparison 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 |
comparison
equal
deleted
inserted
replaced
619:11a0a32144a5 | 620:ac5881d683d3 |
---|---|
585 | 585 |
586 | 586 |
587 class WidgetsPanel(ScrollPanelWrapper): | 587 class WidgetsPanel(ScrollPanelWrapper): |
588 | 588 |
589 def __init__(self, host, locked=False): | 589 def __init__(self, host, locked=False): |
590 """ | |
591 | |
592 @param host (SatWebFrontend): host instance | |
593 @param locked (bool): If True, the tab containing self will not be | |
594 removed when there are no more widget inside self. If False, the | |
595 tab will be removed with self's last widget. | |
596 """ | |
590 ScrollPanelWrapper.__init__(self) | 597 ScrollPanelWrapper.__init__(self) |
591 self.setSize('100%', '100%') | 598 self.setSize('100%', '100%') |
592 self.host = host | 599 self.host = host |
593 self.locked = locked # if True: tab will not be removed when there are no more widgets inside | 600 self.locked = locked |
594 self.selected = None | 601 self.selected = None |
595 self.flextable = FlexTable() | 602 self.flextable = FlexTable() |
596 self.flextable.setSize('100%', '100%') | 603 self.flextable.setSize('100%', '100%') |
597 self.setWidget(self.flextable) | 604 self.setWidget(self.flextable) |
598 self.setStyleName('widgetsPanel') | 605 self.setStyleName('widgetsPanel') |
829 label = Window.prompt(_(u'Name of the new tab'), default_label) | 836 label = Window.prompt(_(u'Name of the new tab'), default_label) |
830 if not label: | 837 if not label: |
831 label = default_label | 838 label = default_label |
832 except: # this happens when the user prevents the page to open the prompt dialog | 839 except: # this happens when the user prevents the page to open the prompt dialog |
833 label = default_label | 840 label = default_label |
834 self.host.addTab(label, select=True) | 841 self.addWidgetsTab(label, select=True) |
835 | 842 |
836 def getCurrentPanel(self): | 843 def getCurrentPanel(self): |
837 """ Get the panel of the currently selected tab | 844 """ Get the panel of the currently selected tab |
838 | 845 |
839 @return: WidgetsPanel | 846 @return: WidgetsPanel |
851 ideal_height = height - DOM.getAbsoluteTop(tab_panel_elt) - tab_bar_h - 5 | 858 ideal_height = height - DOM.getAbsoluteTop(tab_panel_elt) - tab_bar_h - 5 |
852 ideal_width = width - DOM.getAbsoluteLeft(tab_panel_elt) - 5 | 859 ideal_width = width - DOM.getAbsoluteLeft(tab_panel_elt) - 5 |
853 self.setWidth("%s%s" % (ideal_width, "px")) | 860 self.setWidth("%s%s" % (ideal_width, "px")) |
854 self.setHeight("%s%s" % (ideal_height, "px")) | 861 self.setHeight("%s%s" % (ideal_height, "px")) |
855 | 862 |
856 def add(self, widget, text=''): | 863 def addTab(self, widget, label, select=False): |
857 tab = DropTab(self, text) | 864 """Create a new tab for the given widget. |
858 TabPanel.add(self, widget, tab, False) | 865 |
866 @param widget (Widget): widget to associate to the tab | |
867 @param label (unicode): label of the tab | |
868 @param select (bool): True to select the added tab | |
869 """ | |
870 TabPanel.add(self, widget, DropTab(self, label), False) | |
871 if select: | |
872 self.selectTab(self.getWidgetCount() - 1) | |
873 | |
874 def addWidgetsTab(self, label, select=False, locked=False): | |
875 """Create a new tab for containing LiberviaWidgets. | |
876 | |
877 @param label (unicode): label of the tab | |
878 @param select (bool): True to select the added tab | |
879 @param locked (bool): If True, the tab will not be removed when there | |
880 are no more widget inside. If False, the tab will be removed with | |
881 the last widget. | |
882 @return: WidgetsPanel | |
883 """ | |
884 widgets_panel = WidgetsPanel(self, locked=locked) | |
885 self.addTab(widgets_panel, label) | |
886 return widgets_panel | |
859 | 887 |
860 def onWidgetPanelRemove(self, panel): | 888 def onWidgetPanelRemove(self, panel): |
861 """ Called when a child WidgetsPanel is empty and need to be removed """ | 889 """ Called when a child WidgetsPanel is empty and need to be removed """ |
862 widget_index = self.getWidgetIndex(panel) | 890 widget_index = self.getWidgetIndex(panel) |
863 self.remove(panel) | 891 self.remove(panel) |