]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/demo/LayoutAnchors.py
reSWIGged
[wxWidgets.git] / wxPython / demo / LayoutAnchors.py
index b201372a7ec25ce07853e6d85ff47d9563c96279..188cdd2f5bd6d20e05bf8f65b571852d72e2c6d1 100644 (file)
 
-from wxPython.wx import *
-from wxPython.lib.anchors import LayoutAnchors
+import  wx
+import  wx.lib.anchors as anchors
 
 #----------------------------------------------------------------------
 
-
-[wxID_ANCHORSDEMOFRAMEANCHOREDPANEL, wxID_ANCHORSDEMOFRAMEHELPSTATICTEXT,
- wxID_ANCHORSDEMOFRAMEMAINPANEL, wxID_ANCHORSDEMOFRAMEBACKGROUNDPANEL,
- wxID_ANCHORSDEMOFRAMERIGHTCHECKBOX, wxID_ANCHORSDEMOFRAMEOKBUTTON,
- wxID_ANCHORSDEMOFRAMETOPCHECKBOX, wxID_ANCHORSDEMOFRAMEBOTTOMCHECKBOX,
- wxID_ANCHORSDEMOFRAME, wxID_ANCHORSDEMOFRAMELEFTCHECKBOX,
- ] = map(lambda _init_ctrls: wxNewId(), range(10))
-
-class AnchorsDemoFrame(wxFrame):
+# Nifty little trick here; apply wx.NewId() to generate a series of
+# IDs used later on in the app. 
+
+[   ID_ANCHORSDEMOFRAMEANCHOREDPANEL, 
+    ID_ANCHORSDEMOFRAMEHELPSTATICTEXT,
+    ID_ANCHORSDEMOFRAMEMAINPANEL, 
+    ID_ANCHORSDEMOFRAMEBACKGROUNDPANEL,
+    ID_ANCHORSDEMOFRAMERIGHTCHECKBOX, 
+    ID_ANCHORSDEMOFRAMEOKBUTTON,
+    ID_ANCHORSDEMOFRAMETOPCHECKBOX, 
+    ID_ANCHORSDEMOFRAMEBOTTOMCHECKBOX,
+    ID_ANCHORSDEMOFRAME, 
+    ID_ANCHORSDEMOFRAMELEFTCHECKBOX,
+ ] = map(lambda _init_ctrls: wx.NewId(), range(10))
+
+# A small note here: while only certain parts of this frame are actually demonstrating
+# the capabilities of the LayoutAnchors feature, all the controls are within the same
+# frame; therefore, all controls and windows within the frame must use LayoutAnchors.
+# You can't mix LayoutAnchors and sizers.
+class AnchorsDemoFrame(wx.Frame):
     def _init_utils(self):
         pass
 
     def _init_ctrls(self, prnt):
-        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))
-        self._init_utils()
-
-        self.mainPanel = wxPanel(size = wxSize(320, 160), parent = self, id = wxID_ANCHORSDEMOFRAMEMAINPANEL, name = 'panel1', style = wxTAB_TRAVERSAL | wxCLIP_CHILDREN, pos = wxPoint(0, 0))
-        self.mainPanel.SetAutoLayout(true)
-
-        self.okButton = wxButton(label = 'OK', id = wxID_ANCHORSDEMOFRAMEOKBUTTON, parent = self.mainPanel, name = 'okButton', size = wxSize(72, 24), style = 0, pos = wxPoint(240, 128))
-        self.okButton.SetConstraints(LayoutAnchors(self.okButton, false, false, true, true))
-        EVT_BUTTON(self.okButton, wxID_ANCHORSDEMOFRAMEOKBUTTON, self.OnOkButtonButton)
-
-        self.backgroundPanel = wxPanel(size = wxSize(304, 80), parent = self.mainPanel, id = wxID_ANCHORSDEMOFRAMEBACKGROUNDPANEL, name = 'backgroundPanel', style = wxSIMPLE_BORDER | wxCLIP_CHILDREN, pos = wxPoint(8, 40))
-        self.backgroundPanel.SetBackgroundColour(wxColour(255, 255, 255))
-        self.backgroundPanel.SetConstraints(LayoutAnchors(self.backgroundPanel, true, true, true, true))
-
-        self.anchoredPanel = wxPanel(size = wxSize(88, 48), id = wxID_ANCHORSDEMOFRAMEANCHOREDPANEL, parent = self.backgroundPanel, name = 'anchoredPanel', style = wxSIMPLE_BORDER, pos = wxPoint(104, 16))
-        self.anchoredPanel.SetBackgroundColour(wxColour(0, 0, 222))
-        self.anchoredPanel.SetConstraints(LayoutAnchors(self.anchoredPanel, false, false, false, false))
-
-        self.leftCheckBox = wxCheckBox(label = 'Left', id = wxID_ANCHORSDEMOFRAMELEFTCHECKBOX, parent = self.mainPanel, name = 'leftCheckBox', size = wxSize(40, 16), style = 0, pos = wxPoint(8, 8))
-        self.leftCheckBox.SetConstraints(LayoutAnchors(self.leftCheckBox, false, true, false, false))
-        EVT_CHECKBOX(self.leftCheckBox, wxID_ANCHORSDEMOFRAMELEFTCHECKBOX, self.OnCheckboxCheckbox)
-
-        self.topCheckBox = wxCheckBox(label = 'Top', id = wxID_ANCHORSDEMOFRAMETOPCHECKBOX, parent = self.mainPanel, name = 'topCheckBox', size = wxSize(40, 16), style = 0, pos = wxPoint(88, 8))
-        self.topCheckBox.SetConstraints(LayoutAnchors(self.topCheckBox, false, true, false, false))
-        EVT_CHECKBOX(self.topCheckBox, wxID_ANCHORSDEMOFRAMETOPCHECKBOX, self.OnCheckboxCheckbox)
-
-        self.rightCheckBox = wxCheckBox(label = 'Right', id = wxID_ANCHORSDEMOFRAMERIGHTCHECKBOX, parent = self.mainPanel, name = 'rightCheckBox', size = wxSize(48, 16), style = 0, pos = wxPoint(168, 8))
-        self.rightCheckBox.SetConstraints(LayoutAnchors(self.rightCheckBox, false, true, false, false))
-        EVT_CHECKBOX(self.rightCheckBox, wxID_ANCHORSDEMOFRAMERIGHTCHECKBOX, self.OnCheckboxCheckbox)
+        wx.Frame.__init__(
+            self, size=(328, 187), id=ID_ANCHORSDEMOFRAME, 
+            title='LayoutAnchors Demonstration', parent=prnt, 
+            name='AnchorsDemoFrame', 
+            style = wx.DEFAULT_FRAME_STYLE | wx.CLIP_CHILDREN, pos=(261, 123)
+            )
 
-        self.bottomCheckBox = wxCheckBox(label = 'Bottom', id = wxID_ANCHORSDEMOFRAMEBOTTOMCHECKBOX, parent = self.mainPanel, name = 'bottomCheckBox', size = wxSize(56, 16), style = 0, pos = wxPoint(248, 8))
-        self.bottomCheckBox.SetConstraints(LayoutAnchors(self.bottomCheckBox, false, true, false, false))
-        EVT_CHECKBOX(self.bottomCheckBox, wxID_ANCHORSDEMOFRAMEBOTTOMCHECKBOX, self.OnCheckboxCheckbox)
+        self._init_utils()
 
-        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))
-        self.helpStaticText.SetConstraints(LayoutAnchors(self.helpStaticText, true, false, true, true))
+        self.mainPanel = wx.Panel(
+                            size=(320, 160), parent=self, 
+                            id=ID_ANCHORSDEMOFRAMEMAINPANEL, name='panel1', 
+                            style=wx.TAB_TRAVERSAL | wx.CLIP_CHILDREN, 
+                            pos=(0, 0)
+                            )
+
+        self.mainPanel.SetAutoLayout(True)
+
+        self.okButton = wx.Button(
+                            label='OK', id=ID_ANCHORSDEMOFRAMEOKBUTTON, 
+                            parent=self.mainPanel, name='okButton', 
+                            size=(72, 24), style=0, pos=(240, 128)
+                            )
+
+        self.okButton.SetConstraints(
+            anchors.LayoutAnchors(self.okButton, False, False, True, True)
+            )
+
+        self.Bind(
+            wx.EVT_BUTTON, self.OnOkButtonButton, id=ID_ANCHORSDEMOFRAMEOKBUTTON
+            )
+
+        self.backgroundPanel = wx.Panel(
+                                size=(304, 80), parent=self.mainPanel, 
+                                id=ID_ANCHORSDEMOFRAMEBACKGROUNDPANEL, 
+                                name='backgroundPanel', 
+                                style=wx.SIMPLE_BORDER | wx.CLIP_CHILDREN, 
+                                pos = (8, 40)
+                                )
+
+        self.backgroundPanel.SetBackgroundColour(wx.Colour(255, 255, 255))
+        self.backgroundPanel.SetConstraints(
+            anchors.LayoutAnchors(self.backgroundPanel, True, True, True, True)
+            )
+
+        self.anchoredPanel = wx.Panel(
+                                size=(88, 48), id=ID_ANCHORSDEMOFRAMEANCHOREDPANEL, 
+                                parent=self.backgroundPanel, name='anchoredPanel', 
+                                style=wx.SIMPLE_BORDER, pos=(104, 16)
+                                )
+
+        self.anchoredPanel.SetBackgroundColour(wx.Colour(0, 0, 222))
+        self.anchoredPanel.SetConstraints(
+            anchors.LayoutAnchors(self.anchoredPanel, False, False, False, False)
+            )
+
+        self.leftCheckBox = wx.CheckBox(
+                                label='Left', id=ID_ANCHORSDEMOFRAMELEFTCHECKBOX, 
+                                parent=self.mainPanel, name='leftCheckBox', 
+                                size=(40, 16), style=0, pos=(8, 8)
+                                )
+
+        self.leftCheckBox.SetConstraints(
+            anchors.LayoutAnchors(self.leftCheckBox, False, True, False, False)
+            )
+        
+        self.Bind(
+            wx.EVT_CHECKBOX, self.OnCheckboxCheckbox, source=self.leftCheckBox,
+            id=ID_ANCHORSDEMOFRAMELEFTCHECKBOX
+            )
+
+        self.topCheckBox = wx.CheckBox(
+                            label='Top', id=ID_ANCHORSDEMOFRAMETOPCHECKBOX, 
+                            parent=self.mainPanel, name='topCheckBox', 
+                            size=(40, 16), style=0, pos=(88, 8)
+                            )
+
+        self.topCheckBox.SetConstraints(
+            anchors.LayoutAnchors(self.topCheckBox, False, True, False, False)
+            )
+        
+        self.Bind(
+            wx.EVT_CHECKBOX, self.OnCheckboxCheckbox, source=self.topCheckBox,
+            id=ID_ANCHORSDEMOFRAMETOPCHECKBOX
+            )
+
+        self.rightCheckBox = wx.CheckBox(
+                            label='Right', id=ID_ANCHORSDEMOFRAMERIGHTCHECKBOX, 
+                            parent=self.mainPanel, name='rightCheckBox', 
+                            size=(48, 16), style=0, pos=(168, 8)
+                            )
+
+        self.rightCheckBox.SetConstraints(
+            anchors.LayoutAnchors(self.rightCheckBox, False, True, False, False)
+            )
+
+        self.Bind(
+            wx.EVT_CHECKBOX, self.OnCheckboxCheckbox, source=self.rightCheckBox,
+            id=ID_ANCHORSDEMOFRAMERIGHTCHECKBOX
+            )
+
+        self.bottomCheckBox = wx.CheckBox(
+                                label='Bottom', id=ID_ANCHORSDEMOFRAMEBOTTOMCHECKBOX, 
+                                parent=self.mainPanel, name='bottomCheckBox', 
+                                size=(56, 16), style=0, pos=(248, 8)
+                                )
+
+        self.bottomCheckBox.SetConstraints(
+            anchors.LayoutAnchors(self.bottomCheckBox, False, True, False, False)
+            )
+
+        self.Bind(
+            wx.EVT_CHECKBOX, self.OnCheckboxCheckbox, source=self.bottomCheckBox,
+            id=ID_ANCHORSDEMOFRAMEBOTTOMCHECKBOX
+            )
+
+        self.helpStaticText = wx.StaticText(
+                                label='Select anchor options above, then resize window to see the effect', 
+                                id=ID_ANCHORSDEMOFRAMEHELPSTATICTEXT, 
+                                parent=self.mainPanel, name='helpStaticText', 
+                                size=(224, 24), style=wx.ST_NO_AUTORESIZE, 
+                                pos=(8, 128)
+                                )
+
+        self.helpStaticText.SetConstraints(
+            anchors.LayoutAnchors(self.helpStaticText, True, False, True, True)
+            )
 
     def __init__(self, parent):
         self._init_ctrls(parent)
 
+    # Based on the values of the above checkboxes, we will adjust the layout constraints
+    # on the sample window whenever one of the checkboxes changes state.
     def OnCheckboxCheckbox(self, event):
         self.anchoredPanel.SetConstraints(
-            LayoutAnchors(self.anchoredPanel,
+            anchors.LayoutAnchors(self.anchoredPanel,
                           self.leftCheckBox.GetValue(), self.topCheckBox.GetValue(),
-                          self.rightCheckBox.GetValue(), self.bottomCheckBox.GetValue()) )
+                          self.rightCheckBox.GetValue(), self.bottomCheckBox.GetValue()
+                          ) 
+            )
 
     def OnOkButtonButton(self, event):
         self.Close()
@@ -71,7 +177,7 @@ class AnchorsDemoFrame(wxFrame):
 def runTest(frame, nb, log):
     win = AnchorsDemoFrame(frame)
     frame.otherWin = win
-    win.Show(true)
+    win.Show(True)
 
 
 
@@ -79,8 +185,6 @@ def runTest(frame, nb, log):
 #----------------------------------------------------------------------
 
 
-
-
 overview = """<html><body>
 <h2>LayoutAnchors</h2>
         A class that implements Delphi's Anchors with wxLayoutConstraints.
@@ -132,9 +236,8 @@ overview = """<html><body>
 
 
 
-
-
-
-
-
+if __name__ == '__main__':
+    import sys,os
+    import run
+    run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])