2 import wxaddons
.sized_controls
as sc
4 class 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
)
9 pane
= self
.GetContentsPane()
10 pane
.SetSizerType("form")
13 wx
.StaticText(pane
, -1, "Name")
14 textCtrl
= wx
.TextCtrl(pane
, -1, "Your name here")
15 textCtrl
.SetSizerProps(expand
=True)
18 wx
.StaticText(pane
, -1, "Email")
19 emailCtrl
= wx
.TextCtrl(pane
, -1, "")
20 emailCtrl
.SetSizerProps(expand
=True)
23 wx
.StaticText(pane
, -1, "Gender")
24 wx
.Choice(pane
, -1, choices
=["male", "female"])
27 wx
.StaticText(pane
, -1, "State")
28 wx
.TextCtrl(pane
, -1, size
=(60, -1)) # two chars for state
31 wx
.StaticText(pane
, -1, "Title")
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)
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.")
46 self
.SetButtonSizer(self
.CreateStdDialogButtonSizer(wx
.OK | wx
.CANCEL
))
48 # a little trick to make sure that you can't resize the dialog to
49 # less screen space than the controls need
51 self
.SetMinSize(self
.GetSize())
54 class 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
)
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()
67 self
.listCtrl
= wx
.ListCtrl(pane
, -1, style
=wx
.LC_REPORT
)
68 self
.listCtrl
.SetSizerProps(expand
=True, proportion
=1)
69 self
.ConfigureListCtrl()
72 self
.lblDetails
= wx
.StaticText(pane
, -1, "Error Details")
75 self
.details
= wx
.TextCtrl(pane
, -1, style
=wx
.TE_MULTILINE
)
76 self
.details
.SetSizerProps(expand
=True, proportion
=1)
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)
86 self
.saveBtn
= wx
.Button(btnpane
, wx
.ID_SAVE
)
87 spacer
= sc
.SizedPanel(btnpane
, -1)
88 spacer
.SetSizerProps(expand
=True, proportion
=1)
90 self
.clearBtn
= wx
.Button(btnpane
, -1, "Clear")
93 self
.SetMinSize(self
.GetSize())
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)
101 #---------------------------------------------------------------------------
103 class TestPanel(wx
.Panel
):
104 def __init__(self
, parent
, log
):
107 wx
.Panel
.__init
__(self
, parent
, -1)
109 b
= wx
.Button(self
, -1, "Sized Controls Form Dialog", (50,50))
110 self
.Bind(wx
.EVT_BUTTON
, self
.OnFormButton
, b
)
112 b2
= wx
.Button(self
, -1, "Sized Controls Error Dialog", (50,90))
113 self
.Bind(wx
.EVT_BUTTON
, self
.OnErrorButton
, b2
)
116 def OnFormButton(self
, evt
):
118 dlg
= FormDialog(self
, -1)
121 # this does not return until the dialog is closed.
122 val
= dlg
.ShowModal()
125 self
.log
.WriteText("You pressed OK\n")
127 self
.log
.WriteText("You pressed Cancel\n")
131 def OnErrorButton(self
, evt
):
133 dlg
= ErrorDialog(self
, -1)
136 # this does not return until the dialog is closed.
137 val
= dlg
.ShowModal()
140 self
.log
.WriteText("You pressed OK\n")
142 self
.log
.WriteText("You pressed Cancel\n")
146 def runTest(frame
, nb
, log
):
147 win
= TestPanel(nb
, log
)
151 if __name__
== "__main__":
152 app
= wx
.PySimpleApp()