comparison src/browser/sat_browser/base_widget.py @ 637:7113d40533d6 frontends_multi_profiles

merged souliane changes
author Goffi <goffi@goffi.org>
date Mon, 23 Feb 2015 18:47:27 +0100
parents 86ae737da6f3 b77e1070035c
children e0021d571eef
comparison
equal deleted inserted replaced
636:86ae737da6f3 637:7113d40533d6
19 19
20 import pyjd # this is dummy in pyjs 20 import pyjd # this is dummy in pyjs
21 from sat.core.log import getLogger 21 from sat.core.log import getLogger
22 log = getLogger(__name__) 22 log = getLogger(__name__)
23 from sat.core import exceptions 23 from sat.core import exceptions
24 from sat.core.i18n import _
24 from sat_frontends.quick_frontend import quick_widgets 25 from sat_frontends.quick_frontend import quick_widgets
26
25 from pyjamas.ui.SimplePanel import SimplePanel 27 from pyjamas.ui.SimplePanel import SimplePanel
26 from pyjamas.ui.AbsolutePanel import AbsolutePanel 28 from pyjamas.ui.AbsolutePanel import AbsolutePanel
27 from pyjamas.ui.VerticalPanel import VerticalPanel 29 from pyjamas.ui.VerticalPanel import VerticalPanel
28 from pyjamas.ui.HorizontalPanel import HorizontalPanel 30 from pyjamas.ui.HorizontalPanel import HorizontalPanel
29 from pyjamas.ui.ScrollPanel import ScrollPanel 31 from pyjamas.ui.ScrollPanel import ScrollPanel
584 586
585 587
586 class WidgetsPanel(ScrollPanelWrapper): 588 class WidgetsPanel(ScrollPanelWrapper):
587 589
588 def __init__(self, host, locked=False): 590 def __init__(self, host, locked=False):
591 """
592
593 @param host (SatWebFrontend): host instance
594 @param locked (bool): If True, the tab containing self will not be
595 removed when there are no more widget inside self. If False, the
596 tab will be removed with self's last widget.
597 """
589 ScrollPanelWrapper.__init__(self) 598 ScrollPanelWrapper.__init__(self)
590 self.setSize('100%', '100%') 599 self.setSize('100%', '100%')
591 self.host = host 600 self.host = host
592 self.locked = locked # if True: tab will not be removed when there are no more widgets inside 601 self.locked = locked
593 self.selected = None 602 self.selected = None
594 self.flextable = FlexTable() 603 self.flextable = FlexTable()
595 self.flextable.setSize('100%', '100%') 604 self.flextable.setSize('100%', '100%')
596 self.setWidget(self.flextable) 605 self.setWidget(self.flextable)
597 self.setStyleName('widgetsPanel') 606 self.setStyleName('widgetsPanel')
758 return self.tab_panel.tabBar.panel.getWidgetIndex(self.getParent().getParent()) - 1 767 return self.tab_panel.tabBar.panel.getWidgetIndex(self.getParent().getParent()) - 1
759 768
760 def onDragEnter(self, event): 769 def onDragEnter(self, event):
761 #if self == LiberviaDragWidget.current: 770 #if self == LiberviaDragWidget.current:
762 # return 771 # return
763 self.addStyleName('dragover') 772 self.parent.addStyleName('dragover')
764 DOM.eventPreventDefault(event) 773 DOM.eventPreventDefault(event)
765 774
766 def onDragLeave(self, event): 775 def onDragLeave(self, event):
767 self.removeStyleName('dragover') 776 self.parent.removeStyleName('dragover')
768 777
769 def onDragOver(self, event): 778 def onDragOver(self, event):
770 DOM.eventPreventDefault(event) 779 DOM.eventPreventDefault(event)
771 780
772 def onDrop(self, event): 781 def onDrop(self, event):
773 DOM.eventPreventDefault(event) 782 DOM.eventPreventDefault(event)
774 self.removeStyleName('dragover') 783 self.parent.removeStyleName('dragover')
775 if self._getIndex() == self.tab_panel.tabBar.getSelectedTab(): 784 if self._getIndex() == self.tab_panel.tabBar.getSelectedTab():
776 # the widget come from the DragTab, so nothing to do, we let it there 785 # the widget come from the DragTab, so nothing to do, we let it there
777 return 786 return
778 787
779 # FIXME: quite the same stuff as in DropCell, need some factorisation 788 # FIXME: quite the same stuff as in DropCell, need some factorisation
804 813
805 widgets_panel = self.tab_panel.getWidget(self._getIndex()) 814 widgets_panel = self.tab_panel.getWidget(self._getIndex())
806 widgets_panel.addWidget(_new_panel) 815 widgets_panel.addWidget(_new_panel)
807 816
808 817
809 class MainTabPanel(TabPanel): 818 class MainTabPanel(TabPanel, ClickHandler):
810 819
811 def __init__(self, host): 820 def __init__(self, host):
812 TabPanel.__init__(self) 821 TabPanel.__init__(self)
822 ClickHandler.__init__(self)
813 self.host = host 823 self.host = host
814 self.tabBar.setVisible(False)
815 self.setStyleName('liberviaTabPanel') 824 self.setStyleName('liberviaTabPanel')
816 self.addStyleName('mainTabPanel') 825 self.addStyleName('mainTabPanel')
817 Window.addWindowResizeListener(self) 826 Window.addWindowResizeListener(self)
827
828 self.tabBar.addTab(u'✚', True)
829
830 def onTabSelected(self, sender, tabIndex):
831 if tabIndex < self.getWidgetCount():
832 TabPanel.onTabSelected(self, sender, tabIndex)
833 return
834 # user clicked the "+" tab
835 default_label = _(u'new tab')
836 try:
837 label = Window.prompt(_(u'Name of the new tab'), default_label)
838 if not label:
839 label = default_label
840 except: # this happens when the user prevents the page to open the prompt dialog
841 label = default_label
842 self.addWidgetsTab(label, select=True)
818 843
819 def getCurrentPanel(self): 844 def getCurrentPanel(self):
820 """ Get the panel of the currently selected tab 845 """ Get the panel of the currently selected tab
821 846
822 @return: WidgetsPanel 847 @return: WidgetsPanel
834 ideal_height = height - DOM.getAbsoluteTop(tab_panel_elt) - tab_bar_h - 5 859 ideal_height = height - DOM.getAbsoluteTop(tab_panel_elt) - tab_bar_h - 5
835 ideal_width = width - DOM.getAbsoluteLeft(tab_panel_elt) - 5 860 ideal_width = width - DOM.getAbsoluteLeft(tab_panel_elt) - 5
836 self.setWidth("%s%s" % (ideal_width, "px")) 861 self.setWidth("%s%s" % (ideal_width, "px"))
837 self.setHeight("%s%s" % (ideal_height, "px")) 862 self.setHeight("%s%s" % (ideal_height, "px"))
838 863
839 def add(self, widget, text=''): 864 def addTab(self, widget, label, select=False):
840 tab = DropTab(self, text) 865 """Create a new tab for the given widget.
841 TabPanel.add(self, widget, tab, False) 866
842 if self.getWidgetCount() > 1: 867 @param widget (Widget): widget to associate to the tab
843 self.tabBar.setVisible(True) 868 @param label (unicode): label of the tab
844 self.host.resize() 869 @param select (bool): True to select the added tab
870 """
871 TabPanel.add(self, widget, DropTab(self, label), False)
872 if select:
873 self.selectTab(self.getWidgetCount() - 1)
874
875 def addWidgetsTab(self, label, select=False, locked=False):
876 """Create a new tab for containing LiberviaWidgets.
877
878 @param label (unicode): label of the tab
879 @param select (bool): True to select the added tab
880 @param locked (bool): If True, the tab will not be removed when there
881 are no more widget inside. If False, the tab will be removed with
882 the last widget.
883 @return: WidgetsPanel
884 """
885 widgets_panel = WidgetsPanel(self, locked=locked)
886 self.addTab(widgets_panel, label, select)
887 return widgets_panel
845 888
846 def onWidgetPanelRemove(self, panel): 889 def onWidgetPanelRemove(self, panel):
847 """ Called when a child WidgetsPanel is empty and need to be removed """ 890 """ Called when a child WidgetsPanel is empty and need to be removed """
891 widget_index = self.getWidgetIndex(panel)
848 self.remove(panel) 892 self.remove(panel)
849 widgets_count = self.getWidgetCount() 893 widgets_count = self.getWidgetCount()
850 if widgets_count == 1: 894 self.selectTab(widget_index if widget_index < widgets_count else widgets_count - 1)
851 self.tabBar.setVisible(False)
852 self.host.resize()
853 self.selectTab(0)
854 else:
855 self.selectTab(widgets_count - 1)