FNB_ALLOW_FOREIGN_DND = 32768
"""Allows drag 'n' drop operations between different L{FlatNotebook}s"""
+FNB_HIDE_ON_SINGLE_TAB = 65536
+"""Hides the Page Container when there is one or fewer tabs"""
+
VERTICAL_BORDER_PADDING = 4
# Button size is a 16x16 xpm bitmap
FNB_NOWHERE = 0 # Anywhere else
"""Indicates mouse coordinates not on any tab of the notebook"""
-FNB_DEFAULT_STYLE = FNB_MOUSE_MIDDLE_CLOSES_TABS
+FNB_DEFAULT_STYLE = FNB_MOUSE_MIDDLE_CLOSES_TABS | FNB_HIDE_ON_SINGLE_TAB
"""L{FlatNotebook} default style"""
# FlatNotebook Events:
pass
+ def NumberTabsCanFit(self, pageContainer, fr=-1):
+
+ pc = pageContainer
+
+ rect = pc.GetClientRect()
+ clientWidth = rect.width
+
+ vTabInfo = []
+
+ tabHeight = self.CalcTabHeight(pageContainer)
+
+ # The drawing starts from posx
+ posx = pc._pParent.GetPadding()
+
+ if fr < 0:
+ fr = pc._nFrom
+
+ for i in xrange(fr, len(pc._pagesInfoVec)):
+
+ tabWidth = self.CalcTabWidth(pageContainer, i, tabHeight)
+ if posx + tabWidth + self.GetButtonsAreaLength(pc) >= clientWidth:
+ break;
+
+ # Add a result to the returned vector
+ tabRect = wx.Rect(posx, VERTICAL_BORDER_PADDING, tabWidth , tabHeight)
+ vTabInfo.append(tabRect)
+
+ # Advance posx
+ posx += tabWidth + FNB_HEIGHT_SPACER
+
+ return vTabInfo
+
+
# ---------------------------------------------------------------------------- #
# Class FNBRendererMgr
# A manager that handles all the renderers defined below and calls the
pc._colorTo = LightColour(wx.SystemSettings_GetColour(wx.SYS_COLOUR_3DFACE), 0)
pc._colorFrom = LightColour(wx.SystemSettings_GetColour(wx.SYS_COLOUR_3DFACE), 60)
- col2 = (pc.HasFlag(FNB_BOTTOM) and [pc._pParent.GetGradientColourTo()] or [pc._pParent.GetGradientColourFrom()])[0]
- col1 = (pc.HasFlag(FNB_BOTTOM) and [pc._pParent.GetGradientColourFrom()] or [pc._pParent.GetGradientColourTo()])[0]
+ col2 = pc._pParent.GetGradientColourTo()
+ col1 = pc._pParent.GetGradientColourFrom()
# If colorful tabs style is set, override the tab color
if pc.HasFlag(FNB_COLORFUL_TABS):
# refreshing the tab container is not enough
self.SetSelection(self._pages._iActivePage)
+ if not self._pages.HasFlag(FNB_HIDE_ON_SINGLE_TAB):
+ #For Redrawing the Tabs once you remove the Hide tyle
+ self._pages._ReShow()
+
def RemovePage(self, page):
""" Deletes the specified page, without deleting the associated window. """
pass
+ def _ReShow(self):
+ """ Handles the Redraw of the tabs when the FNB_HIDE_ON_SINGLE_TAB has been removed """
+ self.Show()
+ self.GetParent()._mainSizer.Layout()
+ self.Refresh()
+
+
def OnPaint(self, event):
""" Handles the wx.EVT_PAINT event for L{PageContainer}."""
renderer = self._mgr.GetRenderer(self.GetParent().GetWindowStyleFlag())
renderer.DrawTabs(self, dc)
+ if self.HasFlag(FNB_HIDE_ON_SINGLE_TAB) and len(self._pagesInfoVec) <= 1:
+ self.Hide()
+ self.GetParent()._mainSizer.Layout()
+ self.Refresh()
+
def AddPage(self, caption, selected=True, imgindex=-1):
"""
def OnSize(self, event):
""" Handles the wx.EVT_SIZE events for L{PageContainer}. """
+ # When resizing the control, try to fit to screen as many tabs as we can
+ style = self.GetParent().GetWindowStyleFlag()
+ renderer = self._mgr.GetRenderer(style)
+
+ fr = 0
+ page = self.GetSelection()
+
+ for fr in xrange(self._nFrom):
+ vTabInfo = renderer.NumberTabsCanFit(self, fr)
+ if page - fr >= len(vTabInfo):
+ continue
+ break
+
+ self._nFrom = fr
+
self.Refresh() # Call on paint
event.Skip()
def OnRightDown(self, event):
""" Handles the wx.EVT_RIGHT_DOWN events for L{PageContainer}. """
-
- if self._pRightClickMenu:
- where, tabIdx = self.HitTest(event.GetPosition())
+ where, tabIdx = self.HitTest(event.GetPosition())
- if where in [FNB_TAB, FNB_TAB_X]:
+ if where in [FNB_TAB, FNB_TAB_X]:
- if self._pagesInfoVec[tabIdx].GetEnabled():
- # Set the current tab to be active
- self.SetSelection(tabIdx)
-
- # If the owner has defined a context menu for the tabs,
- # popup the right click menu
- if self._pRightClickMenu:
- self.PopupMenu(self._pRightClickMenu)
- else:
- # send a message to popup a custom menu
- event = FlatNotebookEvent(wxEVT_FLATNOTEBOOK_PAGE_CONTEXT_MENU, self.GetParent().GetId())
- event.SetSelection(tabIdx)
- event.SetOldSelection(self._iActivePage)
- event.SetEventObject(self.GetParent())
- self.GetParent().GetEventHandler().ProcessEvent(event)
-
- event.Skip()
+ if self._pagesInfoVec[tabIdx].GetEnabled():
+ # Fire events and eventually (if allowed) change selection
+ self.FireEvent(tabIdx)
+
+ # send a message to popup a custom menu
+ event = FlatNotebookEvent(wxEVT_FLATNOTEBOOK_PAGE_CONTEXT_MENU, self.GetParent().GetId())
+ event.SetSelection(tabIdx)
+ event.SetOldSelection(self._iActivePage)
+ event.SetEventObject(self.GetParent())
+ self.GetParent().GetEventHandler().ProcessEvent(event)
+
+ if self._pRightClickMenu:
+ self.PopupMenu(self._pRightClickMenu)
+
+ event.Skip()
def OnLeftDown(self, event):
da_page.SetFocus()
if not self.IsTabVisible(page):
-
- if page == len(self._pagesInfoVec) - 1:
- # Incase the added tab is last,
- # the function IsTabVisible() will always return False
- # and thus will cause an evil behaviour that the new
- # tab will hide all other tabs, we need to check if the
- # new selected tab can fit to the current screen
- if not self.CanFitToScreen(page):
- self._nFrom = page
-
- else:
+ # Try to remove one tab from start and try again
+
+ if not self.CanFitToScreen(page):
- if not self.CanFitToScreen(page):
- # Redraw the tabs starting from page
+ if self._nFrom > page:
self._nFrom = page
-
+ else:
+ while self._nFrom < page:
+ self._nFrom += 1
+ if self.CanFitToScreen(page):
+ break
+
self.Refresh()
def GetLastVisibleTab(self):
""" Returns the last visible tab. """
+ if self._nFrom < 0:
+ return -1
+
ii = 0
for ii in xrange(self._nFrom, len(self._pagesInfoVec)):
style = self.GetParent().GetWindowStyleFlag()
render = self._mgr.GetRenderer(style)
- if not self.HasFlag(FNB_VC8):
- rect = self.GetClientRect();
- clientWidth = rect.width;
- tabHeight = render.CalcTabHeight(self)
- tabWidth = render.CalcTabWidth(self, page, tabHeight)
-
- posx = self._pParent._nPadding
-
- if self._nFrom >= 0:
-
- for i in xrange(self._nFrom, len(self._pagesInfoVec)):
-
- if self._pagesInfoVec[i].GetPosition() == wx.Point(-1, -1):
- break
-
- posx += self._pagesInfoVec[i].GetSize().x
-
- if posx + tabWidth + render.GetButtonsAreaLength(self) >= clientWidth:
- return False
-
- return True
-
- else:
+ vTabInfo = render.NumberTabsCanFit(self)
- # TODO:: this is ugly and should be improved, we should *never* access the
- # raw pointer directly like we do here (render.Get())
- vc8_render = render
- vTabInfo = vc8_render.NumberTabsCanFit(self)
-
- if page - self._nFrom >= len(vTabInfo):
- return False
-
- return True
+ if page - self._nFrom >= len(vTabInfo):
+ return False
+
+ return True
def GetNumOfVisibleTabs(self):