⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 foldpanelbar.py

📁 Wxpython Implemented on Windows CE, Source code
💻 PY
📖 第 1 页 / 共 5 页
字号:
# --------------------------------------------------------------------------- #
# FOLDPANELBAR wxPython IMPLEMENTATION
# Ported From Jorgen Bodde & Julian Smart (Extended Demo) C++ Code By:
#
# Andrea Gavana, @ 23 Mar 2005
# Latest Revision: 05 Nov 2005, 23.30 CET
#
#
# TODO List
#
# All The C++ TODOs Are Still Alive. I Am Not Able to Read Jorges's Mind
# So I Don't Really Know What Will Be The New Features/Additions He Will
# Make On His Code. At The Moment They Are:
#
# 1. OnPaint Function In CaptionBar Class:
# TODO: Maybe First A Memory Dc Should Draw All, And Then Paint It On The
# Caption. This Way A Flickering Arrow During Resize Is Not Visible.
#
# 2. OnChar Function In CaptionBar Class:
# TODO: This Is Easy To Do But I Don't Have Any Useful Idea On Which Kind
# Of Features To Add. Does Anyone Have An Intelligent Idea?
#
# 3. AddFoldPanelWindow Function In FoldPanelBar Class:
# TODO: Take Old And New Heights, And If Difference, Reposition All The
# Lower Panels. This Is Because The User Can Add New wxWindow Controls
# Somewhere In Between When Other Panels Are Already Present.
# Don't Know What It Means. Probably Is My Poor English...
#
# 4. OnSizePanel Function In FoldPanelBar Class:
# TODO: A Smart Way To Check Wether The Old - New Width Of The
# Panel Changed, If So No Need To Resize The Fold Panel Items
#
#
# DONE List:
#
# 1. Implemented Styles Like FPB_SINGLE_FOLD and FPB_EXCLUSIVE_FOLD
# Thanks To E. A. Tacao For His Nice Suggestions.
#
# 2. Added Some Maquillage To FoldPanelBar: When The Mouse Enters The Icon
# Region, It Is Changed To wx.CURSOR_HAND.
#
#
# For The Original TODO List From Jorgen, Please Refer To:
# http://www.solidsteel.nl/jorg/components/foldpanel/wxFoldPanelBar.php#todo_list
#
#
#
# For All Kind Of Problems, Requests Of Enhancements And Bug Reports, Please
# Write To Me At:
#
# andrea.gavana@agip.it
# andrea_gavan@tin.it
#
# Or, Obviously, To The wxPython Mailing List!!!
#
#
# End Of Comments
# --------------------------------------------------------------------------- #


"""
The `FoldPanelBar` is a control that contains multiple panels (of type
`FoldPanelItem`) that can be expanded or collapsed. The captionbar of
the FoldPanel can be customized by setting it to a horizontal gradient
style, vertical gradient style, a single color, a rectangle or filled
rectangle. The FoldPanel items can be collapsed in place or to the
bottom of the control. `wx.Window` derived controls can be added
dynamically, and separated by separator lines.  FoldPanelBar is
freeware and distributed under the wxPython license.
 
   
How does it work
----------------

The internals of the FoldPanelBar is a list of FoldPanelItem objects. Through
the reference of FoldPanel these panels can be controlled by adding new controls
to a FoldPanel or adding new FoldPanels to the FoldPanelBar. 
The CaptionBar fires events to the parent (container of all panel items) when a
sub-panel needs resizing (either folding or expanding). The fold or expand process
is simply a resize of the panel so it looks like all controls on it are gone. All
controls are still child of the FoldPanel they are located on. If they don't
handle the event (and they won't) then the owner of the FoldPanelBar gets the
events. This is what you need to handle the controls. There isn't much to it just
a lot of calculations to see what panel belongs where. There are no sizers
involved in the panels, everything is purely x-y positioning. 


What can it do and what not?
----------------------------

    a) What it can do:
        * Run-time addition of panels (no deletion just yet) 
        * Run time addition of controls to the panel (it will be resized accordingly)
        * Creating panels in collapsed mode or expanded mode 
        * Various modes of caption behaviour and filling to make it more appealing 
        * Panels can be folded and collapsed (or all of them) to allow more space
        
    b) What it cannot do:

        * Selection of a panel like in a list ctrl 
        * Dragging and dropping the panels 
        * Re-ordering the panels (not yet)  

 
Supported platforms
-------------------

FoldPanelBar is supported on the following platforms: 
  * Windows (Verified on Windows XP, 2000)
  * Linux/Unix (GTK2) (Thanks To Toni Brkic And Robin Dunn)
  * Mac OSX (Thanks To Robin Dunn For The CaptionBar Size Patch)


FoldPanelBar is based upon Jorgen Bodde's C++ implementation.
Latest Revision: Andrea Gavana @ 05 Nov 2005, 23.30 CET

"""

import wx

#----------------------------------------------------------------------
# Collapsed And Expanded Bitmap Images
# Created With img2py.py 
#----------------------------------------------------------------------

def GetCollapsedIconData():
    return \
'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\
\x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\
\x00\x007IDAT8\x8dcddbf\xa0\x040Q\xa4{\xf0\x1b\xf0\xff\xdf\xdf\xff\x03\xe7\
\x02\x98\xed\x84\\A\x1b\x17\xa0\xdb\x8a\xcf\x15\xd4w\x01.\xdbp\x89S\xec\x02\
\xc6\xd1\xbc\xc0\x00\x00\x9a\xf5\x1b\xfa\xf9m$?\x00\x00\x00\x00IEND\xaeB`\
\x82' 

def GetCollapsedIconBitmap():
    return wx.BitmapFromImage(GetCollapsedIconImage())

def GetCollapsedIconImage():
    import  cStringIO
    stream = cStringIO.StringIO(GetCollapsedIconData())
    return wx.ImageFromStream(stream)

#----------------------------------------------------------------------
def GetExpandedIconData():
    return \
'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\
\x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\
\x00\x00BIDAT8\x8dcddbf\xa0\x040Q\xa4{P\x18\xc0\x82.\xf0\xff\xdf\xdf\xff\xb8\
\x143213R\xdd\x05\x18\x06`\xb3\x05\x9f8m\x02\x11\xdd6\\\xb6\xd3\xce\x05\xc8\
\xb6\xe2\xb3\x9d*.`\x1c\xcd\x0b\x0c\x00\x9e\xbc\x04W\x19\xcfa\xb5\x00\x00\
\x00\x00IEND\xaeB`\x82' 

def GetExpandedIconBitmap():
    return wx.BitmapFromImage(GetExpandedIconImage())

def GetExpandedIconImage():
    import  cStringIO
    stream = cStringIO.StringIO(GetExpandedIconData())
    return wx.ImageFromStream(stream)

#----------------------------------------------------------------------

#----------------------------------------------------------------------
# FOLDPANELBAR Starts Here
#----------------------------------------------------------------------

# CAPTIONBAR STYLES
#
#- CAPTIONBAR_GRADIENT_V: Draws a vertical gradient from top to bottom
#- CAPTIONBAR_GRADIENT_H: Draws a horizontal gradient from left to right
#- CAPTIONBAR_SINGLE: Draws a single filled rectangle to draw the caption
#- CAPTIONBAR_RECTANGLE: Draws a single colour with a rectangle around the caption
#- CAPTIONBAR_FILLED_RECTANGLE: Draws a filled rectangle and a border around it

CAPTIONBAR_NOSTYLE            = 0
CAPTIONBAR_GRADIENT_V         = 1
CAPTIONBAR_GRADIENT_H         = 2
CAPTIONBAR_SINGLE             = 3
CAPTIONBAR_RECTANGLE          = 4
CAPTIONBAR_FILLED_RECTANGLE   = 5

FPB_EXTRA_X = 10
FPB_EXTRA_Y = 4

# pixels of the bmp to be aligned from the right filled with space
FPB_BMP_RIGHTSPACE = 2

# Now supported! Single fold forces
# other panels to close when they are open, and only opens the current panel.
# This will allow the open panel to gain the full size left in the client area
FPB_SINGLE_FOLD = 0x0001

# All panels are stacked to the bottom. When they are expanded again they
# show up at the top
FPB_COLLAPSE_TO_BOTTOM = 0x0002

# Now supported! Single fold plus panels
# will be stacked at the bottom
FPB_EXCLUSIVE_FOLD = 0x0004

# Orientation Flag 
FPB_HORIZONTAL = wx.HORIZONTAL
FPB_VERTICAL = wx.VERTICAL  

# Default Extrastyle of the FoldPanelBar 
FPB_DEFAULT_EXTRASTYLE = 0
# Default style of the FoldPanelBar 
FPB_DEFAULT_STYLE = wx.TAB_TRAVERSAL | wx.NO_BORDER

# FoldPanelItem default settings
FPB_ALIGN_LEFT = 0 
FPB_ALIGN_WIDTH = 1

FPB_DEFAULT_LEFTSPACING = 5
FPB_DEFAULT_RIGHTSPACING = 10
FPB_DEFAULT_SPACING = 8

FPB_DEFAULT_LEFTLINESPACING = 2
FPB_DEFAULT_RIGHTLINESPACING = 2


# ------------------------------------------------------------------------------ #
# class CaptionBarStyle
# ------------------------------------------------------------------------------ #

class CaptionBarStyle:
    """
    This class encapsulates the styles you wish to set for the
    `CaptionBar` (this is the part of the FoldPanel where the caption
    is displayed). It can either be applied at creation time be
    reapplied when styles need to be changed.

    At construction time, all styles are set to their default
    transparency.  This means none of the styles will be applied to
    the `CaptionBar` in question, meaning it will be created using the
    default internals. When setting i.e the color, font or panel
    style, these styles become active to be used.
    
    """

    def __init__(self):
        """ Default constructor for this class."""
        
        self.ResetDefaults()


    def ResetDefaults(self):
        """ Resets default CaptionBarStyle."""        
        self._firstColourUsed = False
        self._secondColourUsed = False
        self._textColourUsed = False
        self._captionFontUsed = False
        self._captionStyleUsed = False
        self._captionStyle = CAPTIONBAR_GRADIENT_V


    # ------- CaptionBar Font -------
    
    def SetCaptionFont(self, font):
        """
        Sets font for the caption bar.

        If this is not set, the font property is undefined and will
        not be used. Use `CaptionFontUsed` to check if this style is
        used.
        """        
        self._captionFont = font
        self._captionFontUsed = True


    def CaptionFontUsed(self):
        """ Checks if the caption bar font is set. """        
        return self._captionFontUsed


    def GetCaptionFont(self):
        """
        Returns the font for the caption bar.

        Please be warned this will result in an assertion failure when
        this property is not previously set.
        
        :see: `SetCaptionFont`, `CaptionFontUsed`
        """        
        return self._captionFont


    # ------- First Colour -------
    
    def SetFirstColour(self, colour):
        """
        Sets first colour for the caption bar.

        If this is not set, the colour property is undefined and will
        not be used. Use `FirstColourUsed` to check if this style is
        used.
        """        
        self._firstColour = colour
        self._firstColourUsed = True


    def FirstColourUsed(self):
        """ Checks if the first colour of the caption bar is set."""        
        return self._firstColourUsed


    def GetFirstColour(self):
        """
        Returns the first colour for the caption bar.

        Please be warned this will result in an assertion failure when
        this property is not previously set.
        
        :see: `SetFirstColour`, `FirstColourUsed`
        """        
        return self._firstColour


    # ------- Second Colour -------
    
    def SetSecondColour(self, colour):
        """
        Sets second colour for the caption bar.

        If this is not set, the colour property is undefined and will
        not be used. Use `SecondColourUsed` to check if this style is
        used.
        """        
        self._secondColour = colour
        self._secondColourUsed = True


    def SecondColourUsed(self):
        """ Checks if the second colour of the caption bar is set."""        
        return self._secondColourUsed


    def GetSecondColour(self):
        """
        Returns the second colour for the caption bar.

        Please be warned this will result in an assertion failure when
        this property is not previously set.
        
        :see: `SetSecondColour`, `SecondColourUsed`
        """        
        return self._secondColour


    # ------- Caption Text Colour -------
    
    def SetCaptionColour(self, colour):
        """
        Sets caption colour for the caption bar.

        If this is not set, the colour property is undefined and will
        not be used. Use `CaptionColourUsed` to check if this style is
        used.
        """        
        self._textColour = colour
        self._textColourUsed = True


    def CaptionColourUsed(self):
        """ Checks if the caption colour of the caption bar is set."""        
        return self._textColourUsed


    def GetCaptionColour(self):
        """
        Returns the caption colour for the caption bar.

        Please be warned this will result in an assertion failure
        when this property is not previously set.
        See also SetCaptionColour(), CaptionColourUsed()
        """        
        return self._textColour


    # ------- CaptionStyle  -------
    
    def SetCaptionStyle(self, style):

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -