| 1 | from wxPython.wx import * |
| 2 | #from Lib.Gui.PlainWidgets import * |
| 3 | |
| 4 | class TestLayoutConstraints(wxPanel): |
| 5 | def __init__(self, parent): |
| 6 | wxPanel.__init__(self, parent, -1) |
| 7 | # |
| 8 | nb = wxNotebook(self, -1) |
| 9 | page = wxPanel(nb, -1) |
| 10 | page.SetBackgroundColour(wxBLUE) |
| 11 | button = wxButton(page, -1, 'press me') |
| 12 | # |
| 13 | nb.AddPage(page, 'testpage') |
| 14 | # |
| 15 | lc = wxLayoutConstraints() |
| 16 | lc.top.PercentOf(parent, wxBottom, 0) |
| 17 | lc.bottom.PercentOf(parent, wxBottom, 100) |
| 18 | lc.left.PercentOf(parent, wxRight, 0) |
| 19 | lc.right.PercentOf(parent, wxRight, 100) |
| 20 | self.SetConstraints(lc) |
| 21 | self.SetAutoLayout(true) |
| 22 | # |
| 23 | lc = wxLayoutConstraints() |
| 24 | lc.top.PercentOf(self, wxBottom, 0) |
| 25 | lc.bottom.PercentOf(self, wxBottom, 100) |
| 26 | lc.left.PercentOf(self, wxRight, 0) |
| 27 | lc.right.PercentOf(self, wxRight, 100) |
| 28 | nb.SetConstraints(lc) |
| 29 | # nb.SetAutoLayout(true) |
| 30 | # |
| 31 | # lc = wxLayoutConstraints() |
| 32 | # lc.top.PercentOf(nb, wxBottom, 0) |
| 33 | # lc.bottom.PercentOf(nb, wxBottom, 100) |
| 34 | # lc.left.PercentOf(nb, wxRight, 0) |
| 35 | # lc.right.PercentOf(nb, wxRight, 100) |
| 36 | # page.SetConstraints(lc) |
| 37 | page.SetAutoLayout(true) |
| 38 | |
| 39 | # this should center "button" on "page": |
| 40 | lc = wxLayoutConstraints() |
| 41 | lc.centreY.PercentOf(page, wxBottom, 50) |
| 42 | lc.centreX.PercentOf(page, wxRight, 50) |
| 43 | lc.width.AsIs() |
| 44 | lc.height.AsIs() |
| 45 | button.SetConstraints(lc) |
| 46 | # button.SetAutoLayout(true) |
| 47 | # |
| 48 | button.Layout() |
| 49 | page.Layout() |
| 50 | nb.Layout() |
| 51 | self.Layout() |
| 52 | |
| 53 | |
| 54 | if __name__ == "__main__": |
| 55 | class MyFrame(wxFrame): |
| 56 | def __init__(self, *argT, **optionD): |
| 57 | apply(wxFrame.__init__, (self,) + argT, optionD) |
| 58 | self.SetAutoLayout(true) |
| 59 | TestLayoutConstraints(self) |
| 60 | |
| 61 | class MyApp(wxApp): |
| 62 | def OnInit(self): |
| 63 | frame = MyFrame(None, -1, "TestLayoutConstraints", |
| 64 | size=wxSize(400,300)) |
| 65 | frame.Show(true) |
| 66 | return true |
| 67 | |
| 68 | app = MyApp() |
| 69 | app.MainLoop() |