]> git.saurik.com Git - wxWidgets.git/blame - utils/wxPython/lib/sizers/border.py
fixed bug that caused wxHtmlWindow to segfault on html tables with cell(s) with rowsp...
[wxWidgets.git] / utils / wxPython / lib / sizers / border.py
CommitLineData
bb0054cd
RD
1#----------------------------------------------------------------------
2# Name: wxPython.lib.sizers.border
3# Purpose: A Sizer that wraps an empty border around its contents
4#
5# Author: Robin Dunn
6#
7# Created: 9-June-1999
8# RCS-ID: $Id$
9# Copyright: (c) 1998 by Total Control Software
10# Licence: wxWindows license
11#----------------------------------------------------------------------
12
13from sizer import wxSizer
14
15wxNORTH = 1
16wxSOUTH = 2
17wxEAST = 4
18wxWEST = 8
19wxALL = wxNORTH | wxSOUTH | wxEAST | wxWEST
20
21#----------------------------------------------------------------------
22
23class wxBorderSizer(wxSizer):
24 """
25 wxBorderSizer
26
27 This sizer provides an empty buffer on one or more sides of it's
28 contents. It can only hold a single widget, but that can be a
29 sizer containing other items if you wish.
30
31 The sizer is constructed with a parameter specifying which sides
32 should have the border. You can use a logical OR of the following
33 values to specify the sides:
34
35 wxNORTH -- the top side
36 wxSOUTH -- the bottom side
37 wxEAST -- the right side
38 wxWEST -- the left side
39 wxALL -- all sides
40
41 The width in pixels of the border is specified when the child
42 widget is Added to the sizer.
43
44 """
45 def __init__(self, sides = wxALL):
46 wxSizer.__init__(self)
47 self.sides = sides
48
49
50 def Add(self, widget, borderSize):
51 if self.children:
52 raise ValueError("wxBorderSizer can only contain one child.")
53
54 wxSizer.Add(self, widget, borderSize)
55
56
57 def CalcMin(self):
58 isSizer, widget, width, height, borderSize = self.children[0]
59
60 if isSizer:
61 width, height = widget.CalcMin()
62
63 if self.sides & wxEAST:
64 width = width + borderSize
65
66 if self.sides & wxWEST:
67 width = width + borderSize
68
69 if self.sides & wxNORTH:
70 height = height + borderSize
71
72 if self.sides & wxSOUTH:
73 height = height + borderSize
74
75 return width, height
76
77
78 def RecalcSizes(self):
79 isSizer, widget, width, height, borderSize = self.children[0]
80 width = self.size.width
81 height = self.size.height
82 px = self.origin.x
83 py = self.origin.y
84
85 if self.sides & wxWEST:
86 width = width - borderSize
87 px = px + borderSize
88 if self.sides & wxEAST:
89 width = width - borderSize
90
91 if self.sides & wxNORTH:
92 height = height - borderSize
93 py = py + borderSize
94 if self.sides & wxSOUTH:
95 height = height - borderSize
96
97 widget.SetDimensions(px, py, width, height)
98
99
100#----------------------------------------------------------------------
101#
102# TODO... Make an abstract class wxBorder whose decendants can be added to
103# a wxBorderSizer to provide drawing for the buffer area. Ideas are
104# to provide a color border, beveled borders, rounded borders, etc.
105
106
107
108
109