]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/py/wxd/Sizers.py
   1 """Decorator classes for documentation and shell scripting. 
   3 Sizer is the abstract base class used for laying out subwindows in a 
   4 window.  You cannot use Sizer directly; instead, you will have to use 
   5 one of the sizer classes derived from it.  Currently there are 
   6 BoxSizer, StaticBoxSizer, NotebookSizer, GridSizer, and FlexGridSizer. 
   8 The layout algorithm used by sizers in wxPython is closely related to 
   9 layout in other GUI toolkits, such as Java's AWT, the GTK toolkit or 
  10 the Qt toolkit.  It is based upon the idea of the individual 
  11 subwindows reporting their minimal required size and their ability to 
  12 get stretched if the size of the parent window has changed.  This will 
  13 most often mean, that the programmer does not set the original size of 
  14 a dialog in the beginning, rather the dialog will assigned a sizer and 
  15 this sizer will be queried about the recommended size.  The sizer in 
  16 turn will query its children, which can be normal windows, empty space 
  17 or other sizers, so that a hierarchy of sizers can be constructed. 
  18 Note that wxSizer does not derive from wxWindow and thus do not 
  19 interfere with tab ordering and requires very little resources 
  20 compared to a real window on screen. 
  22 What makes sizers so well fitted for use in wxPython is the fact that 
  23 every control reports its own minimal size and the algorithm can 
  24 handle differences in font sizes or different window (dialog item) 
  25 sizes on different platforms without problems.  If e.g. the standard 
  26 font as well as the overall design of Motif widgets requires more 
  27 space than on Windows, the initial dialog size will automatically be 
  28 bigger on Motif than on Windows. 
  30 If you wish to create a sizer class in wxPython you should derive the 
  31 class from PySizer in order to get Python-aware capabilities for the 
  32 various virtual methods. 
  35 __author__ 
= "Patrick K. O'Brien <pobrien@orbtech.com>" 
  37 __revision__ 
= "$Revision$"[11:-2] 
  40 # These are not the real wxPython classes. These are Python versions 
  41 # for documentation purposes. They are also used to apply docstrings 
  42 # to the real wxPython classes, which are SWIG-generated wrappers for 
  46 from Base 
import Object
 
  47 import Parameters 
as wx
 
  57     """Sizer is the abstract base class used for laying out subwindows 
  58     in a window. You shouldn't use Sizer directly; instead, you should 
  59     use one of the sizer classes derived from it. 
  61     If you wish to create a sizer class in wxPython you should derive 
  62     the class from PySizer in order to get Python-aware capabilities 
  63     for the various virtual methods. 
  65     Placing a child sizer in a sizer allows you to create hierarchies 
  66     of sizers (typically a vertical box as the top sizer and several 
  67     horizontal boxes on the level beneath). 
  69     When you place a window in a sizer the window's initial size 
  70     (either set explicitly by the user or calculated internally when 
  71     using wxDefaultSize) is interpreted as the minimal and in many 
  72     cases also the initial size.  This is particularly useful in 
  73     connection with SetSizeHints. 
  75     Adding spacers to sizers gives more flexibility in the design of 
  76     dialogs.  Imagine for example a horizontal box with two buttons at 
  77     the bottom of a dialog: you might want to insert a space between 
  78     the two buttons and make that space stretchable using the 
  79     proportion flag and the result will be that the left button will 
  80     be aligned with the left side of the dialog and the right button 
  81     with the right side - the space in between will shrink and grow 
  84     Several methods (Add, Insert, Prepend) take the following 
  87     proportion - Used only by BoxSizer to indicate if a child of a 
  88     sizer can change its size in the main orientation of the BoxSizer, 
  89     where 0 stands for not changeable and a value of more than zero is 
  90     interpreted relative to the value of other children of the same 
  91     BoxSizer.  For example, you might have a horizontal BoxSizer with 
  92     three children, two of which are supposed to change their size 
  93     with the sizer.  Then the two stretchable windows would each get a 
  94     value of 1 to make them grow and shrink equally with the sizer's 
  97     flag - This parameter can be used to set a number of flags which 
  98     can be combined using the binary OR operator |.  Two main 
  99     behaviours are defined using these flags.  One is the border 
 100     around a window: the border parameter determines the border width 
 101     whereas the flags given here determine where the border may be 
 102     (wx.TOP, wx.BOTTOM, wx.LEFT, wx.RIGHT or wx.ALL).  The other flags 
 103     determine the child window's behaviour if the size of the sizer 
 104     changes.  However this is not - in contrast to the proportion flag 
 105     - in the main orientation, but in the respectively other 
 106     orientation.  So if you created a BoxSizer with the wx.VERTICAL 
 107     option, these flags will be relevant if the sizer changes its 
 108     horizontal size.  A child may get resized to completely fill out 
 109     the new size (using either wx.GROW or wx.EXPAND), it may get 
 110     proportionally resized (wx.SHAPED), it may get centered 
 111     (wx.ALIGN_CENTER or wx.ALIGN_CENTRE) or it may get aligned to 
 112     either side (wx.ALIGN_LEFT and wx.ALIGN_TOP are set to 0 and thus 
 113     represent the default, wx.ALIGN_RIGHT and wx.ALIGN_BOTTOM have 
 114     their obvious meaning).  With proportional resize, a child may 
 115     also be centered in the main orientation using 
 116     wx.ALIGN_CENTER_VERTICAL (same as wx.ALIGN_CENTRE_VERTICAL) and 
 117     wx.ALIGN_CENTER_HORIZONTAL (same as wx.ALIGN_CENTRE_HORIZONTAL) 
 118     flags.  Finally, you can also specify wx.ADJUST_MINSIZE flag to 
 119     make the minimal size of the control dynamically adjust to the 
 120     value returned by its GetAdjustedBestSize() method - this allows, 
 121     for example, for correct relayouting of a static text control even 
 122     if its text is changed during run-time. 
 124     border - Determines the border width, if the flag parameter is set 
 125     to any border.  A border is not a visible element, but rather a 
 126     margin of empty space surrounding the item. 
 128     userData - Allows an extra object to be attached to the sizer 
 129     item, for use in derived classes when sizing information is more 
 130     complex than the option and flag parameters will allow.""" 
 133         """Must be defined by subclasses.""" 
 136     def Add(self
, item
, proportion
=0, flag
=0, border
=0, 
 138         """Add item to sizer. 
 140         item - window, sizer, or spacer.  Spacer is specified with a 
 141         (width, height) tuple or wx.Size representing the spacer size. 
 143         Call Layout() to update the layout on-screen after adding.""" 
 146     def Clear(self
, delete_windows
=False): 
 147         """Remove all items from this sizer. 
 149         If delete_windows is True, destroy any window items.""" 
 152     def DeleteWindows(self
): 
 153         """Destroy windows associated with this sizer.""" 
 157         """Destroy the sizer.""" 
 160     def Fit(self
, window
): 
 161         """Resize window to match sizer's minimal size; return size. 
 163         This is commonly done in the constructor of the window itself.""" 
 166     def FitInside(self
, window
): 
 167         """Resize window virtual size to match sizer's minimal size. 
 169         This will not alter the on screen size of the window, but may 
 170         cause the addition/removal/alteration of scrollbars required 
 171         to view the virtual area in windows which manage it.""" 
 174     def GetChildren(self
): 
 175         """Return list of SizerItem instances.""" 
 178     def GetMinSize(self
): 
 179         """Return the minimal size of the sizer. 
 181         This is either the combined minimal size of all the children 
 182         and their borders or the minimal size set by SetMinSize, 
 183         whichever is larger.""" 
 186     def GetMinSizeTuple(self
): 
 187         """Return the minimal size of the sizer as a tuple. 
 189         This is either the combined minimal size of all the children 
 190         and their borders or the minimal size set by SetMinSize, 
 191         whichever is larger.""" 
 194     def GetPosition(self
): 
 195         """Return the current position of the sizer.""" 
 198     def GetPositionTuple(self
): 
 199         """Return the current position of the sizer as a tuple.""" 
 203         """Return the current size of the sizer.""" 
 206     def GetSizeTuple(self
): 
 207         """Return the current size of the sizer as a tuple.""" 
 210     def Hide(self
, item
): 
 211         """Hide item (sizer or window).  To make a sizer item 
 212         disappear on-screen, use Hide() followed by Layout().""" 
 215     def Insert(self
, before
, item
, proportion
=0, flag
=0, border
=0, 
 217         """Same as Add, but inserts item into list of items (windows, 
 218         subsizers or spacers) owned by this sizer. 
 220         Call Layout() to update the layout on-screen after inserting.""" 
 223     def IsShown(self
, item
): 
 224         """Return True if item (sizer or window) is shown.""" 
 228         """Force layout of children anew. 
 230         Use after adding or removing a child (window, other sizer, or 
 231         spacer) from the sizer while keeping the current dimension.""" 
 234     def Prepend(self
, item
, proportion
=0, flag
=0, border
=0, 
 236         """Same as Add, but prepends item to beginning of list of 
 237         items (windows, subsizers or spacers) owned by this sizer. 
 239         Call Layout() to update the layout on-screen after prepending.""" 
 242     def Remove(self
, item
): 
 243         """Remove item from the sizer. 
 245         item - sizer, window, or index of item in the sizer, typically 
 246         0 for the first item. 
 248         Does not cause any layout or resizing to take place, and does 
 249         not delete the child itself.  Call Layout() to update the 
 250         layout on-screen after removing child. 
 252         Return True if child found and removed, False otherwise.""" 
 255     def SetDimension(self
, x
, y
, width
, height
): 
 256         """Force sizer to take the given dimension and thus force 
 257         items owned by sizer to resize themselves according to the 
 258         rules defined by the parameter in the Add and Prepend methods.""" 
 261     def SetItemMinSize(self
, item
, width
, height
): 
 262         """Set minimal size of item. 
 264         item - sizer, window, or index of item in the sizer, typically 
 265         0 for the first item. 
 267         The item will be found recursively in the sizer's descendants. 
 268         Enables application to set size of item after initialization.""" 
 271     def SetMinSize(self
, size
): 
 274         Normally, sizer will calculate minimal size based on how much 
 275         space its children need.  After calling this method, 
 276         GetMinSize will return the minimal size as requested by its 
 277         children or the minimal size set here, whichever is larger.""" 
 280     def SetSizeHints(self
, window
): 
 281         """Set (and Fit) minimal size of window to match sizer's 
 282         minimal size.  Commonly called in the window's init.""" 
 285     def SetVirtualSizeHints(self
, window
): 
 286         """Set minimal size of window virtual area to match sizer's 
 287         minimal size.  For windows with managed scrollbars this will 
 288         set them appropriately.""" 
 291     def Show(self
, item
, show
=True): 
 292         """Show or hide item (sizer or window).  To make item 
 293         disappear or reappear on-screen, use Show() followed by 
 297     def ShowItems(self
, show
): 
 298         """Recursively call Show() on all sizer items.""" 
 302 class PySizer(Sizer
): 
 303     """If you wish to create a custom sizer class you should derive 
 304     the class from PySizer in order to get Python-aware capabilities 
 305     for the various virtual methods.""" 
 308         """Create a PySizer instance.  Override in subclass.""" 
 312 class BoxSizer(Sizer
): 
 313     """A box sizer is used to lay out a rather simple geometry, 
 314     typically a row or column or several hierarchies of either.""" 
 316     def __init__(self
, orient
=wx
.HORIZONTAL
): 
 317         """Create BoxSizer instance. 
 319         orient is either wx.VERTICAL or wx.HORIZONTAL""" 
 323         """Calculate minimum size.  Do not call directly.""" 
 326     def GetOrientation(self
): 
 327         """Return orientation: wx.VERTICAL or wx.HORIZONTAL.""" 
 330     def RecalcSizes(self
): 
 331         """Recalculate sizes, then set the size of its children 
 332         (calling SetSize if child is a window).  Do not call directly.""" 
 335     def SetOrientation(self
, orient
): 
 336         """Set orientation to either wx.VERTICAL or wx.HORIZONTAL.""" 
 340 class StaticBoxSizer(BoxSizer
): 
 341     """Like BoxSizer, but adds a static box around the sizer.  Note 
 342     that the static box has to be created separately.""" 
 344     def __init__(self
, box
, orient
=wx
.HORIZONTAL
): 
 345         """Create StaticBoxSizer instance. 
 347         box - instance of wx.StaticBox 
 349         orient - either wx.VERTICAL or wx.HORIZONTAL""" 
 353         """Calculate minimum size.  Do not call directly.""" 
 356     def GetStaticBox(self
): 
 357         """Return the static box associated with the sizer.""" 
 360     def RecalcSizes(self
): 
 361         """Recalculate sizes, then set the size of its children 
 362         (calling SetSize if child is a window).  Do not call directly.""" 
 366 class GridSizer(Sizer
): 
 367     """A grid sizer lays out its children in a two-dimensional table 
 368     where all cells have the same size: the width of each cell is the 
 369     width of the widest child, the height of each cell is the height 
 370     of the tallest child.  See also the FlexGridSizer.""" 
 372     def __init__(self
, rows
=1, cols
=0, vgap
=0, hgap
=0): 
 373         """Create a GridSizer instance. 
 375         rows and cols - the number of rows and columns in the grid; if 
 376         either is zero, it will be calculated as the number of 
 377         children in the sizer, allowing the sizer grow dynamically. 
 379         vgap and hgap - extra space between all cells, in pixels.""" 
 383         """Calculate minimum size.  Do not call directly.""" 
 387         """Return the number of columns in the grid.""" 
 391         """Return the horizontal gap (in pixels) between cells.""" 
 395         """Return the number of rows in the grid.""" 
 399         """Return the vertical gap (in pixels) between cells.""" 
 402     def RecalcSizes(self
): 
 403         """Recalculate sizes, then set the size of its children 
 404         (calling SetSize if child is a window).  Do not call directly.""" 
 407     def SetCols(self
, cols
): 
 408         """Set the number of columns in the grid.""" 
 411     def SetHGap(self
, gap
): 
 412         """Set the horizontal gap (in pixels) between cells.""" 
 415     def SetRows(self
, rows
): 
 416         """Sets the number of rows in the grid.""" 
 419     def SetVGap(self
, gap
): 
 420         """Set the vertical gap (in pixels) between cells.""" 
 424 class FlexGridSizer(GridSizer
): 
 425     """A flex grid sizer lays out its children in a two-dimensional 
 426     table where all cells in one row have the same height and all 
 427     cells in one column have the same width, but all cells are not 
 428     necessarily the same height and width, as in the GridSizer.""" 
 430     def __init__(self
, rows
=1, cols
=0, vgap
=0, hgap
=0): 
 431         """Create a GridSizer instance. 
 433         rows and cols - the number of rows and columns in the grid; if 
 434         either is zero, it will be calculated as the number of 
 435         children in the sizer, allowing the sizer grow dynamically. 
 437         vgap and hgap - extra space between all cells, in pixels.""" 
 440     def AddGrowableCol(self
, idx
): 
 441         """Specify that column idx (starting from zero) should expand 
 442         if there is extra space available to the sizer.""" 
 445     def AddGrowableRow(self
, idx
): 
 446         """Specify that row idx (starting from zero) should expand if 
 447         there is extra space available to the sizer.""" 
 451         """Calculate minimum size.  Do not call directly.""" 
 454     def RecalcSizes(self
): 
 455         """Recalculate sizes, then set the size of its children 
 456         (calling SetSize if child is a window).  Do not call directly.""" 
 459     def RemoveGrowableCol(self
, idx
): 
 460         """Specify that column idx is no longer growable.""" 
 463     def RemoveGrowableRow(self
, idx
): 
 464         """Specify that row idx is no longer growable.""" 
 468 class NotebookSizer(Sizer
): 
 469     """NotebookSizer works with a notebook to determine the size of 
 470     the biggest page and report an adjusted minimal size to a more 
 471     toplevel sizer.  Do not add children to a NotebookSizer.""" 
 473     def __init__(self
, nb
): 
 474         """Create a NotebookSizer instance for notebook.""" 
 478         """Calculate minimum size.  Do not call directly.""" 
 481     def GetNotebook(self
): 
 482         """Return the notebook associated with the sizer.""" 
 485     def RecalcSizes(self
): 
 486         """Recalculate size.  Do not call directly.""" 
 490 class SizerItem(Object
): 
 491     """SizerItem class.  Wrapper for items managed by a sizer.""" 
 493     def __init__(self
, this
): 
 494         """Create a SizerItem instance.  You don't normally create one 
 499         """Calculate minimum size.  Do not call directly.""" 
 502     def DeleteWindows(self
): 
 503         """Recursively destroy windows associated with this SizerItem.""" 
 507         """Return border width.""" 
 511         """Return flag value.""" 
 515         """Return option value.""" 
 518     def GetPosition(self
): 
 519         """Return wx.Point instance representing position relative to 
 524         """Return a floating point aspect ratio (width/height).  If 
 525         wx.SHAPED flag is used item will maintain ratio when resized.""" 
 529         """Return wx.Size instance with size.""" 
 533         """If IsSizer() return the sizer; otherwise return None.""" 
 536     def GetUserData(self
): 
 537         """Return a wx.PyUserData object.""" 
 541         """If IsWindow() return the window; otherwise return None.""" 
 545         """Return True if item is shown.""" 
 549         """Return True if SizerItem represents a sizer.""" 
 553         """Return True if SizerItem represents a spacer.""" 
 557         """Return True if SizerItem represents a window.""" 
 560     def SetBorder(self
, border
): 
 561         """Set border width for item.""" 
 564     def SetDimension(self
, pos
, size
): 
 565         """Set position and size for item.""" 
 568     def SetFlag(self
, flag
): 
 569         """Set flag for item.""" 
 572     def SetInitSize(self
, x
, y
): 
 573         """Set initial size of item.""" 
 576     def SetOption(self
, option
): 
 577         """Set option for item.""" 
 580     def SetRatio(self
, ratio
): 
 581         """Set a floating point aspect ratio (width/height).  If 
 582         wx.SHAPED flag is used item will maintain ratio when resized.""" 
 585     def SetRatioSize(self
, size
): 
 586         """Set a floating point aspect ratio (width/height).  If 
 587         wx.SHAPED flag is used item will maintain ratio when resized.""" 
 590     def SetRatioWH(self
, width
, height
): 
 591         """Set a floating point aspect ratio (width/height).  If 
 592         wx.SHAPED flag is used item will maintain ratio when resized.""" 
 595     def SetSizer(self
, sizer
): 
 596         """Set sizer associated with SizerItem.""" 
 599     def SetWindow(self
, window
): 
 600         """Set window associated with SizerItem.""" 
 603     def Show(self
, show
): 
 604         """Is show is True, show item, otherwise hide item."""