AGW Logo

svn SVN Revision 69946 For labelbook

This file contains the SVN revision history for labelbook, at revision 69946.

Available information include commit date, the name of the committer, the file size, the SVN log messages and a diff from the previous version (if available).


file_info File Information

  • Commit Date: 17-Oct-2008 19:15:31 UTC
  • Committer: AG
  • File Size: 111405 byte(s)

svn_log Log Messages

The following log message was entered by the committer:

  • LabelBook: added the ability to have enabled/disabled tabs (thanks to David Hughes for the patch);
  • LabelBook: now Ctrl+Tab switches between tabs as the normal wx.Notebook does;
  • LabelBook: Added the new style INB_BOLD_TAB_SELECTION to use a bold font for the selected tab text.

svn_diff Diff To Previous Version (69803)

Version SVN diff:

--- wxPython/3rdParty/AGW/agw/labelbook.py  2011/11/23 17:47:12     69803
+++ wxPython/3rdParty/AGW/agw/labelbook.py  2011/12/07 20:16:28     69946
@@ -10,7 +10,7 @@
# Python Code By:
#
# Andrea Gavana, @ 03 Nov 2006
-# Latest Revision: 23 Nov 2011, 18.00 GMT
+# Latest Revision: 07 Dec 2011, 21.00 GMT
#
#
# For All Kind Of Problems, Requests Of Enhancements And Bug Reports, Please
@@ -137,6 +137,7 @@
``INB_WEB_HILITE``                0x800 On mouse hovering, tabs behave like html hyperlinks. Available only for L{LabelBook}.
``INB_NO_RESIZE``                0x1000 Don't allow resizing of the tab area.
``INB_FIT_LABELTEXT``            0x2000 Will fit the tab area to the longest text (or text+image if you have images) in all the tabs.
+``INB_BOLD_TAB_SELECTION``       0x4000 Show the selected tab text using a bold font.
=========================== =========== ==================================================


@@ -155,18 +156,27 @@
=================================== ==================================================


+TODOs
+=====
+
+- L{LabelBook}: support ``IMB_SHOW_ONLY_IMAGES``;
+- L{LabelBook}: an option to only draw the border between the controls and the pages so the background
+  colour can flow into the window background.
+
+
License And Version
===================

L{LabelBook} and L{FlatImageBook} are distributed under the wxPython license.

-Latest Revision: Andrea Gavana @ 23 Nov 2011, 18.00 GMT
+Latest Revision: Andrea Gavana @ 07 Dec 2011, 21.00 GMT

-Version 0.5.
+Version 0.6.

"""

__docformat__ = "epytext"
+__version__ = "0.6"


#----------------------------------------------------------------------
@@ -211,6 +221,8 @@
""" Don't allow resizing of the tab area. """
INB_FIT_LABELTEXT = 8192
""" Will fit the tab area to the longest text (or text+image if you have images) in all the tabs. """
+INB_BOLD_TAB_SELECTION = 16384
+""" Show the selected tab text using a bold font. """

wxEVT_IMAGENOTEBOOK_PAGE_CHANGED = wx.wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
wxEVT_IMAGENOTEBOOK_PAGE_CHANGING = wx.wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
@@ -332,13 +344,14 @@
This class holds all the information (caption, image, etc...) belonging to a
single tab in L{LabelBook}.
"""
-    def __init__(self, strCaption="", imageIndex=-1):
+    def __init__(self, strCaption="", imageIndex=-1, enabled=True):
"""
Default class constructor.

:param `strCaption`: the tab caption;
:param `imageIndex`: the tab image index based on the assigned (set)
-         `wx.ImageList` (if any).
+         `wx.ImageList` (if any);
+        :param `enabled`: sets the tab as enabled or disabled.
"""

self._pos = wx.Point()
@@ -346,6 +359,7 @@
self._strCaption = strCaption
self._ImageIndex = imageIndex
self._captionRect = wx.Rect()
+        self._bEnabled = enabled


def SetCaption(self, value):
@@ -428,6 +442,22 @@
return self._captionRect


+    def GetEnabled(self):
+        """ Returns whether the tab is enabled or not. """
+
+        return self._bEnabled
+
+
+    def EnableTab(self, enabled):
+        """
+        Sets the tab enabled or disabled.
+
+        :param `enabled`: ``True`` to enable a tab, ``False`` to disable it.
+        """
+
+        self._bEnabled = enabled
+
+
# ---------------------------------------------------------------------------- #
# Class ImageContainerBase
# ---------------------------------------------------------------------------- #
@@ -468,6 +498,7 @@
``INB_WEB_HILITE``                0x800 On mouse hovering, tabs behave like html hyperlinks. Available only for L{LabelBook}.
``INB_NO_RESIZE``                0x1000 Don't allow resizing of the tab area.
``INB_FIT_LABELTEXT``            0x2000 Will fit the tab area to the longest text (or text+image if you have images) in all the tabs.
+         ``INB_BOLD_TAB_SELECTION``       0x4000 Show the selected tab text using a bold font.
=========================== =========== ==================================================

:param `name`: the window name.
@@ -476,7 +507,7 @@
self._nIndex = -1
self._nImgSize = 16
self._ImageList = None
-        self._nHoeveredImgIdx = -1
+        self._nHoveredImgIdx = -1
self._bCollapsed = False
self._tabAreaSize = (-1, -1)
self._nPinButtonStatus = INB_PIN_NONE
@@ -509,6 +540,7 @@
``INB_WEB_HILITE``                0x800 On mouse hovering, tabs behave like html hyperlinks. Available only for L{LabelBook}.
``INB_NO_RESIZE``                0x1000 Don't allow resizing of the tab area.
``INB_FIT_LABELTEXT``            0x2000 Will fit the tab area to the longest text (or text+image if you have images) in all the tabs.
+         ``INB_BOLD_TAB_SELECTION``       0x4000 Show the selected tab text using a bold font.
=========================== =========== ==================================================
"""

@@ -661,7 +693,36 @@
imgInfo = self._pagesInfoVec[page]
return imgInfo.GetCaption()

+
+    def GetEnabled(self, page):
+        """
+        Returns whether a tab is enabled or not.
+
+        :param `page`: an integer specifying the page index.
+        """
+
+        if page >= len(self._pagesInfoVec):
+            return True # Adding a page - enabled by default
+
+        imgInfo = self._pagesInfoVec[page]
+        return imgInfo.GetEnabled()
+
+
+    def EnableTab(self, page, enabled=True):
+        """
+        Enables or disables a tab.
+
+        :param `page`: an integer specifying the page index;
+        :param `enabled`: ``True`` to enable a tab, ``False`` to disable it.
+        """
+
+        if page >= len(self._pagesInfoVec):
+            return
+
+        imgInfo = self._pagesInfoVec[page]
+        imgInfo.EnableTab(enabled)

+
def ClearAll(self):
""" Deletes all the pages in the container. """

@@ -822,7 +883,7 @@
tabIdx, where = self.HitTest(event.GetPosition())

if where == IMG_OVER_IMG:
-            self._nHoeveredImgIdx = -1
+            self._nHoveredImgIdx = -1

if tabIdx == -1:
return
@@ -837,8 +898,8 @@
:param `event`: a `wx.MouseEvent` event to be processed.
"""

-        bRepaint = self._nHoeveredImgIdx != -1
-        self._nHoeveredImgIdx = -1
+        bRepaint = self._nHoveredImgIdx != -1
+        self._nHoveredImgIdx = -1

# Make sure the pin button status is NONE
# incase we were in pin button style
@@ -928,29 +989,25 @@
self.DrawPin(dc, self._pinBtnRect, not self._bCollapsed)

imgIdx, where = self.HitTest(event.GetPosition())
-        self._nHoeveredImgIdx = imgIdx
+
+        # Allow hovering unless over current tab or tab is disabled
+        self._nHoveredImgIdx = -1
+
+        if imgIdx < len(self._pagesInfoVec) and self.GetEnabled(imgIdx) and imgIdx != self._nIndex:
+            self._nHoveredImgIdx = imgIdx

if not self._bCollapsed:

-            if self._nHoeveredImgIdx >= 0 and self._nHoeveredImgIdx < len(self._pagesInfoVec):
+            if self._nHoveredImgIdx >= 0 and self.HasAGWFlag(INB_WEB_HILITE):

-                # Change the cursor to be Hand
-                if self.HasAGWFlag(INB_WEB_HILITE) and self._nHoeveredImgIdx != self._nIndex:
-                    wx.SetCursor(wx.StockCursor(wx.CURSOR_HAND))
+                # Change the cursor to be Hand if we have the Web hover style set
+                wx.SetCursor(wx.StockCursor(wx.CURSOR_HAND))

-            else:
+            elif not self.PointOnSash(event.GetPosition()):

-                # Restore the cursor only if we have the Web hover style set,
-                # and we are not currently hovering the sash
-                if self.HasAGWFlag(INB_WEB_HILITE) and not self.PointOnSash(event.GetPosition()):
-                    wx.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
-
-        # Dont display hover effect when hoevering the
-        # selected label
-
-        if self._nHoeveredImgIdx == self._nIndex:
-            self._nHoeveredImgIdx = -1
-
+                # Restore the cursor if we are not currently hovering the sash
+                wx.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
+
self.Refresh()


@@ -1046,6 +1103,7 @@
``INB_WEB_HILITE``                0x800 On mouse hovering, tabs behave like html hyperlinks. Available only for L{LabelBook}.
``INB_NO_RESIZE``                0x1000 Don't allow resizing of the tab area.
``INB_FIT_LABELTEXT``            0x2000 Will fit the tab area to the longest text (or text+image if you have images) in all the tabs.
+         ``INB_BOLD_TAB_SELECTION``       0x4000 Show the selected tab text using a bold font.
=========================== =========== ==================================================

:param `name`: the window name.
@@ -1204,6 +1262,9 @@
nTextPaddingLeft = 2

count = 0
+        normalFont = wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT)
+        boldFont = wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT)
+        boldFont.SetWeight(wx.BOLD)

for i in xrange(len(self._pagesInfoVec)):

@@ -1213,15 +1274,13 @@
# text width plus padding
# Incase the style IS applied, but the style is either LEFT or RIGHT
# we ignore it
-            normalFont = wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT)
dc.SetFont(normalFont)

+            if style & INB_BOLD_TAB_SELECTION and self._nIndex == i:
+                dc.SetFont(boldFont)
+
textWidth, textHeight = dc.GetTextExtent(self._pagesInfoVec[i].GetCaption())

-            # Restore font to be normal
-            normalFont.SetWeight(wx.FONTWEIGHT_NORMAL)
-            dc.SetFont(normalFont)
-
# Default values for the surronounding rectangle
# around a button
rectWidth = self._nImgSize * 2  # To avoid the recangle to 'touch' the borders
@@ -1277,7 +1336,7 @@

dc.DrawRectangleRect(buttonRect)

-            if self._nHoeveredImgIdx == i:
+            if self._nHoveredImgIdx == i:

# Set the colours
penColour = wx.SystemSettings_GetColour(wx.SYS_COLOUR_ACTIVECAPTION)
@@ -1331,8 +1390,11 @@

# Draw the text
if not style & INB_SHOW_ONLY_IMAGES and not self._pagesInfoVec[i].GetCaption() == "":
-
-                dc.SetFont(normalFont)
+
+                if style & INB_BOLD_TAB_SELECTION and self._nIndex == i:
+                    dc.SetFont(boldFont)
+                else:
+                    dc.SetFont(normalFont)

# Check if the text can fit the size of the rectangle,
# if not truncate it
@@ -1416,6 +1478,7 @@
``INB_WEB_HILITE``                0x800 On mouse hovering, tabs behave like html hyperlinks. Available only for L{LabelBook}.
``INB_NO_RESIZE``                0x1000 Don't allow resizing of the tab area.
``INB_FIT_LABELTEXT``            0x2000 Will fit the tab area to the longest text (or text+image if you have images) in all the tabs.
+         ``INB_BOLD_TAB_SELECTION``       0x4000 Show the selected tab text using a bold font.
=========================== =========== ==================================================

:param `name`: the window name.
@@ -1576,8 +1639,12 @@
if self.HasAGWFlag(INB_SHOW_ONLY_TEXT):
font = wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT)
font.SetPointSize(font.GetPointSize() * self.GetParent().GetFontSizeMultiple())
+
if self.GetParent().GetFontBold():
font.SetWeight(wx.FONTWEIGHT_BOLD)
+                elif self.HasAGWFlag(INB_BOLD_TAB_SELECTION) and self._nIndex == i:
+                    font.SetWeight(wx.FONTWEIGHT_BOLD)
+
dc.SetFont(font)
w, h = dc.GetTextExtent(self._pagesInfoVec[i].GetCaption())
rectHeight = h * 2
@@ -1601,7 +1668,7 @@

self.DrawLabel(dc, buttonRect, self._pagesInfoVec[i].GetCaption(), bmp,
self._pagesInfoVec[i], self.HasAGWFlag(INB_LEFT) or self.HasAGWFlag(INB_TOP),
-                           i, self._nIndex == i, self._nHoeveredImgIdx == i)
+                           i, self._nIndex == i, self._nHoveredImgIdx == i)

posy += rectHeight

@@ -1874,14 +1941,15 @@
dc.DrawLine(rect.x, rect.y + rect.height, rect.x + rect.width, rect.y + rect.height)


-    def DrawWebHover(self, dc, caption, xCoord, yCoord):
+    def DrawWebHover(self, dc, caption, xCoord, yCoord, selected):
"""
Draws a web style hover effect (cursor set to hand & text is underlined).

:param `dc`: an instance of `wx.DC`;
:param `caption`: the tab caption text;
:param `xCoord`: the x position of the tab caption;
-        :param `yCoord`: the y position of the tab caption.
+        :param `yCoord`: the y position of the tab caption;
+        :param `selected`: ``True`` if the tab is selected, ``False`` otherwise.
"""

# Redraw the text with underlined font
@@ -1889,6 +1957,9 @@
underLinedFont.SetPointSize(underLinedFont.GetPointSize() * self.GetParent().GetFontSizeMultiple())
if self.GetParent().GetFontBold():
underLinedFont.SetWeight(wx.FONTWEIGHT_BOLD)
+        elif self.HasAGWFlag(INB_BOLD_TAB_SELECTION) and selected:
+            underLinedFont.SetWeight(wx.FONTWEIGHT_BOLD)
+
underLinedFont.SetUnderlined(True)
dc.SetFont(underLinedFont)
dc.DrawText(caption, xCoord, yCoord)
@@ -1983,8 +2054,12 @@

font = wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT)
font.SetPointSize(font.GetPointSize() * self.GetParent().GetFontSizeMultiple())
+
if self.GetParent().GetFontBold():
font.SetWeight(wx.FONTWEIGHT_BOLD)
+        elif self.HasAGWFlag(INB_BOLD_TAB_SELECTION) and selected:
+            font.SetWeight(wx.FONTWEIGHT_BOLD)
+
dc.SetFont(font)

# First we define the rectangle for the text
@@ -2076,15 +2151,14 @@

else:

-                if imgIdx+1 != self._nHoeveredImgIdx:
-
+                if imgIdx+1 != self._nHoveredImgIdx:
ArtManager.Get().DrawBitmapShadow(dc, rect, sstyle)

# Draw hover effect
if hover:

if self.HasAGWFlag(INB_WEB_HILITE) and caption != "":
-                self.DrawWebHover(dc, caption, textRect.x, textRect.y)
+                self.DrawWebHover(dc, caption, textRect.x, textRect.y, selected)
else:
self.DrawRegularHover(dc, rect)

@@ -2132,6 +2206,7 @@
``INB_WEB_HILITE``                0x800 On mouse hovering, tabs behave like html hyperlinks. Available only for L{LabelBook}.
``INB_NO_RESIZE``                0x1000 Don't allow resizing of the tab area.
``INB_FIT_LABELTEXT``            0x2000 Will fit the tab area to the longest text (or text+image if you have images) in all the tabs.
+         ``INB_BOLD_TAB_SELECTION``       0x4000 Show the selected tab text using a bold font.
=========================== =========== ==================================================

:param `name`: the window name.
@@ -2151,6 +2226,8 @@
wx.Panel.__init__(self, parent, id, pos, size, style, name)
self._bInitializing = False

+        self.Bind(wx.EVT_NAVIGATION_KEY, self.OnNavigationKey)
+

def SetAGWWindowStyleFlag(self, agwStyle):
"""
@@ -2175,6 +2252,7 @@
``INB_WEB_HILITE``                0x800 On mouse hovering, tabs behave like html hyperlinks. Available only for L{LabelBook}.
``INB_NO_RESIZE``                0x1000 Don't allow resizing of the tab area.
``INB_FIT_LABELTEXT``            0x2000 Will fit the tab area to the longest text (or text+image if you have images) in all the tabs.
+         ``INB_BOLD_TAB_SELECTION``       0x4000 Show the selected tab text using a bold font.
=========================== =========== ==================================================

"""
@@ -2421,7 +2499,7 @@
dc.SelectObject(wx.EmptyBitmap(1, 1))
font = wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT)
font.SetPointSize(font.GetPointSize()*self._fontSizeMultiple)
-            if self.GetFontBold():
+            if self.GetFontBold() or agwStyle & INB_BOLD_TAB_SELECTION:
font.SetWeight(wx.FONTWEIGHT_BOLD)
dc.SetFont(font)
maxW = 0
@@ -2473,6 +2551,9 @@
if page >= len(self._windows):
return

+        if not self.GetEnabled(page):
+            return
+
if page == self.GetSelection() and not self._bForceSelection:
return

@@ -2645,6 +2726,31 @@
return self._pages.GetPageImage(page)


+    def GetEnabled(self, page):
+        """
+        Returns whether a tab is enabled or not.
+
+        :param `page`: an integer specifying the page index.
+        """
+
+        return self._pages.GetEnabled(page)
+
+
+    def EnableTab(self, page, enabled=True):
+        """
+        Enables or disables a tab.
+
+        :param `page`: an integer specifying the page index;
+        :param `enabled`: ``True`` to enable a tab, ``False`` to disable it.
+        """
+
+        if page >= len(self._windows):
+            return
+
+        self._windows[page].Enable(enabled)
+        self._pages.EnableTab(page, enabled)
+
+
def GetPage(self, page):
"""
Returns the window at the given page position.
@@ -2667,6 +2773,24 @@
return self.GetPage(self.GetSelection())


+    def OnNavigationKey(self, event):
+        """
+        Handles the ``wx.EVT_NAVIGATION_KEY`` event for L{FlatBookBase}.
+
+        :param `event`: a `wx.NavigationKeyEvent` event to be processed.
+        """
+
+        if event.IsWindowChange():
+            if self.GetPageCount() == 0:
+                return
+
+            # change pages
+            self.AdvanceSelection(event.GetDirection())
+
+        else:
+            event.Skip()
+
+
def AdvanceSelection(self, forward=True):
"""
Cycles through the tabs.
@@ -2762,6 +2886,7 @@
``INB_WEB_HILITE``                0x800 On mouse hovering, tabs behave like html hyperlinks. Available only for L{LabelBook}.
``INB_NO_RESIZE``                0x1000 Don't allow resizing of the tab area.
``INB_FIT_LABELTEXT``            0x2000 Will fit the tab area to the longest text (or text+image if you have images) in all the tabs.
+         ``INB_BOLD_TAB_SELECTION``       0x4000 Show the selected tab text using a bold font.
=========================== =========== ==================================================

:param `name`: the window name.
@@ -2837,6 +2962,7 @@
``INB_WEB_HILITE``                0x800 On mouse hovering, tabs behave like html hyperlinks. Available only for L{LabelBook}.
``INB_NO_RESIZE``                0x1000 Don't allow resizing of the tab area.
``INB_FIT_LABELTEXT``            0x2000 Will fit the tab area to the longest text (or text+image if you have images) in all the tabs.
+         ``INB_BOLD_TAB_SELECTION``       0x4000 Show the selected tab text using a bold font.
=========================== =========== ==================================================

:param `name`: the window name.
Tree

Table Of Contents

Previous topic

SVN Revision 69803 For labelbook

Next topic

multidirdialog