File: LayoutConstraints.py

package info (click to toggle)
wxpython3.0 3.0.2.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 482,760 kB
  • ctags: 518,293
  • sloc: cpp: 2,127,226; python: 294,045; makefile: 51,942; ansic: 19,033; sh: 3,013; xml: 1,629; perl: 17
file content (148 lines) | stat: -rw-r--r-- 4,882 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148

import  wx

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

class TestLayoutConstraints(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, -1)
        self.SetAutoLayout(True)
        self.Bind(wx.EVT_BUTTON, self.OnButton, id=100)

        self.SetBackgroundColour(wx.NamedColour("MEDIUM ORCHID"))

        self.panelA = wx.Window(self, -1, style=wx.SIMPLE_BORDER)
        self.panelA.SetBackgroundColour(wx.BLUE)

        txt = wx.StaticText(
                    self.panelA, -1,
                    "Resize the window and see\n"
                    "what happens...  Notice that\n"
                    "there is no OnSize handler.",
                    (5,5), (-1, 50)
                    )

        txt.SetBackgroundColour(wx.BLUE)
        txt.SetForegroundColour(wx.WHITE)

        lc = wx.LayoutConstraints()
        lc.top.SameAs(self, wx.Top, 10)
        lc.left.SameAs(self, wx.Left, 10)
        lc.bottom.SameAs(self, wx.Bottom, 10)
        lc.right.PercentOf(self, wx.Right, 50)
        self.panelA.SetConstraints(lc)

        self.panelB = wx.Window(self, -1, style=wx.SIMPLE_BORDER)
        self.panelB.SetBackgroundColour(wx.RED)
        lc = wx.LayoutConstraints()
        lc.top.SameAs(self, wx.Top, 10)
        lc.right.SameAs(self, wx.Right, 10)
        lc.bottom.PercentOf(self, wx.Bottom, 30)
        lc.left.RightOf(self.panelA, 10)
        self.panelB.SetConstraints(lc)

        self.panelC = wx.Window(self, -1, style=wx.SIMPLE_BORDER)
        self.panelC.SetBackgroundColour(wx.WHITE)
        lc = wx.LayoutConstraints()
        lc.top.Below(self.panelB, 10)
        lc.right.SameAs(self, wx.Right, 10)
        lc.bottom.SameAs(self, wx.Bottom, 10)
        lc.left.RightOf(self.panelA, 10)
        self.panelC.SetConstraints(lc)

        b = wx.Button(self.panelA, 100, ' Panel A ')
        lc = wx.LayoutConstraints()
        lc.centreX.SameAs   (self.panelA, wx.CentreX)
        lc.centreY.SameAs   (self.panelA, wx.CentreY)
        lc.height.AsIs      ()
        lc.width.PercentOf  (self.panelA, wx.Width, 50)
        b.SetConstraints(lc)

        b = wx.Button(self.panelB, 100, ' Panel B ')
        lc = wx.LayoutConstraints()
        lc.top.SameAs       (self.panelB, wx.Top, 2)
        lc.right.SameAs     (self.panelB, wx.Right, 4)
        lc.height.AsIs      ()
        lc.width.AsIs       ()
        b.SetConstraints(lc)

        self.panelD = wx.Window(self.panelC, -1, style=wx.SIMPLE_BORDER)
        self.panelD.SetBackgroundColour(wx.GREEN)
        wx.StaticText(
            self.panelD, -1, "Panel D", (4, 4)
            ).SetBackgroundColour(wx.GREEN)

        b = wx.Button(self.panelC, 100, ' Panel C ')
        lc = wx.LayoutConstraints()
        lc.top.Below        (self.panelD)
        lc.left.RightOf     (self.panelD)
        lc.height.AsIs      ()
        lc.width.AsIs       ()
        b.SetConstraints(lc)

        lc = wx.LayoutConstraints()
        lc.bottom.PercentOf (self.panelC, wx.Height, 50)
        lc.right.PercentOf  (self.panelC, wx.Width, 50)
        lc.height.SameAs    (b, wx.Height)
        lc.width.SameAs     (b, wx.Width)
        self.panelD.SetConstraints(lc)


    def OnButton(self, event):
        wx.Bell()


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

def runTest(frame, nb, log):
    win = TestLayoutConstraints(nb)
    return win

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



overview = """\
<html><body>
Objects of this class can be associated with a window to define its
layout constraints, with respect to siblings or its parent.

<p>The class consists of the following eight constraints of class
wxIndividualLayoutConstraint, some or all of which should be accessed
directly to set the appropriate constraints.

<p><ul>
<li>left: represents the left hand edge of the window

<li>right: represents the right hand edge of the window

<li>top: represents the top edge of the window

<li>bottom: represents the bottom edge of the window

<li>width: represents the width of the window

<li>height: represents the height of the window

<li>centreX: represents the horizontal centre point of the window

<li>centreY: represents the vertical centre point of the window
</ul>
<p>Most constraints are initially set to have the relationship
wxUnconstrained, which means that their values should be calculated by
looking at known constraints. The exceptions are width and height,
which are set to wxAsIs to ensure that if the user does not specify a
constraint, the existing width and height will be used, to be
compatible with panel items which often have take a default size. If
the constraint is wxAsIs, the dimension will not be changed.

"""




if __name__ == '__main__':
    import sys,os
    import run
    run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])