comparison browser_side/panels.py @ 184:97d5e9de1106

browser side: contacts panel switch: - contact panel is now on the left of main tab panel (instead of being part of the first tab) - there is a new button on the left of "Contacts" title to (un)hide the panel
author Goffi <goffi@goffi.org>
date Sun, 03 Mar 2013 03:04:04 +0100
parents c0b78a3af06d
children 40adfd4ee4d7
comparison
equal deleted inserted replaced
183:a50ce9c06e0e 184:97d5e9de1106
848 def onUrlClick(self, sender): 848 def onUrlClick(self, sender):
849 self._frame.setUrl(self._url.getText()) 849 self._frame.setUrl(self._url.getText())
850 850
851 class WidgetsPanel(ScrollPanelWrapper): 851 class WidgetsPanel(ScrollPanelWrapper):
852 852
853 def __init__(self, host): 853 def __init__(self, host, locked = False):
854 ScrollPanelWrapper.__init__(self) 854 ScrollPanelWrapper.__init__(self)
855 self.setSize('100%', '100%') 855 self.setSize('100%', '100%')
856 self.host = host 856 self.host = host
857 self.locked = locked #if True: tab will not be removed when there are no more widgets inside
857 self.flextable = FlexTable() 858 self.flextable = FlexTable()
858 self.flextable.setSize('100%','100%') 859 self.flextable.setSize('100%','100%')
859 self.setWidget(self.flextable) 860 self.setWidget(self.flextable)
860 self.setStyleName('widgetsPanel') 861 self.setStyleName('widgetsPanel')
861 _bottom = BottomBorderWidget(self.host) 862 _bottom = BottomBorderWidget(self.host)
862 self.flextable.setWidget(0, 0, _bottom) #There will be always an Empty widget on the last row, 863 self.flextable.setWidget(0, 0, _bottom) #There will be always an Empty widget on the last row,
863 #dropping a widget there will add a new row 864 #dropping a widget there will add a new row
864 td_elt = _bottom.getElement().parentNode 865 td_elt = _bottom.getElement().parentNode
865 DOM.setStyleAttribute(td_elt, "height", "1px") #needed so the cell adapt to the size of the border (specially in webkit) 866 DOM.setStyleAttribute(td_elt, "height", "1px") #needed so the cell adapt to the size of the border (specially in webkit)
866 self._max_cols = 1 #give the maximum number of columns i a raw 867 self._max_cols = 1 #give the maximum number of columns i a raw
868
869 def isLocked(self):
870 return self.locked
867 871
868 def changeWidget(self, row, col, wid): 872 def changeWidget(self, row, col, wid):
869 """Change the widget in the given location, add row or columns when necessary""" 873 """Change the widget in the given location, add row or columns when necessary"""
870 print "changing widget:", wid, row, col 874 print "changing widget:", wid, row, col
871 last_row = max(0, self.flextable.getRowCount()-1) 875 last_row = max(0, self.flextable.getRowCount()-1)
950 self._sizesAdjust() 954 self._sizesAdjust()
951 current = self 955 current = self
952 956
953 blank_page = not [wid for wid in self.flextable if isinstance(wid, LiberviaWidget)] # do we still have widgets on the page ? 957 blank_page = not [wid for wid in self.flextable if isinstance(wid, LiberviaWidget)] # do we still have widgets on the page ?
954 958
955 if blank_page and not isinstance(self.getParent(), MainDiscussionPanel): 959 if blank_page and not self.isLocked():
956 #we now notice the MainTabPanel that the WidgetsPanel is empty and need to be removed 960 #we now notice the MainTabPanel that the WidgetsPanel is empty and need to be removed
957 while current is not None: 961 while current is not None:
958 if isinstance(current, MainTabPanel): 962 if isinstance(current, MainTabPanel):
959 current.onWidgetPanelRemove(self) 963 current.onWidgetPanelRemove(self)
960 return 964 return
978 982
979 def setRowSpan(self, row, col, value): 983 def setRowSpan(self, row, col, value):
980 cellFormatter = self.flextable.getFlexCellFormatter() 984 cellFormatter = self.flextable.getFlexCellFormatter()
981 return cellFormatter.setRowSpan(row, col, value) 985 return cellFormatter.setRowSpan(row, col, value)
982 986
983 class MainDiscussionPanel(HorizontalPanel): 987 class ContactTabPanel(HorizontalPanel):
984 988 """ TabPanel with a contacts list which can be hidden """
985 def __init__(self, host): 989
990 def __init__(self, host, locked = False):
986 self.host=host 991 self.host=host
987 HorizontalPanel.__init__(self) 992 HorizontalPanel.__init__(self)
988 self._left = self.host.contact_panel 993 self._left = VerticalPanel()
994 contacts_switch = Button('<<', self._contactsSwitch)
995 contacts_switch.addStyleName('contactsSwitch')
996 self._left.add(contacts_switch)
997 self._left.add(self.host.contact_panel)
989 self._right = WidgetsPanel(host) 998 self._right = WidgetsPanel(host)
990 self._right.setWidth('100%') 999 self._right.setWidth('100%')
991 self._right.setHeight('100%') 1000 self._right.setHeight('100%')
992 self.add(self._left) 1001 self.add(self._left)
993 self.add(self._right) 1002 self.add(self._right)
994 self.setCellWidth(self._right, "100%") 1003 self.setCellWidth(self._right, "100%")
995 1004
996 def addWidget(self, wid): 1005 def addWidget(self, wid):
997 """Add a widget to the WidgetsPanel""" 1006 """Add a widget to the WidgetsPanel"""
998 print "main addWidget", wid 1007 print "main addWidget", wid
999 self._right.addWidget(wid) 1008 self._right.addWidget(wid)
1000 1009
1014 if not _elts.length: 1023 if not _elts.length:
1015 print ("ERROR: no TabBar found, it should exist !") 1024 print ("ERROR: no TabBar found, it should exist !")
1016 tab_bar_h = 0 1025 tab_bar_h = 0
1017 else: 1026 else:
1018 tab_bar_h = _elts.item(0).offsetHeight 1027 tab_bar_h = _elts.item(0).offsetHeight
1019 ideal_height = Window.getClientHeight() - tab_panel_elt.offsetTop - tab_bar_h - 5 1028 ideal_height = Window.getClientHeight() - DOM.getAbsoluteTop(tab_panel_elt) - tab_bar_h - 5
1020 self.setWidth("%s%s" % (width-5, "px")); 1029 ideal_width = width - self.host.contact_panel.getElement().offsetWidth - 5
1030 self.setWidth("%s%s" % (ideal_width, "px"));
1021 self.setHeight("%s%s" % (ideal_height, "px")); 1031 self.setHeight("%s%s" % (ideal_height, "px"));
1022 1032
1023 def add(self, widget, tabText=None, asHTML=False): 1033 def add(self, widget, tabText=None, asHTML=False):
1024 TabPanel.add(self, widget, tabText, asHTML) 1034 TabPanel.add(self, widget, tabText, asHTML)
1025 if self.getWidgetCount()>1: 1035 if self.getWidgetCount()>1:
1038 1048
1039 def __init__(self, host): 1049 def __init__(self, host):
1040 self.host=host 1050 self.host=host
1041 AbsolutePanel.__init__(self) 1051 AbsolutePanel.__init__(self)
1042 1052
1053 #menu
1043 menu = Menu(host) 1054 menu = Menu(host)
1055
1056 #unibox
1044 unibox_panel = UniBoxPanel(host) 1057 unibox_panel = UniBoxPanel(host)
1045 self.host.setUniBox(unibox_panel.unibox) 1058 self.host.setUniBox(unibox_panel.unibox)
1059
1060 #status bar
1046 status = host.status_panel 1061 status = host.status_panel
1062
1063 #contacts
1064 _contacts = VerticalPanel()
1065 contacts_switch = Button('<<', self._contactsSwitch)
1066 contacts_switch.addStyleName('contactsSwitch')
1067 _contacts.add(contacts_switch)
1068 _contacts.add(self.host.contact_panel)
1069
1070 #tabs
1047 self.tab_panel = MainTabPanel(host) 1071 self.tab_panel = MainTabPanel(host)
1048 self.discuss_panel = MainDiscussionPanel(self.host) 1072 self.discuss_panel = WidgetsPanel(self.host, locked=True)
1049 self.tab_panel.add(self.discuss_panel, "Discussions") 1073 self.tab_panel.add(self.discuss_panel, "Discussions")
1050 self.tab_panel.selectTab(0) 1074 self.tab_panel.selectTab(0)
1051 1075
1052 header=AbsolutePanel() 1076 header=AbsolutePanel()
1053 header.add(menu) 1077 header.add(menu)
1054 header.add(unibox_panel) 1078 header.add(unibox_panel)
1055 header.add(status) 1079 header.add(status)
1056 header.setStyleName('header') 1080 header.setStyleName('header')
1057 self.add(header) 1081 self.add(header)
1058 self.add(self.tab_panel) 1082
1083 _hpanel = HorizontalPanel()
1084 _hpanel.add(_contacts)
1085 _hpanel.add(self.tab_panel)
1086 self.add(_hpanel)
1059 1087
1060 self.setWidth("100%") 1088 self.setWidth("100%")
1061 Window.addWindowResizeListener(self) 1089 Window.addWindowResizeListener(self)
1090
1091 def _contactsSwitch(self, btn):
1092 """ (Un)hide contacts panel """
1093 cpanel = self.host.contact_panel
1094 cpanel.setVisible(not cpanel.getVisible())
1095 btn.setText("<<" if cpanel.getVisible() else ">>")
1096 self.host.resize()
1062 1097
1063 def onWindowResized(self, width, height): 1098 def onWindowResized(self, width, height):
1064 _elts = doc().getElementsByClassName('gwt-TabBar') 1099 _elts = doc().getElementsByClassName('gwt-TabBar')
1065 if not _elts.length: 1100 if not _elts.length:
1066 tab_bar_h = 0 1101 tab_bar_h = 0