comparison browser_side/panels.py @ 177:ba95cd824e06

browser side: tab is removed if it doesn't contain widget anymore. bug 8
author Goffi <goffi@goffi.org>
date Fri, 25 Jan 2013 00:38:06 +0100
parents d97b0cba8b04
children 7a349be99a77
comparison
equal deleted inserted replaced
176:b9edfa058786 177:ba95cd824e06
170 if self.__selectable: 170 if self.__selectable:
171 self.addClickListener(self) 171 self.addClickListener(self)
172 self.host.registerWidget(self) 172 self.host.registerWidget(self)
173 173
174 def _getWidgetsPanel(self): 174 def _getWidgetsPanel(self):
175 return self.getParent().getParent().getParent() 175 current = self
176 while current is not None and current.__class__ != WidgetsPanel:
177 current = current.getParent()
178 if current is None:
179 print "Error: can't find WidgetsPanel"
180 return current
176 181
177 def onClick(self, sender): 182 def onClick(self, sender):
178 self.host.select(self) 183 self.host.select(self)
179 184
180 def onClose(self, sender): 185 def onClose(self, sender):
181 print "onClose:", sender
182 _widgetspanel = self._getWidgetsPanel() 186 _widgetspanel = self._getWidgetsPanel()
183 _widgetspanel.removeWidget(self) 187 _widgetspanel.removeWidget(self)
184 188
185 def onSetting(self, sender): 189 def onSetting(self, sender):
186 widpanel = self._getWidgetsPanel() 190 widpanel = self._getWidgetsPanel()
899 for row_idx in xrange(self.flextable.getRowCount()): 903 for row_idx in xrange(self.flextable.getRowCount()):
900 _max_cols = max(_max_cols, self.flextable.getCellCount(row_idx)) 904 _max_cols = max(_max_cols, self.flextable.getCellCount(row_idx))
901 if _max_cols != self._max_cols: 905 if _max_cols != self._max_cols:
902 self._max_cols = _max_cols 906 self._max_cols = _max_cols
903 self._sizesAdjust() 907 self._sizesAdjust()
908 current = self
909
910 blank_page = not [wid for wid in self.flextable if isinstance(wid, LiberviaWidget)] # do we still have widgets on the page ?
911
912 if blank_page and not isinstance(self.getParent(), MainDiscussionPanel):
913 #we now notice the MainTabPanel that the WidgetsPanel is empty and need to be removed
914 while current is not None:
915 if isinstance(current, MainTabPanel):
916 current.onWidgetPanelRemove(self)
917 return
918 current = current.getParent()
919 print "Error: no MainTabPanel found !"
904 920
905 def getIndex(self, wid): 921 def getIndex(self, wid):
906 return self.flextable.getIndex(wid) 922 return self.flextable.getIndex(wid)
907 923
908 def getColSpan(self, row, col): 924 def getColSpan(self, row, col):
951 967
952 def onWindowResized(self, width, height): 968 def onWindowResized(self, width, height):
953 tab_panel_elt = self.getElement() 969 tab_panel_elt = self.getElement()
954 _elts = doc().getElementsByClassName('gwt-TabBar') 970 _elts = doc().getElementsByClassName('gwt-TabBar')
955 if not _elts.length: 971 if not _elts.length:
956 print ("ERROR: not TabBar found, it should exist !") 972 print ("ERROR: no TabBar found, it should exist !")
957 tab_bar_h = 0 973 tab_bar_h = 0
958 else: 974 else:
959 tab_bar_h = _elts.item(0).offsetHeight 975 tab_bar_h = _elts.item(0).offsetHeight
960 ideal_height = Window.getClientHeight() - tab_panel_elt.offsetTop - tab_bar_h - 5 976 ideal_height = Window.getClientHeight() - tab_panel_elt.offsetTop - tab_bar_h - 5
961 self.setWidth("%s%s" % (width-5, "px")); 977 self.setWidth("%s%s" % (width-5, "px"));
964 def add(self, widget, tabText=None, asHTML=False): 980 def add(self, widget, tabText=None, asHTML=False):
965 TabPanel.add(self, widget, tabText, asHTML) 981 TabPanel.add(self, widget, tabText, asHTML)
966 if self.getWidgetCount()>1: 982 if self.getWidgetCount()>1:
967 self.tabBar.setVisible(True) 983 self.tabBar.setVisible(True)
968 self.host.resize() 984 self.host.resize()
985
986 def onWidgetPanelRemove(self, panel):
987 """ Called when a child WidgetsPanel is empty and need to be removed """
988 self.remove(panel)
989 if self.getWidgetCount() == 1:
990 self.tabBar.setVisible(False)
991 self.host.resize()
992 self.selectTab(0)
969 993
970 class MainPanel(AbsolutePanel): 994 class MainPanel(AbsolutePanel):
971 995
972 def __init__(self, host): 996 def __init__(self, host):
973 self.host=host 997 self.host=host