]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/SizedControls.py
Add SizedControls demo.
[wxWidgets.git] / wxPython / demo / SizedControls.py
CommitLineData
5448935a
KO
1import wx
2import wxaddons.sized_controls as sc
3
4class FormDialog(sc.SizedDialog):
5 def __init__(self, parent, id):
6 sc.SizedDialog.__init__(self, None, -1, "SizedForm Dialog",
7 style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
8
9 pane = self.GetContentsPane()
10 pane.SetSizerType("form")
11
12 # row 1
13 wx.StaticText(pane, -1, "Name")
14 textCtrl = wx.TextCtrl(pane, -1, "Your name here")
15 textCtrl.SetSizerProps(expand=True)
16
17 # row 2
18 wx.StaticText(pane, -1, "Email")
19 emailCtrl = wx.TextCtrl(pane, -1, "")
20 emailCtrl.SetSizerProps(expand=True)
21
22 # row 3
23 wx.StaticText(pane, -1, "Gender")
24 wx.Choice(pane, -1, choices=["male", "female"])
25
26 # row 4
27 wx.StaticText(pane, -1, "State")
28 wx.TextCtrl(pane, -1, size=(60, -1)) # two chars for state
29
30 # row 5
31 wx.StaticText(pane, -1, "Title")
32
33 # here's how to add a 'nested sizer' using sized_controls
34 radioPane = sc.SizedPanel(pane, -1)
35 radioPane.SetSizerType("horizontal")
36 radioPane.SetSizerProps(expand=True)
37
38 # make these children of the radioPane to have them use
39 # the horizontal layout
40 wx.RadioButton(radioPane, -1, "Mr.")
41 wx.RadioButton(radioPane, -1, "Mrs.")
42 wx.RadioButton(radioPane, -1, "Dr.")
43 # end row 5
44
45 # add dialog buttons
46 self.SetButtonSizer(self.CreateStdDialogButtonSizer(wx.OK | wx.CANCEL))
47
48 # a little trick to make sure that you can't resize the dialog to
49 # less screen space than the controls need
50 self.Fit()
51 self.SetMinSize(self.GetSize())
52
53
54class ErrorDialog(sc.SizedDialog):
55 def __init__(self, parent, id):
56 sc.SizedDialog.__init__(self, parent, id, "Error log viewer",
57 wx.DefaultPosition, wx.Size(420, 340),
58 style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)
59
60 # Always use self.GetContentsPane() - this ensures that your dialog
61 # automatically adheres to HIG spacing requirements on all platforms.
62 # pane here is a sc.SizedPanel with a vertical sizer layout. All children
63 # should be added to this pane, NOT to self.
64 pane = self.GetContentsPane()
65
66 # first row
67 self.listCtrl = wx.ListCtrl(pane, -1, style=wx.LC_REPORT)
68 self.listCtrl.SetSizerProps(expand=True, proportion=1)
69 self.ConfigureListCtrl()
70
71 # second row
72 self.lblDetails = wx.StaticText(pane, -1, "Error Details")
73
74 # third row
75 self.details = wx.TextCtrl(pane, -1, style=wx.TE_MULTILINE)
76 self.details.SetSizerProps(expand=True, proportion=1)
77
78 # final row
79 # since we want to use a custom button layout, we won't use the
80 # CreateStdDialogBtnSizer here, we'll just create our own panel with
81 # a horizontal layout and add the buttons to that.
82 btnpane = sc.SizedPanel(pane, -1)
83 btnpane.SetSizerType("horizontal")
84 btnpane.SetSizerProps(expand=True)
85
86 self.saveBtn = wx.Button(btnpane, wx.ID_SAVE)
87 spacer = sc.SizedPanel(btnpane, -1)
88 spacer.SetSizerProps(expand=True, proportion=1)
89
90 self.clearBtn = wx.Button(btnpane, -1, "Clear")
91
92 self.Fit()
93 self.SetMinSize(self.GetSize())
94
95 def ConfigureListCtrl(self):
96 self.listCtrl.InsertColumn(0, "Time")
97 self.listCtrl.InsertColumn(1, "Error Message")
98 self.listCtrl.SetColumnWidth(0, 100)
99 self.listCtrl.SetColumnWidth(1, 280)
100
101#---------------------------------------------------------------------------
102
103class TestPanel(wx.Panel):
104 def __init__(self, parent, log):
105 self.log = log
106 self.parent = parent
107 wx.Panel.__init__(self, parent, -1)
108
109 b = wx.Button(self, -1, "Sized Controls Form Dialog", (50,50))
110 self.Bind(wx.EVT_BUTTON, self.OnFormButton, b)
111
112 b2 = wx.Button(self, -1, "Sized Controls Error Dialog", (50,90))
113 self.Bind(wx.EVT_BUTTON, self.OnErrorButton, b2)
114
115
116 def OnFormButton(self, evt):
117 print
118 dlg = FormDialog(self, -1)
119 dlg.CenterOnScreen()
120
121 # this does not return until the dialog is closed.
122 val = dlg.ShowModal()
123
124 if val == wx.ID_OK:
125 self.log.WriteText("You pressed OK\n")
126 else:
127 self.log.WriteText("You pressed Cancel\n")
128
129 dlg.Destroy()
130
131 def OnErrorButton(self, evt):
132
133 dlg = ErrorDialog(self, -1)
134 dlg.CenterOnScreen()
135
136 # this does not return until the dialog is closed.
137 val = dlg.ShowModal()
138
139 if val == wx.ID_OK:
140 self.log.WriteText("You pressed OK\n")
141 else:
142 self.log.WriteText("You pressed Cancel\n")
143
144 dlg.Destroy()
145
146def runTest(frame, nb, log):
147 win = TestPanel(nb, log)
148 return win
149
150
151if __name__ == "__main__":
152 app = wx.PySimpleApp()
153 dlg = FormDialog()
154 dlg.ShowModal()