]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/RadioButton.py
Docsrings for wxSplitterWindow
[wxWidgets.git] / wxPython / demo / RadioButton.py
CommitLineData
8fa876ca
RD
1
2import wx
3
1e4a197e
RD
4#----------------------------------------------------------------------
5
8fa876ca 6class TestPanel( wx.Panel ):
1e4a197e
RD
7 def __init__( self, parent, log ):
8
8fa876ca 9 wx.Panel.__init__( self, parent, -1 )
1e4a197e 10 self.log = log
8fa876ca 11 panel = wx.Panel( self, -1 )
1e4a197e
RD
12
13 # 1st group of controls:
14 self.group1_ctrls = []
8fa876ca
RD
15 radio1 = wx.RadioButton( panel, -1, " Radio1 ", style = wx.RB_GROUP )
16 text1 = wx.TextCtrl( panel, -1, "" )
17 radio2 = wx.RadioButton( panel, -1, " Radio2 " )
18 text2 = wx.TextCtrl( panel, -1, "" )
19 radio3 = wx.RadioButton( panel, -1, " Radio3 " )
20 text3 = wx.TextCtrl( panel, -1, "" )
1e4a197e
RD
21 self.group1_ctrls.append((radio1, text1))
22 self.group1_ctrls.append((radio2, text2))
23 self.group1_ctrls.append((radio3, text3))
24
25 # 2nd group of controls:
26 self.group2_ctrls = []
8fa876ca
RD
27 radio4 = wx.RadioButton( panel, -1, " Radio1 ", style = wx.RB_GROUP )
28 text4 = wx.TextCtrl( panel, -1, "" )
29 radio5 = wx.RadioButton( panel, -1, " Radio2 " )
30 text5 = wx.TextCtrl( panel, -1, "" )
31 radio6 = wx.RadioButton( panel, -1, " Radio3 " )
32 text6 = wx.TextCtrl( panel, -1, "" )
1e4a197e
RD
33 self.group2_ctrls.append((radio4, text4))
34 self.group2_ctrls.append((radio5, text5))
35 self.group2_ctrls.append((radio6, text6))
36
37 # Layout controls on panel:
8fa876ca
RD
38 vs = wx.BoxSizer( wx.VERTICAL )
39
40 box1_title = wx.StaticBox( panel, -1, "Group 1" )
41 box1 = wx.StaticBoxSizer( box1_title, wx.VERTICAL )
42 grid1 = wx.FlexGridSizer( 0, 2, 0, 0 )
1e4a197e 43
1e4a197e 44 for radio, text in self.group1_ctrls:
8fa876ca
RD
45 grid1.AddWindow( radio, 0, wx.ALIGN_CENTRE|wx.LEFT|wx.RIGHT|wx.TOP, 5 )
46 grid1.AddWindow( text, 0, wx.ALIGN_CENTRE|wx.LEFT|wx.RIGHT|wx.TOP, 5 )
47
48 box1.AddSizer( grid1, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
49 vs.AddSizer( box1, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
50
51 box2_title = wx.StaticBox( panel, -1, "Group 2" )
52 box2 = wx.StaticBoxSizer( box2_title, wx.VERTICAL )
53 grid2 = wx.FlexGridSizer( 0, 2, 0, 0 )
54
1e4a197e 55 for radio, text in self.group2_ctrls:
8fa876ca
RD
56 grid2.AddWindow( radio, 0, wx.ALIGN_CENTRE|wx.LEFT|wx.RIGHT|wx.TOP, 5 )
57 grid2.AddWindow( text, 0, wx.ALIGN_CENTRE|wx.LEFT|wx.RIGHT|wx.TOP, 5 )
58
59 box2.AddSizer( grid2, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
60 vs.AddSizer( box2, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
1e4a197e
RD
61
62 panel.SetSizer( vs )
63 vs.Fit( panel )
64 panel.Move( (50,50) )
65 self.panel = panel
66
67 # Setup event handling and initial state for controls:
68 for radio, text in self.group1_ctrls:
8fa876ca 69 self.Bind(wx.EVT_RADIOBUTTON, self.OnGroup1Select, radio )
1e4a197e
RD
70
71 for radio, text in self.group2_ctrls:
8fa876ca 72 self.Bind(wx.EVT_RADIOBUTTON, self.OnGroup2Select, radio )
1e4a197e
RD
73
74 for radio, text in self.group1_ctrls + self.group2_ctrls:
75 radio.SetValue(0)
76 text.Enable(False)
77
1e4a197e
RD
78 def OnGroup1Select( self, event ):
79 radio_selected = event.GetEventObject()
80 self.log.write('Group1 %s selected\n' % radio_selected.GetLabel() )
8fa876ca 81
1e4a197e
RD
82 for radio, text in self.group1_ctrls:
83 if radio is radio_selected:
84 text.Enable(True)
85 else:
86 text.Enable(False)
87
88 def OnGroup2Select( self, event ):
89 radio_selected = event.GetEventObject()
90 self.log.write('Group2 %s selected\n' % radio_selected.GetLabel() )
8fa876ca 91
1e4a197e
RD
92 for radio, text in self.group2_ctrls:
93 if radio is radio_selected:
94 text.Enable(True)
95 else:
96 text.Enable(False)
97
98#----------------------------------------------------------------------
99
100def runTest( frame, nb, log ):
101 win = TestPanel( nb, log )
102 return win
103
104#----------------------------------------------------------------------
105
106
107overview = """\
108<html><body>
109<P>
110This demo shows how individual radio buttons can be used to build
111more complicated selection mechanisms...
112<P>
95bfd958
RD
113It uses 2 groups of wx.RadioButtons, where the groups are defined by
114instantiation. When a wx.RadioButton is created with the <I>wx.RB_GROUP</I>
115style, all subsequent wx.RadioButtons created without it are implicitly
1e4a197e
RD
116added to that group by the framework.
117</body></html>
118"""
119
120
121
122if __name__ == '__main__':
123 import sys,os
124 import run
8eca4fef 125 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
1e4a197e 126