]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/LayoutAnchors.py
fix menubar sizing (at least under windows)
[wxWidgets.git] / wxPython / demo / LayoutAnchors.py
1
2 from wxPython.wx import *
3 from wxPython.lib.anchors import LayoutAnchors
4
5 #----------------------------------------------------------------------
6
7
8 [wxID_ANCHORSDEMOFRAMEANCHOREDPANEL, wxID_ANCHORSDEMOFRAMEHELPSTATICTEXT,
9 wxID_ANCHORSDEMOFRAMEMAINPANEL, wxID_ANCHORSDEMOFRAMEBACKGROUNDPANEL,
10 wxID_ANCHORSDEMOFRAMERIGHTCHECKBOX, wxID_ANCHORSDEMOFRAMEOKBUTTON,
11 wxID_ANCHORSDEMOFRAMETOPCHECKBOX, wxID_ANCHORSDEMOFRAMEBOTTOMCHECKBOX,
12 wxID_ANCHORSDEMOFRAME, wxID_ANCHORSDEMOFRAMELEFTCHECKBOX,
13 ] = map(lambda _init_ctrls: wxNewId(), range(10))
14
15 class AnchorsDemoFrame(wxFrame):
16 def _init_utils(self):
17 pass
18
19 def _init_ctrls(self, prnt):
20 wxFrame.__init__(self, size = wxSize(328, 187), id = wxID_ANCHORSDEMOFRAME, title = 'LayoutAnchors Demonstration', parent = prnt, name = 'AnchorsDemoFrame', style = wxDEFAULT_FRAME_STYLE | wxCLIP_CHILDREN, pos = wxPoint(261, 123))
21 self._init_utils()
22
23 self.mainPanel = wxPanel(size = wxSize(320, 160), parent = self, id = wxID_ANCHORSDEMOFRAMEMAINPANEL, name = 'panel1', style = wxTAB_TRAVERSAL | wxCLIP_CHILDREN, pos = wxPoint(0, 0))
24 self.mainPanel.SetAutoLayout(true)
25
26 self.okButton = wxButton(label = 'OK', id = wxID_ANCHORSDEMOFRAMEOKBUTTON, parent = self.mainPanel, name = 'okButton', size = wxSize(72, 24), style = 0, pos = wxPoint(240, 128))
27 self.okButton.SetConstraints(LayoutAnchors(self.okButton, false, false, true, true))
28 EVT_BUTTON(self.okButton, wxID_ANCHORSDEMOFRAMEOKBUTTON, self.OnOkButtonButton)
29
30 self.backgroundPanel = wxPanel(size = wxSize(304, 80), parent = self.mainPanel, id = wxID_ANCHORSDEMOFRAMEBACKGROUNDPANEL, name = 'backgroundPanel', style = wxSIMPLE_BORDER | wxCLIP_CHILDREN, pos = wxPoint(8, 40))
31 self.backgroundPanel.SetBackgroundColour(wxColour(255, 255, 255))
32 self.backgroundPanel.SetConstraints(LayoutAnchors(self.backgroundPanel, true, true, true, true))
33
34 self.anchoredPanel = wxPanel(size = wxSize(88, 48), id = wxID_ANCHORSDEMOFRAMEANCHOREDPANEL, parent = self.backgroundPanel, name = 'anchoredPanel', style = wxSIMPLE_BORDER, pos = wxPoint(104, 16))
35 self.anchoredPanel.SetBackgroundColour(wxColour(0, 0, 222))
36 self.anchoredPanel.SetConstraints(LayoutAnchors(self.anchoredPanel, false, false, false, false))
37
38 self.leftCheckBox = wxCheckBox(label = 'Left', id = wxID_ANCHORSDEMOFRAMELEFTCHECKBOX, parent = self.mainPanel, name = 'leftCheckBox', size = wxSize(40, 16), style = 0, pos = wxPoint(8, 8))
39 self.leftCheckBox.SetConstraints(LayoutAnchors(self.leftCheckBox, false, true, false, false))
40 EVT_CHECKBOX(self.leftCheckBox, wxID_ANCHORSDEMOFRAMELEFTCHECKBOX, self.OnCheckboxCheckbox)
41
42 self.topCheckBox = wxCheckBox(label = 'Top', id = wxID_ANCHORSDEMOFRAMETOPCHECKBOX, parent = self.mainPanel, name = 'topCheckBox', size = wxSize(40, 16), style = 0, pos = wxPoint(88, 8))
43 self.topCheckBox.SetConstraints(LayoutAnchors(self.topCheckBox, false, true, false, false))
44 EVT_CHECKBOX(self.topCheckBox, wxID_ANCHORSDEMOFRAMETOPCHECKBOX, self.OnCheckboxCheckbox)
45
46 self.rightCheckBox = wxCheckBox(label = 'Right', id = wxID_ANCHORSDEMOFRAMERIGHTCHECKBOX, parent = self.mainPanel, name = 'rightCheckBox', size = wxSize(48, 16), style = 0, pos = wxPoint(168, 8))
47 self.rightCheckBox.SetConstraints(LayoutAnchors(self.rightCheckBox, false, true, false, false))
48 EVT_CHECKBOX(self.rightCheckBox, wxID_ANCHORSDEMOFRAMERIGHTCHECKBOX, self.OnCheckboxCheckbox)
49
50 self.bottomCheckBox = wxCheckBox(label = 'Bottom', id = wxID_ANCHORSDEMOFRAMEBOTTOMCHECKBOX, parent = self.mainPanel, name = 'bottomCheckBox', size = wxSize(56, 16), style = 0, pos = wxPoint(248, 8))
51 self.bottomCheckBox.SetConstraints(LayoutAnchors(self.bottomCheckBox, false, true, false, false))
52 EVT_CHECKBOX(self.bottomCheckBox, wxID_ANCHORSDEMOFRAMEBOTTOMCHECKBOX, self.OnCheckboxCheckbox)
53
54 self.helpStaticText = wxStaticText(label = 'Select anchor options above, then resize window to see the effect', id = wxID_ANCHORSDEMOFRAMEHELPSTATICTEXT, parent = self.mainPanel, name = 'helpStaticText', size = wxSize(224, 24), style = wxST_NO_AUTORESIZE, pos = wxPoint(8, 128))
55 self.helpStaticText.SetConstraints(LayoutAnchors(self.helpStaticText, true, false, true, true))
56
57 def __init__(self, parent):
58 self._init_ctrls(parent)
59
60 def OnCheckboxCheckbox(self, event):
61 self.anchoredPanel.SetConstraints(
62 LayoutAnchors(self.anchoredPanel,
63 self.leftCheckBox.GetValue(), self.topCheckBox.GetValue(),
64 self.rightCheckBox.GetValue(), self.bottomCheckBox.GetValue()) )
65
66 def OnOkButtonButton(self, event):
67 self.Close()
68
69 #----------------------------------------------------------------------
70
71 def runTest(frame, nb, log):
72 win = AnchorsDemoFrame(frame)
73 frame.otherWin = win
74 win.Show(true)
75
76
77
78
79 #----------------------------------------------------------------------
80
81
82
83
84 overview = """<html><body>
85 <h2>LayoutAnchors</h2>
86 A class that implements Delphi's Anchors with wxLayoutConstraints.
87 <p>
88 Anchored sides maintain the distance from the edge of the
89 control to the same edge of the parent.
90 When neither side is selected, the control keeps the same
91 relative position to both sides.
92 <p>
93 The current position and size of the control and it's parent
94 is used when setting up the constraints. To change the size or
95 position of an already anchored control, set the constraints to
96 None, reposition or resize and reapply the anchors.
97 <p>
98 Examples:
99 <p>
100 Let's anchor the right and bottom edge of a control and
101 resize it's parent.
102 <p>
103 <pre>
104 ctrl.SetConstraints(LayoutAnchors(ctrl, left=0, top=0, right=1, bottom=1))
105
106 +=========+ +===================+
107 | +-----+ | | |
108 | | * | -> | |
109 | +--*--+ | | +-----+ |
110 +---------+ | | * |
111 | +--*--+ |
112 +-------------------+
113 * = anchored edge
114 </pre>
115 <p>
116 When anchored on both sides the control will stretch horizontally.
117 <p>
118 <pre>
119 ctrl.SetConstraints(LayoutAnchors(ctrl, 1, 0, 1, 1))
120
121 +=========+ +===================+
122 | +-----+ | | |
123 | * * | -> | |
124 | +--*--+ | | +---------------+ |
125 +---------+ | * ctrl * |
126 | +-------*-------+ |
127 +-------------------+
128 * = anchored edge
129 </pre>
130 </html></body>
131 """
132
133
134
135
136
137
138
139
140