Docstring updates

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34032 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2005-05-12 22:46:53 +00:00
parent 948ee5ea30
commit 4e5d278c12
9 changed files with 615 additions and 542 deletions

View File

@@ -20,6 +20,9 @@
# o Many ehnacements # o Many ehnacements
# #
"""
`AnalogClockWindow` is a simple analog clock class.
"""
import math import math
import sys import sys

View File

@@ -1,5 +1,5 @@
#---------------------------------------------------------------------- #----------------------------------------------------------------------
# Name: wx.lib.aanalogclockopts # Name: wx.lib.analogclockopts
# Purpose: An analog clock window - setup frame # Purpose: An analog clock window - setup frame
# #
# Author: E. A. Tacao # Author: E. A. Tacao
@@ -10,6 +10,10 @@
# Originally generated by wx.Glade 0.3.1 on Wed Feb 18 00:05:35 2004 # Originally generated by wx.Glade 0.3.1 on Wed Feb 18 00:05:35 2004
# Converted to wx namespace by Peter Damoc # Converted to wx namespace by Peter Damoc
"""
A configuration dialog (frame actually) for the AnalogClockWindow
"""
import wx import wx
import wx.lib.colourselect as csel import wx.lib.colourselect as csel

View File

@@ -15,6 +15,10 @@
# o Updated for wx namespace # o Updated for wx namespace
# o Tested with updated demo # o Tested with updated demo
# #
"""
`LayoutAnchors` is a class that implements Delphi's Anchors using
`wx.LayoutConstraints`.
"""
import wx import wx

View File

@@ -18,18 +18,9 @@
""" """
This module implements various forms of generic buttons, meaning that This module implements various forms of generic buttons, meaning that
they are not built on native controls but are self-drawn. they are not built on native controls but are self-drawn. They act
like normal buttons but you are able to better control how they look,
The GenButton is the base. It acts like a normal button but you bevel width, colours, etc.
are able to better control how it looks, bevel width, colours, etc.
GenBitmapButton is a button with one or more bitmaps that show
the various states the button can be in.
GenToggleButton stays depressed when clicked, until clicked again.
GenBitmapToggleButton the same but with bitmaps.
""" """
import wx import wx
@@ -39,6 +30,7 @@ import imageutils
#---------------------------------------------------------------------- #----------------------------------------------------------------------
class GenButtonEvent(wx.PyCommandEvent): class GenButtonEvent(wx.PyCommandEvent):
"""Event sent from the generic buttons when the button is activated. """
def __init__(self, eventType, ID): def __init__(self, eventType, ID):
wx.PyCommandEvent.__init__(self, eventType, ID) wx.PyCommandEvent.__init__(self, eventType, ID)
self.isDown = False self.isDown = False
@@ -60,6 +52,8 @@ class GenButtonEvent(wx.PyCommandEvent):
#---------------------------------------------------------------------- #----------------------------------------------------------------------
class GenButton(wx.PyControl): class GenButton(wx.PyControl):
"""A generic button, and base class for the other generic buttons."""
labelDelta = 1 labelDelta = 1
def __init__(self, parent, ID, label, def __init__(self, parent, ID, label,
@@ -356,6 +350,8 @@ class GenButton(wx.PyControl):
#---------------------------------------------------------------------- #----------------------------------------------------------------------
class GenBitmapButton(GenButton): class GenBitmapButton(GenButton):
"""A generic bitmap button."""
def __init__(self, parent, ID, bitmap, def __init__(self, parent, ID, bitmap,
pos = wx.DefaultPosition, size = wx.DefaultSize, pos = wx.DefaultPosition, size = wx.DefaultSize,
style = 0, validator = wx.DefaultValidator, style = 0, validator = wx.DefaultValidator,
@@ -429,7 +425,8 @@ class GenBitmapButton(GenButton):
#---------------------------------------------------------------------- #----------------------------------------------------------------------
class GenBitmapTextButton(GenBitmapButton): # generic bitmapped button with Text Label class GenBitmapTextButton(GenBitmapButton):
"""A generic bitmapped button with text label"""
def __init__(self, parent, ID, bitmap, label, def __init__(self, parent, ID, bitmap, label,
pos = wx.DefaultPosition, size = wx.DefaultSize, pos = wx.DefaultPosition, size = wx.DefaultSize,
style = 0, validator = wx.DefaultValidator, style = 0, validator = wx.DefaultValidator,
@@ -550,12 +547,15 @@ class __ToggleMixin:
class GenToggleButton(__ToggleMixin, GenButton): class GenToggleButton(__ToggleMixin, GenButton):
"""A generic toggle button"""
pass pass
class GenBitmapToggleButton(__ToggleMixin, GenBitmapButton): class GenBitmapToggleButton(__ToggleMixin, GenBitmapButton):
"""A generic toggle bitmap button"""
pass pass
class GenBitmapTextToggleButton(__ToggleMixin, GenBitmapTextButton): class GenBitmapTextToggleButton(__ToggleMixin, GenBitmapTextButton):
"""A generic toggle bitmap button with text label"""
pass pass
#---------------------------------------------------------------------- #----------------------------------------------------------------------

View File

@@ -12,16 +12,19 @@
#---------------------------------------------------------------------- #----------------------------------------------------------------------
""" """
Load color names/values from the rgb.txt file on my system... Load addition color names/values into the wx colour database. These
names and values originally came from the rgb.txt file on my system...
""" """
def getColourList(): def getColourList():
"""Returns a list of just the colour names used by this module."""
return [ x[0] for x in getColourInfoList() ] return [ x[0] for x in getColourInfoList() ]
def getColourInfoList(): def getColourInfoList():
"""Returns the list of colour name/value tuples used by this module."""
return [ return [
("SNOW", 255, 250, 250), ("SNOW", 255, 250, 250),
("GHOST WHITE", 248, 248, 255), ("GHOST WHITE", 248, 248, 255),
@@ -659,6 +662,7 @@ def getColourInfoList():
_haveUpdated = False _haveUpdated = False
def updateColourDB(): def updateColourDB():
"""Updates the wx colour database by adding new colour names and RGB values."""
global _haveUpdated global _haveUpdated
if not _haveUpdated: if not _haveUpdated:
import wx import wx

View File

@@ -32,6 +32,12 @@
# o Updated for 2.5 compatability. # o Updated for 2.5 compatability.
# #
"""
Provides a `ColourSelect` button that, when clicked, will display a
colour selection dialog. The selected colour is displayed on the
button itself.
"""
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
import wx import wx

File diff suppressed because it is too large Load Diff

View File

@@ -17,20 +17,20 @@
# #
""" """
A module that allows multiple handlers to respond to single wxWindows A module that allows multiple handlers to respond to single wxWidgets
events. This allows true NxN Observer/Observable connections: One events. This allows true NxN Observer/Observable connections: One
event can be received by multiple handlers, and one handler can event can be received by multiple handlers, and one handler can
receive multiple events. receive multiple events.
There are two ways to register event handlers. The first way is There are two ways to register event handlers. The first way is
similar to standard wxPython handler registration: similar to standard wxPython handler registration::
from wxPython.lib.evtmgr import eventManager from wx.lib.evtmgr import eventManager
eventManager.Register(handleEvents, EVT_BUTTON, win=frame, id=101) eventManager.Register(handleEvents, EVT_BUTTON, win=frame, id=101)
There's also a new object-oriented way to register for events. This There's also a new object-oriented way to register for events. This
invocation is equivalent to the one above, but does not require the invocation is equivalent to the one above, but does not require the
programmer to declare or track control ids or parent containers: programmer to declare or track control ids or parent containers::
eventManager.Register(handleEvents, EVT_BUTTON, myButton) eventManager.Register(handleEvents, EVT_BUTTON, myButton)
@@ -64,14 +64,17 @@ class EventManager:
Registers a listener function (or any callable object) to Registers a listener function (or any callable object) to
receive events of type event coming from the source window. receive events of type event coming from the source window.
For example:: For example::
eventManager.Register(self.OnButton, EVT_BUTTON, theButton) eventManager.Register(self.OnButton, EVT_BUTTON, theButton)
Alternatively, the specific window where the event is Alternatively, the specific window where the event is
delivered, and/or the ID of the event source can be specified. delivered, and/or the ID of the event source can be specified.
For example:: For example::
eventManager.Register(self.OnButton, EVT_BUTTON, win=self, id=ID_BUTTON) eventManager.Register(self.OnButton, EVT_BUTTON, win=self, id=ID_BUTTON)
or:: or::
eventManager.Register(self.OnButton, EVT_BUTTON, theButton, self) eventManager.Register(self.OnButton, EVT_BUTTON, theButton, self)
""" """

View File

@@ -53,18 +53,19 @@
# --------------------------------------------------------------------------- # # --------------------------------------------------------------------------- #
"""Description: """
The `FoldPanelBar` is a control that contains multiple panels (of type
The FoldPanelBar is a control that contains multiple panels (FoldPanel items) `FoldPanelItem`) that can be expanded or collapsed. The captionbar of
that can be expanded or collapsed. The captionbar of the FoldPanel can be the FoldPanel can be customized by setting it to a horizontal gradient
customized by setting it to a horizontal gradient style, vertical gradient style, style, vertical gradient style, a single color, a rectangle or filled
a single color, a rectangle or filled rectangle. The FoldPanel items can be rectangle. The FoldPanel items can be collapsed in place or to the
collapsed in place or to the bottom of the control. The wxWindow derived controls bottom of the control. `wx.Window` derived controls can be added
can be added dynamically, and separated by separator lines. dynamically, and separated by separator lines. FoldPanelBar is
FoldPanelBar is freeware and distributed under the wxPython license. freeware and distributed under the wxPython license.
- How does it work: How does it work
----------------
The internals of the FoldPanelBar is a list of FoldPanelItem objects. Through 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 the reference of FoldPanel these panels can be controlled by adding new controls
@@ -79,28 +80,30 @@ a lot of calculations to see what panel belongs where. There are no sizers
involved in the panels, everything is purely x-y positioning. involved in the panels, everything is purely x-y positioning.
- What can it do and what not? What can it do and what not?
----------------------------
a) What it can do: a) What it can do:
Run-time addition of panels (no deletion just yet) * Run-time addition of panels (no deletion just yet)
Run time addition of controls to the panel (it will be resized accordingly) * Run time addition of controls to the panel (it will be resized accordingly)
Creating panels in collapsed mode or expanded mode * Creating panels in collapsed mode or expanded mode
Various modes of caption behaviour and filling to make it more appealing * 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 * Panels can be folded and collapsed (or all of them) to allow more space
b) What it cannot do: b) What it cannot do:
Selection of a panel like in a list ctrl * Selection of a panel like in a list ctrl
Dragging and dropping the panels * Dragging and dropping the panels
Re-ordering the panels (not yet) * Re-ordering the panels (not yet)
- Supported platforms Supported platforms
-------------------
FoldPanelBar is supported on the following platforms: FoldPanelBar is supported on the following platforms:
Windows (Verified on Windows XP, 2000) * Windows (Verified on Windows XP, 2000)
Linux/Unix (GTK2) (Thanks To Toni Brkic And Robin Dunn) * Linux/Unix (GTK2) (Thanks To Toni Brkic And Robin Dunn)
Mac OSX (Thanks To Robin Dunn For The CaptionBar Size Patch) * Mac OSX (Thanks To Robin Dunn For The CaptionBar Size Patch)
Latest Revision: Andrea Gavana @ 30 Mar 2005, 22.30 CET Latest Revision: Andrea Gavana @ 30 Mar 2005, 22.30 CET
@@ -212,18 +215,22 @@ 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.
# ------------------------------------------------------------------------------ # # ------------------------------------------------------------------------------ #
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): def __init__(self):
""" Default constructor for this class.""" """ Default constructor for this class."""
@@ -232,8 +239,7 @@ class CaptionBarStyle:
def ResetDefaults(self): def ResetDefaults(self):
""" Resets Default CaptionBarStyle.""" """ Resets default CaptionBarStyle."""
self._firstColourUsed = False self._firstColourUsed = False
self._secondColourUsed = False self._secondColourUsed = False
self._textColourUsed = False self._textColourUsed = False
@@ -248,17 +254,16 @@ class CaptionBarStyle:
""" """
Sets font for the caption bar. Sets font for the caption bar.
If this is not set, the font property is undefined and will not If this is not set, the font property is undefined and will
be used. Use CaptionFontUsed() to check if this style is used. not be used. Use `CaptionFontUsed` to check if this style is
used.
""" """
self._captionFont = font self._captionFont = font
self._captionFontUsed = True self._captionFontUsed = True
def CaptionFontUsed(self): def CaptionFontUsed(self):
""" Checks if the caption bar font is set. """ """ Checks if the caption bar font is set. """
return self._captionFontUsed return self._captionFontUsed
@@ -268,9 +273,9 @@ class CaptionBarStyle:
Please be warned this will result in an assertion failure when Please be warned this will result in an assertion failure when
this property is not previously set. this property is not previously set.
See also SetCaptionFont(), CaptionFontUsed()
"""
:see: `SetCaptionFont`, `CaptionFontUsed`
"""
return self._captionFont return self._captionFont
@@ -280,17 +285,16 @@ class CaptionBarStyle:
""" """
Sets first colour for the caption bar. Sets first colour for the caption bar.
If this is not set, the colour property is undefined and will not If this is not set, the colour property is undefined and will
be used. Use FirstColourUsed() to check if this style is used. not be used. Use `FirstColourUsed` to check if this style is
used.
""" """
self._firstColour = colour self._firstColour = colour
self._firstColourUsed = True self._firstColourUsed = True
def FirstColourUsed(self): def FirstColourUsed(self):
""" Checks if the first colour of the caption bar is set.""" """ Checks if the first colour of the caption bar is set."""
return self._firstColourUsed return self._firstColourUsed
@@ -298,11 +302,11 @@ class CaptionBarStyle:
""" """
Returns the first colour for the caption bar. Returns the first colour for the caption bar.
Please be warned this will result in an assertion failure Please be warned this will result in an assertion failure when
when this property is not previously set. this property is not previously set.
See also SetCaptionFirstColour(), CaptionFirstColourUsed()
"""
:see: `SetFirstColour`, `FirstColourUsed`
"""
return self._firstColour return self._firstColour
@@ -312,28 +316,28 @@ class CaptionBarStyle:
""" """
Sets second colour for the caption bar. Sets second colour for the caption bar.
If this is not set, the colour property is undefined and will not If this is not set, the colour property is undefined and will
be used. Use SecondColourUsed() to check if this style is used. not be used. Use `SecondColourUsed` to check if this style is
used.
""" """
self._secondColour = colour self._secondColour = colour
self._secondColourUsed = True self._secondColourUsed = True
def SecondColourUsed(self): def SecondColourUsed(self):
""" Checks if the second colour of the caption bar is set.""" """ Checks if the second colour of the caption bar is set."""
return self._secondColourUsed return self._secondColourUsed
def GetSecondColour(self): def GetSecondColour(self):
""" """
Returns the second colour for the caption bar. Returns the second colour for the caption bar.
Please be warned this will result in an assertion failure Please be warned this will result in an assertion failure when
when this property is not previously set. this property is not previously set.
See also SetCaptionSecondColour(), CaptionSecondColourUsed()
"""
:see: `SetSecondColour`, `SecondColourUsed`
"""
return self._secondColour return self._secondColour
@@ -343,17 +347,16 @@ class CaptionBarStyle:
""" """
Sets caption colour for the caption bar. Sets caption colour for the caption bar.
If this is not set, the colour property is undefined and will not If this is not set, the colour property is undefined and will
be used. Use CaptionColourUsed() to check if this style is used. not be used. Use `CaptionColourUsed` to check if this style is
used.
""" """
self._textColour = colour self._textColour = colour
self._textColourUsed = True self._textColourUsed = True
def CaptionColourUsed(self): def CaptionColourUsed(self):
""" Checks if the caption colour of the caption bar is set.""" """ Checks if the caption colour of the caption bar is set."""
return self._textColourUsed return self._textColourUsed
@@ -365,7 +368,6 @@ class CaptionBarStyle:
when this property is not previously set. when this property is not previously set.
See also SetCaptionColour(), CaptionColourUsed() See also SetCaptionColour(), CaptionColourUsed()
""" """
return self._textColour return self._textColour
@@ -375,23 +377,31 @@ class CaptionBarStyle:
""" """
Sets caption style for the caption bar. Sets caption style for the caption bar.
If this is not set, the property is undefined and will not If this is not set, the property is undefined and will not be
be used. Use CaptionStyleUsed() to check if this style is used. used. Use CaptionStyleUsed() to check if this style is used.
The following styles can be applied: The following styles can be applied:
- 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_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
"""
self._captionStyle = style self._captionStyle = style
self._captionStyleUsed = True self._captionStyleUsed = True
def CaptionStyleUsed(self): def CaptionStyleUsed(self):
""" Checks if the caption style of the caption bar is set.""" """ Checks if the caption style of the caption bar is set."""
return self._captionStyleUsed return self._captionStyleUsed
@@ -401,9 +411,9 @@ class CaptionBarStyle:
Please be warned this will result in an assertion failure Please be warned this will result in an assertion failure
when this property is not previously set. when this property is not previously set.
See also SetCaptionStyle(), CaptionStyleUsed()
"""
:see: `SetCaptionStyle`, `CaptionStyleUsed`
"""
return self._captionStyle return self._captionStyle
@@ -416,65 +426,66 @@ EVT_CAPTIONBAR = wx.PyEventBinder(wxEVT_CAPTIONBAR, 0)
# ---------------------------------------------------------------------------- # # ---------------------------------------------------------------------------- #
# class CaptionBarEvent # class CaptionBarEvent
# This event will be sent when a EVT_CAPTIONBAR is mapped in the parent.
# It is to notify the parent that the bar is now in collapsed or expanded
# state. The parent should re-arrange the associated windows accordingly
# ---------------------------------------------------------------------------- # # ---------------------------------------------------------------------------- #
class CaptionBarEvent(wx.PyCommandEvent): class CaptionBarEvent(wx.PyCommandEvent):
"""
This event will be sent when a EVT_CAPTIONBAR is mapped in the parent.
It is to notify the parent that the bar is now in collapsed or expanded
state. The parent should re-arrange the associated windows accordingly
"""
def __init__(self, evtType): def __init__(self, evtType):
""" Default Constructor For This Class.""" """ Default Constructor For This Class."""
wx.PyCommandEvent.__init__(self, evtType) wx.PyCommandEvent.__init__(self, evtType)
def GetFoldStatus(self): def GetFoldStatus(self):
""" Returns Wether The Bar Is Expanded Or Collapsed. True Means Expanded.""" """
Returns whether the bar is expanded or collapsed. True means
expanded.
"""
return not self._bar.IsCollapsed() return not self._bar.IsCollapsed()
def GetBar(self): def GetBar(self):
""" Returns The CaptionBar Selected.""" """ Returns The CaptionBar Selected."""
return self._bar return self._bar
def SetTag(self, tag): def SetTag(self, tag):
""" Assign A Tag To The Selected CaptionBar.""" """ Assign A Tag To The Selected CaptionBar."""
self._tag = tag self._tag = tag
def GetTag(self): def GetTag(self):
""" Returns The Tag Assigned To The Selected CaptionBar.""" """ Returns The Tag Assigned To The Selected CaptionBar."""
return self._tag return self._tag
def SetBar(self, bar): def SetBar(self, bar):
""" """
Sets The Bar Associated With This Event. Sets the bar associated with this event.
Should Not Used By Any Other Then The Originator Of The Event. Should not used by any other then the originator of the event.
""" """
self._bar = bar self._bar = bar
# -------------------------------------------------------------------------------- # # -------------------------------------------------------------------------------- #
# class CaptionBar # class CaptionBar
# This class is a graphical caption component that consists of a caption and
# a clickable arrow.
#
# The CaptionBar fires an event EVT_CAPTIONBAR which is a CaptionBarEvent.
# This event can be caught and the parent window can act upon the collapsed
# or expanded state of the bar (which is actually just the icon which changed).
# The parent panel can reduce size or expand again.
# -------------------------------------------------------------------------------- # # -------------------------------------------------------------------------------- #
class CaptionBar(wx.Window): class CaptionBar(wx.Window):
"""
This class is a graphical caption component that consists of a
caption and a clickable arrow.
The CaptionBar fires an event EVT_CAPTIONBAR which is a
`CaptionBarEvent`. This event can be caught and the parent window
can act upon the collapsed or expanded state of the bar (which is
actually just the icon which changed). The parent panel can
reduce size or expand again.
"""
# Define Empty CaptionBar Style # Define Empty CaptionBar Style
EmptyCaptionBarStyle = CaptionBarStyle() EmptyCaptionBarStyle = CaptionBarStyle()
@@ -559,42 +570,41 @@ class CaptionBar(wx.Window):
""" """
Sets CaptionBar styles with CapionBarStyle class. Sets CaptionBar styles with CapionBarStyle class.
All styles that are actually set, are applied. If you set applyDefault All styles that are actually set, are applied. If you set
to True, all other (not defined) styles will be set to default. If it applyDefault to True, all other (not defined) styles will be
is False, the styles which are not set in the CaptionBarStyle will be set to default. If it is False, the styles which are not set
ignored. in the CaptionBarStyle will be ignored.
""" """
self.ApplyCaptionStyle(cbstyle, applyDefault) self.ApplyCaptionStyle(cbstyle, applyDefault)
self.Refresh() self.Refresh()
def GetCaptionStyle(self): def GetCaptionStyle(self):
""" """
Returns the current style of the captionbar in a CaptionBarStyle class. Returns the current style of the captionbar in a
`CaptionBarStyle` class.
This can be used to change and set back the changes. This can be used to change and set back the changes.
""" """
return self._style return self._style
def IsCollapsed(self): def IsCollapsed(self):
""" """
Returns wether the status of the bar is expanded or collapsed. """ Returns wether the status of the bar is expanded or collapsed.
"""
return self._collapsed return self._collapsed
def SetRightIndent(self, pixels): def SetRightIndent(self, pixels):
""" """
Sets the amount of pixels on the right from which the bitmap is trailing. Sets the amount of pixels on the right from which the bitmap
is trailing.
If this is 0, it will be drawn all the way to the right, default is If this is 0, it will be drawn all the way to the right,
equal to FPB_BMP_RIGHTSPACE. Assign this before assigning an image default is equal to FPB_BMP_RIGHTSPACE. Assign this before
list to prevent a redraw. assigning an image list to prevent a redraw.
""" """
assert pixels >= 0 assert pixels >= 0
self._rightIndent = pixels self._rightIndent = pixels
if self._foldIcons: if self._foldIcons:
@@ -605,9 +615,9 @@ class CaptionBar(wx.Window):
""" """
This sets the internal state / representation to collapsed. This sets the internal state / representation to collapsed.
This does not trigger a CaptionBarEvent to be sent to the parent. This does not trigger a `CaptionBarEvent` to be sent to the
parent.
""" """
self._collapsed = True self._collapsed = True
self.RedrawIconBitmap() self.RedrawIconBitmap()
@@ -616,9 +626,9 @@ class CaptionBar(wx.Window):
""" """
This sets the internal state / representation to expanded. This sets the internal state / representation to expanded.
This does not trigger a CaptionBarEvent to be sent to the parent. This does not trigger a `CaptionBarEvent` to be sent to the
parent.
""" """
self._collapsed = False self._collapsed = False
self.RedrawIconBitmap() self.RedrawIconBitmap()
@@ -693,7 +703,10 @@ class CaptionBar(wx.Window):
def FillCaptionBackground(self, dc): def FillCaptionBackground(self, dc):
""" Fills the background of the caption with either a gradient or a solid color. """ """
Fills the background of the caption with either a gradient or
a solid color.
"""
style = self._style.GetCaptionStyle() style = self._style.GetCaptionStyle()
@@ -721,8 +734,9 @@ class CaptionBar(wx.Window):
""" """
Catches the mouse click-double click. Catches the mouse click-double click.
If clicked on the arrow (single) or double on the caption we change state If clicked on the arrow (single) or double on the caption we
and an event must be fired to let this panel collapse or expand. change state and an event must be fired to let this panel
collapse or expand.
""" """
send_event = False send_event = False
@@ -752,14 +766,15 @@ class CaptionBar(wx.Window):
def OnChar(self, event): def OnChar(self, event):
""" Unused Methods. Any Ideas?!?""" """ Unused Methods. Any Ideas?!?"""
# TODO: Anything here? # TODO: Anything here?
event.Skip() event.Skip()
def DoGetBestSize(self): def DoGetBestSize(self):
""" Returns the best size for this panel, based upon the font assigned """
to this window, and the caption string""" Returns the best size for this panel, based upon the font
assigned to this window, and the caption string
"""
if self.IsVertical(): if self.IsVertical():
x, y = self.GetTextExtent(self._caption) x, y = self.GetTextExtent(self._caption)
@@ -945,23 +960,26 @@ class CaptionBar(wx.Window):
# ---------------------------------------------------------------------------------- # # ---------------------------------------------------------------------------------- #
# class FoldPanelBar # class FoldPanelBar
# The FoldPanelBar is a class which can maintain a list of collapsable panels.
# Once a panel is collapsed, only it's panel bar is visible to the user. This
# will provide more space for the other panels, or allow the user to close
# panels which are not used often to get the most out of the work area.
#
# This control is easy to use. Simply create it as a child for a panel or
# sash window, and populate panels with FoldPanelBar.AddFoldPanel(). Then use
# the FoldPanelBar.AddFoldPanelWindow() to add wxWindow derived controls to the
# current fold panel. Use FoldPanelBar.AddFoldPanelSeparator() to put separators
# between the groups of controls that need a visual separator to group them
# together. After all is constructed, the user can fold the panels by
# doubleclicking on the bar or single click on the arrow, which will indicate
# the collapsed or expanded state.
# ---------------------------------------------------------------------------------- # # ---------------------------------------------------------------------------------- #
class FoldPanelBar(wx.Panel): class FoldPanelBar(wx.Panel):
"""
The FoldPanelBar is a class which can maintain a list of
collapsable panels. Once a panel is collapsed, only it's caption
bar is visible to the user. This will provide more space for the
other panels, or allow the user to close panels which are not used
often to get the most out of the work area.
This control is easy to use. Simply create it as a child for a
panel or sash window, and populate panels with
`AddFoldPanel`. Then use the AdddFoldPanelWindow` to add
`wx.Window` derived controls to the current fold panel. Use
`AddFoldPanelSeparator` to put separators between the groups of
controls that need a visual separator to group them
together. After all is constructed, the user can fold the panels
by doubleclicking on the bar or single click on the arrow, which
will indicate the collapsed or expanded state.
"""
# Define Empty CaptionBar Style # Define Empty CaptionBar Style
EmptyCaptionBarStyle = CaptionBarStyle() EmptyCaptionBarStyle = CaptionBarStyle()
@@ -1004,15 +1022,14 @@ class FoldPanelBar(wx.Panel):
""" """
Adds a fold panel to the list of panels. Adds a fold panel to the list of panels.
If the flag collapsed is set to True, the panel is collapsed initially. If the flag collapsed is set to True, the panel is collapsed
The FoldPanel item which is returned, can be used as a reference to initially. The FoldPanel item which is returned, can be used
perform actions upon the fold panel like collapsing it, expanding it, as a reference to perform actions upon the fold panel like
or deleting it from the list. collapsing it, expanding it, or deleting it from the list.
Use this foldpanel to add windows to it. Please consult Use this foldpanel to add windows to it. Please consult
FoldPanelBar.AddFoldPanelWindow() and `AddFoldPanelWindow` and `AddFoldPanelSeparator` to know how
FoldPanelBar.AddFoldPanelSeparator() to know how to add wxWindow items to add items derived from `wx.Window` to the panels.
to the panels.
""" """
# create a fold panel item, which is first only the caption. # create a fold panel item, which is first only the caption.
@@ -1046,28 +1063,31 @@ class FoldPanelBar(wx.Panel):
leftSpacing=FPB_DEFAULT_LEFTLINESPACING, leftSpacing=FPB_DEFAULT_LEFTLINESPACING,
rightSpacing=FPB_DEFAULT_RIGHTLINESPACING): rightSpacing=FPB_DEFAULT_RIGHTLINESPACING):
""" """
Adds a wxWindow derived class to the referenced FoldPanel. Adds a `wx.Window` derived instance to the referenced
FoldPanel.
IMPORTANT: Make the to be created window, child of the FoldPanel. See IMPORTANT: Make the window be a child of the FoldPanel. See
example that follows. The flags to be used are: example that follows. The flags to be used are:
- FPB_ALIGN_WIDTH: Which means the wxWindow to be added will be
aligned to fit the width of the FoldPanel when it is resized.
Very handy for sizer items, buttons and text boxes.
- FPB_ALIGN_LEFT: Alligns left instead of fitting the width of
the child window to be added. Use either this one or
FPB_ALIGN_WIDTH.
The wxWindow to be added can be slightly indented from left and right * FPB_ALIGN_WIDTH: Which means the wxWindow to be added
so it is more visibly placed in the FoldPanel. Use Spacing > 0 to give will be aligned to fit the width of the FoldPanel when
the control an y offset from the previous wxWindow added, use leftSpacing it is resized. Very handy for sizer items, buttons and
to give it a slight indent from the left, and rightSpacing also reserves text boxes.
a little space on the right so the wxWindow can be properly placed in
the FoldPanel.
The following example adds a FoldPanel to the FoldPanelBar and adds two * FPB_ALIGN_LEFT: Alligns left instead of fitting the
wxWindow derived controls to the FoldPanel: width of the child window to be added. Use either this
one or FPB_ALIGN_WIDTH.
# CODE The wx.Window to be added can be slightly indented from left
and right so it is more visibly placed in the FoldPanel. Use
Spacing > 0 to give the control an y offset from the previous
wx.Window added, use leftSpacing to give it a slight indent
from the left, and rightSpacing also reserves a little space
on the right so the wxWindow can be properly placed in the
FoldPanel.
The following example adds a FoldPanel to the FoldPanelBar and
adds two wx.Window derived controls to the FoldPanel::
# create the FoldPanelBar # create the FoldPanelBar
>>> m_pnl = FoldPanelBar(self, wx.ID_ANY, wx.DefaultPosition, >>> m_pnl = FoldPanelBar(self, wx.ID_ANY, wx.DefaultPosition,
@@ -1093,7 +1113,6 @@ class FoldPanelBar(wx.Panel):
>>> m_pnl.AddFoldPanelWindow(item, wx.TextCtrl(item, wx.ID_ANY, "Comment"), >>> m_pnl.AddFoldPanelWindow(item, wx.TextCtrl(item, wx.ID_ANY, "Comment"),
FPB_ALIGN_WIDTH, FPB_DEFAULT_SPACING, 20) FPB_ALIGN_WIDTH, FPB_DEFAULT_SPACING, 20)
# ENDCODE
""" """
try: try:
@@ -1117,10 +1136,11 @@ class FoldPanelBar(wx.Panel):
""" """
Adds a separator line to the current FoldPanel. Adds a separator line to the current FoldPanel.
The seperator is a simple line which is drawn and is no real component. The seperator is a simple line which is drawn and is no real
It can be used to separate groups of controls which belong to each other. component. It can be used to separate groups of controls
The colour is adjustable, and it takes the same Spacing, leftSpacing and which belong to each other. The colour is adjustable, and it
rightSpacing as AddFoldPanelWindow(). takes the same Spacing, leftSpacing and rightSpacing as
`AddFoldPanelWindow`.
""" """
try: try:
@@ -1133,7 +1153,7 @@ class FoldPanelBar(wx.Panel):
def OnSizePanel(self, event): def OnSizePanel(self, event):
""" Handles the EVT_SIZE method for the FoldPanelBar. """ """ Handles the EVT_SIZE event for the FoldPanelBar. """
# skip all stuff when we are not initialised yet # skip all stuff when we are not initialised yet
@@ -1211,16 +1231,12 @@ class FoldPanelBar(wx.Panel):
for j in range(i+1, len(self._panels)): for j in range(i+1, len(self._panels)):
pos = pos + self._panels[j].Reposition(pos) pos = pos + self._panels[j].Reposition(pos)
self.Thaw() self.Thaw()
## self.Refresh()
def RedisplayFoldPanelItems(self): def RedisplayFoldPanelItems(self):
""" Resizes the fold panels so they match the width. """ """ Resizes the fold panels so they match the width. """
# resize them all. No need to reposition # resize them all. No need to reposition
for panels in self._panels: for panels in self._panels:
panels.ResizePanel() panels.ResizePanel()
panels.Refresh() panels.Refresh()
@@ -1230,9 +1246,10 @@ class FoldPanelBar(wx.Panel):
""" """
Repositions all the collapsed panels to the bottom. Repositions all the collapsed panels to the bottom.
When it is not possible to align them to the bottom, stick them behind the When it is not possible to align them to the bottom, stick
visible panels. The Rect holds the slack area left between last repositioned them behind the visible panels. The Rect holds the slack area
panel and the bottom panels. This needs to get a refresh. left between last repositioned panel and the bottom
panels. This needs to get a refresh.
""" """
value = wx.Rect(0,0,0,0) value = wx.Rect(0,0,0,0)
@@ -1283,10 +1300,12 @@ class FoldPanelBar(wx.Panel):
def GetPanelsLength(self, collapsed, expanded): def GetPanelsLength(self, collapsed, expanded):
""" """
Returns the length of the panels that are expanded and collapsed. Returns the length of the panels that are expanded and
collapsed.
This is useful to determine quickly what size is used to display, This is useful to determine quickly what size is used to
and what is left at the bottom (right) to align the collapsed panels. display, and what is left at the bottom (right) to align the
collapsed panels.
""" """
value = 0 value = 0
@@ -1307,10 +1326,12 @@ class FoldPanelBar(wx.Panel):
def Collapse(self, foldpanel): def Collapse(self, foldpanel):
""" """
Collapses the given FoldPanel reference, and updates the foldpanel bar. Collapses the given FoldPanel reference, and updates the
foldpanel bar.
In the FPB_COLLAPSE_TO_BOTTOM style, all collapsed captions are put at In the FPB_COLLAPSE_TO_BOTTOM style, all collapsed captions
the bottom of the control. In the normal mode, they stay where they are. are put at the bottom of the control. In the normal mode, they
stay where they are.
""" """
try: try:
@@ -1324,10 +1345,12 @@ class FoldPanelBar(wx.Panel):
def Expand(self, foldpanel): def Expand(self, foldpanel):
""" """
Expands the given FoldPanel reference, and updates the foldpanel bar. Expands the given FoldPanel reference, and updates the
foldpanel bar.
In the FPB_COLLAPSE_TO_BOTTOM style, they will be removed from the bottom In the FPB_COLLAPSE_TO_BOTTOM style, they will be removed from
and the order where the panel originally was placed is restored. the bottom and the order where the panel originally was placed
is restored.
""" """
foldpanel.Expand() foldpanel.Expand()
@@ -1336,22 +1359,24 @@ class FoldPanelBar(wx.Panel):
def ApplyCaptionStyle(self, foldpanel, cbstyle): def ApplyCaptionStyle(self, foldpanel, cbstyle):
""" """
Sets the style of the caption bar (called CaptionBar) of the FoldPanel. Sets the style of the caption bar (`CaptionBar`) of the
FoldPanel.
The changes are applied immediately. All styles not set in the CaptionBarStyle The changes are applied immediately. All styles not set in the
class are not applied. Use the CaptionBar reference to indicate what captionbar CaptionBarStyle class are not applied. Use the CaptionBar
you want to apply the style to. To apply one style to all CaptionBar items, use reference to indicate what captionbar you want to apply the
ApplyCaptionStyleAll() style to. To apply one style to all CaptionBar items, use
`ApplyCaptionStyleAll`
""" """
foldpanel.ApplyCaptionStyle(cbstyle) foldpanel.ApplyCaptionStyle(cbstyle)
def ApplyCaptionStyleAll(self, cbstyle): def ApplyCaptionStyleAll(self, cbstyle):
""" Sets the style of all the caption bars of the FoldPanel. """
Sets the style of all the caption bars of the FoldPanel.
The changes are applied immediately. """
The changes are applied immediately.
"""
for panels in self._panels: for panels in self._panels:
self.ApplyCaptionStyle(panels, cbstyle) self.ApplyCaptionStyle(panels, cbstyle)
@@ -1360,20 +1385,18 @@ class FoldPanelBar(wx.Panel):
""" """
Returns the currently used caption style for the FoldPanel. Returns the currently used caption style for the FoldPanel.
It is returned as a CaptionBarStyle class. After modifying it, it can be It is returned as a CaptionBarStyle class. After modifying it,
set again. it can be set again.
""" """
return foldpanel.GetCaptionStyle() return foldpanel.GetCaptionStyle()
def IsVertical(self): def IsVertical(self):
""" """
Returns wether the CaptionBar Has Default Orientation Or Not. Returns whether the CaptionBar has default orientation or not.
Default is vertical. Default is vertical.
""" """
return self._isVertical return self._isVertical
@@ -1384,7 +1407,6 @@ class FoldPanelBar(wx.Panel):
See the example at the bottom of the module, especially the events See the example at the bottom of the module, especially the events
for the "Collapse Me" and "Expand Me" buttons. for the "Collapse Me" and "Expand Me" buttons.
""" """
try: try:
ind = self._panels[item] ind = self._panels[item]
return self._panels[item] return self._panels[item]
@@ -1406,13 +1428,14 @@ class FoldPanelBar(wx.Panel):
# --------------------------------------------------------------------------------- # # --------------------------------------------------------------------------------- #
# class FoldPanelItem # class FoldPanelItem
# This class is a child sibling of the FoldPanelBar class. It will contain a
# CaptionBar class for receiving of events, and a the rest of the area can be
# populated by a wxPanel derived class.
# --------------------------------------------------------------------------------- # # --------------------------------------------------------------------------------- #
class FoldPanelItem(wx.Panel): class FoldPanelItem(wx.Panel):
"""
This class is a child sibling of the `FoldPanelBar` class. It will
contain a `CaptionBar` class for receiving of events, and a the
rest of the area can be populated by a `wx.Panel` derived class.
"""
# Define Empty CaptionBar Style # Define Empty CaptionBar Style
EmptyCaptionBarStyle = CaptionBarStyle() EmptyCaptionBarStyle = CaptionBarStyle()
@@ -1470,10 +1493,11 @@ class FoldPanelItem(wx.Panel):
""" """
Adds a window item to the list of items on this panel. Adds a window item to the list of items on this panel.
The flags are FPB_ALIGN_LEFT for a non sizing window element, and The flags are FPB_ALIGN_LEFT for a non sizing window element,
FPB_ALIGN_WIDTH for a width aligned item. The Spacing parameter reserves and FPB_ALIGN_WIDTH for a width aligned item. The Spacing
a number of pixels before the window element, and leftSpacing is an indent. parameter reserves a number of pixels before the window
rightSpacing is only relevant when the style FPB_ALIGN_WIDTH is chosen. element, and leftSpacing is an indent. rightSpacing is only
relevant when the style FPB_ALIGN_WIDTH is chosen.
""" """
wi = FoldWindowItem(self, window, Type="WINDOW", flags=flags, Spacing=Spacing, wi = FoldWindowItem(self, window, Type="WINDOW", flags=flags, Spacing=Spacing,
@@ -1515,9 +1539,10 @@ class FoldPanelItem(wx.Panel):
def Reposition(self, pos): def Reposition(self, pos):
""" Repositions this FoldPanelBar and reports the length occupied for the """
next FoldPanelBar in the list. """ Repositions this FoldPanelBar and reports the length occupied
for the next FoldPanelBar in the list.
"""
# NOTE: Call Resize before Reposition when an item is added, because the new # NOTE: Call Resize before Reposition when an item is added, because the new
# size needed will be calculated by Resize. Of course the relative position # size needed will be calculated by Resize. Of course the relative position
# of the controls have to be correct in respect to the caption bar # of the controls have to be correct in respect to the caption bar
@@ -1532,7 +1557,6 @@ class FoldPanelItem(wx.Panel):
self._itemPos = pos self._itemPos = pos
self.Thaw() self.Thaw()
## self.Refresh()
return self.GetPanelLength() return self.GetPanelLength()
@@ -1596,7 +1620,6 @@ class FoldPanelItem(wx.Panel):
[size.GetHeight()])[0], vertical) [size.GetHeight()])[0], vertical)
self.Thaw() self.Thaw()
## self.Refresh()
def OnPaint(self, event): def OnPaint(self, event):
@@ -1642,9 +1665,10 @@ class FoldPanelItem(wx.Panel):
def IsExpanded(self): def IsExpanded(self):
""" Returns expanded or collapsed status. """
Returns expanded or collapsed status. If the panel is
If the panel is expanded, True is returned. """ expanded, True is returned.
"""
return not self._captionBar.IsCollapsed() return not self._captionBar.IsCollapsed()
@@ -1685,7 +1709,10 @@ class FoldPanelItem(wx.Panel):
def GetCaptionLength(self): def GetCaptionLength(self):
""" Returns height of caption only. This is for folding calculation purposes. """ """
Returns height of caption only. This is for folding
calculation purposes.
"""
size = self._captionBar.GetSize() size = self._captionBar.GetSize()
return (self.IsVertical() and [size.GetHeight()] or [size.GetWidth()])[0] return (self.IsVertical() and [size.GetHeight()] or [size.GetWidth()])[0]
@@ -1699,7 +1726,8 @@ class FoldPanelItem(wx.Panel):
def GetCaptionStyle(self): def GetCaptionStyle(self):
""" """
Returns the current style of the captionbar in a CaptionBarStyle class. Returns the current style of the captionbar in a
CaptionBarStyle class.
This can be used to change and set back the changes. This can be used to change and set back the changes.
""" """
@@ -1709,25 +1737,27 @@ class FoldPanelItem(wx.Panel):
# ----------------------------------------------------------------------------------- # # ----------------------------------------------------------------------------------- #
# class FoldWindowItem # class FoldWindowItem
# This class is a child sibling of the FoldPanelItem class. It will contain
# wxWindow that can be either a separator (a colored line simulated by a wxWindow)
# or a wxPython controls (such as a wxButton, a wxListCtrl etc...).
# ----------------------------------------------------------------------------------- # # ----------------------------------------------------------------------------------- #
class FoldWindowItem: class FoldWindowItem:
"""
This class is a child sibling of the `FoldPanelItem` class. It
will contain wx.Window that can be either a separator (a colored
line simulated by a wx.Window) or a wxPython controls (such as a
wx.Button, a wx.ListCtrl etc...).
"""
def __init__(self, parent, window=None, **kw): def __init__(self, parent, window=None, **kw):
""" """
Default Class Constructor Default Class Constructor
Initialize with: Initialize with::
Type = "WINDOW", flags = FPB_ALIGN_WIDTH, Type = "WINDOW", flags = FPB_ALIGN_WIDTH,
Spacing = FPB_DEFAULT_SPACING, Spacing = FPB_DEFAULT_SPACING,
leftSpacing = FPB_DEFAULT_LEFTSPACING, leftSpacing = FPB_DEFAULT_LEFTSPACING,
rightSpacing = FPB_DEFAULT_RIGHTSPACING rightSpacing = FPB_DEFAULT_RIGHTSPACING
or: or::
Type = "SEPARATOR" Type = "SEPARATOR"
y, lineColor = wx.BLACK, y, lineColor = wx.BLACK,
@@ -1826,8 +1856,10 @@ class FoldWindowItem:
def GetWindowLength(self, vertical=True): def GetWindowLength(self, vertical=True):
""" Returns space needed by the window if type is FoldWindowItem "WINDOW" """
and returns the total size plus the extra spacing.""" Returns space needed by the window if type is FoldWindowItem
"WINDOW" and returns the total size plus the extra spacing.
"""
value = 0 value = 0
if self._type == "WINDOW": if self._type == "WINDOW":