]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxRadioButton.py
1 # 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
3 # o Updated for wx namespace
8 #----------------------------------------------------------------------
10 class TestPanel( wx
.Panel
):
11 def __init__( self
, parent
, log
):
13 wx
.Panel
.__init
__( self
, parent
, -1 )
15 panel
= wx
.Panel( self
, -1 )
17 # 1st group of controls:
18 self
.group1_ctrls
= []
19 radio1
= wx
.RadioButton( panel
, -1, " Radio1 ", style
= wx
.RB_GROUP
)
20 text1
= wx
.TextCtrl( panel
, -1, "" )
21 radio2
= wx
.RadioButton( panel
, -1, " Radio2 " )
22 text2
= wx
.TextCtrl( panel
, -1, "" )
23 radio3
= wx
.RadioButton( panel
, -1, " Radio3 " )
24 text3
= wx
.TextCtrl( panel
, -1, "" )
25 self
.group1_ctrls
.append((radio1
, text1
))
26 self
.group1_ctrls
.append((radio2
, text2
))
27 self
.group1_ctrls
.append((radio3
, text3
))
29 # 2nd group of controls:
30 self
.group2_ctrls
= []
31 radio4
= wx
.RadioButton( panel
, -1, " Radio1 ", style
= wx
.RB_GROUP
)
32 text4
= wx
.TextCtrl( panel
, -1, "" )
33 radio5
= wx
.RadioButton( panel
, -1, " Radio2 " )
34 text5
= wx
.TextCtrl( panel
, -1, "" )
35 radio6
= wx
.RadioButton( panel
, -1, " Radio3 " )
36 text6
= wx
.TextCtrl( panel
, -1, "" )
37 self
.group2_ctrls
.append((radio4
, text4
))
38 self
.group2_ctrls
.append((radio5
, text5
))
39 self
.group2_ctrls
.append((radio6
, text6
))
41 # Layout controls on panel:
42 vs
= wx
.BoxSizer( wx
.VERTICAL
)
44 box1_title
= wx
.StaticBox( panel
, -1, "Group 1" )
45 box1
= wx
.StaticBoxSizer( box1_title
, wx
.VERTICAL
)
46 grid1
= wx
.FlexGridSizer( 0, 2, 0, 0 )
48 for radio
, text
in self
.group1_ctrls
:
49 grid1
.AddWindow( radio
, 0, wx
.ALIGN_CENTRE|wx
.LEFT|wx
.RIGHT|wx
.TOP
, 5 )
50 grid1
.AddWindow( text
, 0, wx
.ALIGN_CENTRE|wx
.LEFT|wx
.RIGHT|wx
.TOP
, 5 )
52 box1
.AddSizer( grid1
, 0, wx
.ALIGN_CENTRE|wx
.ALL
, 5 )
53 vs
.AddSizer( box1
, 0, wx
.ALIGN_CENTRE|wx
.ALL
, 5 )
55 box2_title
= wx
.StaticBox( panel
, -1, "Group 2" )
56 box2
= wx
.StaticBoxSizer( box2_title
, wx
.VERTICAL
)
57 grid2
= wx
.FlexGridSizer( 0, 2, 0, 0 )
59 for radio
, text
in self
.group2_ctrls
:
60 grid2
.AddWindow( radio
, 0, wx
.ALIGN_CENTRE|wx
.LEFT|wx
.RIGHT|wx
.TOP
, 5 )
61 grid2
.AddWindow( text
, 0, wx
.ALIGN_CENTRE|wx
.LEFT|wx
.RIGHT|wx
.TOP
, 5 )
63 box2
.AddSizer( grid2
, 0, wx
.ALIGN_CENTRE|wx
.ALL
, 5 )
64 vs
.AddSizer( box2
, 0, wx
.ALIGN_CENTRE|wx
.ALL
, 5 )
71 # Setup event handling and initial state for controls:
72 for radio
, text
in self
.group1_ctrls
:
73 self
.Bind(wx
.EVT_RADIOBUTTON
, self
.OnGroup1Select
, radio
)
75 for radio
, text
in self
.group2_ctrls
:
76 self
.Bind(wx
.EVT_RADIOBUTTON
, self
.OnGroup2Select
, radio
)
78 for radio
, text
in self
.group1_ctrls
+ self
.group2_ctrls
:
82 def OnGroup1Select( self
, event
):
83 radio_selected
= event
.GetEventObject()
84 self
.log
.write('Group1 %s selected\n' % radio_selected
.GetLabel() )
86 for radio
, text
in self
.group1_ctrls
:
87 if radio
is radio_selected
:
92 def OnGroup2Select( self
, event
):
93 radio_selected
= event
.GetEventObject()
94 self
.log
.write('Group2 %s selected\n' % radio_selected
.GetLabel() )
96 for radio
, text
in self
.group2_ctrls
:
97 if radio
is radio_selected
:
102 #----------------------------------------------------------------------
104 def runTest( frame
, nb
, log
):
105 win
= TestPanel( nb
, log
)
108 #----------------------------------------------------------------------
114 This demo shows how individual radio buttons can be used to build
115 more complicated selection mechanisms...
117 It uses 2 groups of wxRadioButtons, where the groups are defined by
118 instantiation. When a wxRadioButton is created with the <I>wxRB_GROUP</I>
119 style, all subsequent wxRadioButtons created without it are implicitly
120 added to that group by the framework.
126 if __name__
== '__main__':
129 run
.main(['', os
.path
.basename(sys
.argv
[0])])