Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / lib / python2.4 / site-packages / Pmw / Pmw_1_2 / doc / RadioSelect.html
CommitLineData
920dae64
AT
1
2 <html>
3 <head>
4 <meta name="description" content="Pmw - a toolkit for building high-level compound widgets in Python">
5 <meta name="content" content="python, megawidget, mega widget, compound widget, gui, tkinter">
6 <title>Pmw.RadioSelect reference manual</title>
7 </head>
8
9 <body bgcolor="#ffffff" text="#000000" link="#0000ee"
10 vlink="551a8b" alink="ff0000">
11
12 <h1 ALIGN="CENTER">Pmw.RadioSelect</h1>
13
14<center><IMG SRC=RadioSelect.gif ALT="" WIDTH=466 HEIGHT=272></center>
15<dl>
16<dt> <h3>Name</h3></dt><dd>
17<p>Pmw.RadioSelect() -
18 a set of buttons, some of which may be selected
19</p>
20
21
22</dd>
23<dt> <h3>Inherits</h3></dt><dd>
24<a href="MegaWidget.html">Pmw.MegaWidget</a><br>
25</dd>
26<dt> <h3>Description</h3></dt><dd>
27<p>
28 A radio select is a container megawidget which manages a number of
29 buttons. The buttons may be laid out either horizontally or
30 vertically. In single selection mode, only one button may be
31 selected at any one time. In multiple selection mode, several
32 buttons may be selected at the same time and clicking on a
33 selected button will deselect it. </p>
34
35<p> The buttons displayed can be either standard buttons, radio
36 buttons or check buttons. When selected, standard buttons are
37 displayed sunken and radio and check buttons are displayed with
38 the appropriate indicator color and relief.</p>
39
40<p></p>
41
42
43</dd>
44<dt> <h3>Options</h3></dt><dd>
45Options for this megawidget and its base
46classes are described below.<p></p>
47<a name=option.buttontype></a>
48<dl><dt> <strong>buttontype
49</strong></dt><dd>
50Initialisation option. Specifies the default type of buttons created by the <code>add()</code>
51 method. If <strong>'button'</strong>, the default type is Tkinter.Button. If
52 <strong>'radiobutton'</strong>, the default type is Tkinter.Radiobutton. If
53 <strong>'checkbutton'</strong>, the default type is Tkinter.Checkbutton.</p>
54<p> If <strong>'radiobutton'</strong>, single selection mode is automatically set.
55 If <strong>'checkbutton'</strong>, multiple selection mode is automatically set. The default is <strong>'button'</strong>.</p>
56
57
58
59</dd></dl>
60<a name=option.command></a>
61<dl><dt> <strong>command
62</strong></dt><dd>
63Specifies a function to call when one of the buttons is clicked on
64 or when <code>invoke()</code> is called.</p>
65<p> In single selection mode, the function is called with a single
66 argument, which is the name of the selected button.</p>
67
68<p> In multiple selection mode, the function is called with the first
69 argument being the name of the button and the second argument
70 being true if the button is now selected or false if it is now
71 deselected. The default is <strong>None</strong>.</p>
72
73
74
75</dd></dl>
76<a name=option.labelmargin></a>
77<dl><dt> <strong>labelmargin
78</strong></dt><dd>
79Initialisation option. If the <strong>labelpos</strong> option is not <strong>None</strong>, this specifies the
80 distance between the <strong>label</strong> component and the rest of the
81 megawidget. The default is <strong>0</strong>.</p>
82
83
84</dd></dl>
85<a name=option.labelpos></a>
86<dl><dt> <strong>labelpos
87</strong></dt><dd>
88Initialisation option. Specifies where to place the <strong>label</strong> component. If not
89 <strong>None</strong>, it should be a concatenation of one or two of the
90 letters <strong>'n'</strong>, <strong>'s'</strong>, <strong>'e'</strong> and <strong>'w'</strong>. The first letter
91 specifies on which side of the megawidget to place the label.
92 If a second letter is specified, it indicates where on that
93 side to place the label. For example, if <strong>labelpos</strong> is <strong>'w'</strong>,
94 the label is placed in the center of the left hand side; if
95 it is <strong>'wn'</strong>, the label is placed at the top of the left
96 hand side; if it is <strong>'ws'</strong>, the label is placed at the
97 bottom of the left hand side.</p>
98<p> If <strong>None</strong>, a label component is not created. The default is <strong>None</strong>.</p>
99
100
101
102</dd></dl>
103<a name=option.orient></a>
104<dl><dt> <strong>orient
105</strong></dt><dd>
106Initialisation option. Specifies the direction in which the buttons are laid out. This
107 may be <strong>'horizontal'</strong> or <strong>'vertical'</strong>. The default is <strong>'horizontal'</strong>.</p>
108
109
110</dd></dl>
111<a name=option.padx></a>
112<dl><dt> <strong>padx
113</strong></dt><dd>
114Initialisation option. Specifies a padding distance to leave between each button in the x
115 direction and also between the buttons and the outer edge of the
116 radio select. The default is <strong>5</strong>.</p>
117
118
119</dd></dl>
120<a name=option.pady></a>
121<dl><dt> <strong>pady
122</strong></dt><dd>
123Initialisation option. Specifies a padding distance to leave between each button in the y
124 direction and also between the buttons and the outer edge of the
125 radio select. The default is <strong>5</strong>.</p>
126
127
128</dd></dl>
129<a name=option.selectmode></a>
130<dl><dt> <strong>selectmode
131</strong></dt><dd>
132Initialisation option. Specifies the selection mode: whether a single button or multiple
133 buttons can be selected at one time. If <strong>'single'</strong>, clicking on
134 an unselected button selects it and deselects all other buttons.
135 If <strong>'multiple'</strong>, clicking on an unselected button selects it and
136 clicking on a selected button deselects it. This option is
137 ignored if <strong>buttontype</strong> is <strong>'radiobutton'</strong> or <strong>'checkbutton'</strong>. The default is <strong>'single'</strong>.</p>
138
139
140</dd></dl>
141</dd>
142<dt> <h3>Components</h3></dt><dd>
143Components created by this megawidget and its base
144classes are described below.<p></p>
145<a name=component.frame></a>
146<dl><dt> <strong>frame
147</strong></dt><dd>
148If the <strong>label</strong> component has been created (that is, the <strong>labelpos</strong>
149 option is not <strong>None</strong>), the <strong>frame</strong> component is created to act as
150 the container of the buttons created by the <code>add()</code> method. If
151 there is no <strong>label</strong> component, then no <strong>frame</strong> component is
152 created and the <strong>hull</strong> component acts as the container. By default, this component is a Tkinter.Frame.</p>
153
154
155</dd></dl>
156<a name=component.hull></a>
157<dl><dt> <strong>hull
158</strong></dt><dd>
159This acts as the body for the entire megawidget. Other components
160 are created as children of the hull to further specialise this
161 class. By default, this component is a Tkinter.Frame.</p>
162
163
164</dd></dl>
165<a name=component.label></a>
166<dl><dt> <strong>label
167</strong></dt><dd>
168If the <strong>labelpos</strong> option is not <strong>None</strong>, this component is
169 created as a text label for the megawidget. See the
170 <strong>labelpos</strong> option for details. Note that to set, for example,
171 the <strong>text</strong> option of the label, you need to use the <strong>label_text</strong>
172 component option. By default, this component is a Tkinter.Label.</p>
173
174
175</dd></dl>
176</dd>
177<dt> <h3>Dynamic components</h3></dt><dd>
178<p>
179 Button components are created dynamically by the <code>add()</code>
180 method. The default type of the buttons depends on the value
181 of the <strong>buttontype</strong> option.</p>
182
183<p> Button components are created with a component group of <strong>Button</strong>.</p>
184<p> </p>
185
186
187
188</dd>
189<a name=methods></a>
190<dt> <h3>Methods</h3></dt><dd>
191Only methods specific to this megawidget are described below.
192For a description of its inherited methods, see the
193manual for its base class
194<strong><a href="MegaWidget.html#methods">Pmw.MegaWidget</a></strong>.
195<p></p>
196<a name=method.add></a>
197<dl><dt> <strong>add</strong>(<em>componentName</em>, **<em>kw</em>)</dt><dd>
198Add a button to the end of the radio select as a component
199 named <em>componentName</em>. with a default type as specified by
200 <strong>buttontype</strong>. Any keyword arguments present (except <strong>command</strong>)
201 will be passed to the constructor when creating the button. If
202 the <strong>text</strong> keyword argument is not given, the <strong>text</strong> option of the
203 button defaults to <em>componentName</em>. The method returns the
204 component widget.</p>
205
206
207</dd></dl>
208<a name=method.button></a>
209<dl><dt> <strong>button</strong>(<em>buttonIndex</em>)</dt><dd>
210Return the button specified by <em>buttonIndex</em>, which may have any
211 of the forms accepted by the <code>index()</code> method.</p>
212
213
214</dd></dl>
215<a name=method.deleteall></a>
216<dl><dt> <strong>deleteall</strong>()</dt><dd>
217Delete all buttons and clear the current selection.</p>
218
219
220</dd></dl>
221<a name=method.getcurselection></a>
222<dl><dt> <strong>getcurselection</strong>()</dt><dd>
223Same as <code>getvalue()</code> method.</p>
224
225
226</dd></dl>
227<a name=method.getvalue></a>
228<dl><dt> <strong>getvalue</strong>()</dt><dd>
229In single selection mode, return the name of the currently
230 selected button, or <strong>None</strong> if no buttons have been selected yet.</p>
231<p> In multiple selection mode, return a list of the names of the
232 currently selected buttons.</p>
233
234
235
236</dd></dl>
237<a name=method.index></a>
238<dl><dt> <strong>index</strong>(<em>index</em>)</dt><dd>
239Return the numerical index of the button corresponding to <em>index</em>.
240 This may be specified in any of the following forms:</p>
241<dl><dt><em>name</em></dt><dd>Specifies the button named <em>name</em>.<p></p>
242
243</dd>
244<dt><em>number</em></dt><dd>Specifies the button numerically, where <strong>0</strong> corresponds to
245 the left (or top) button.<p></p>
246
247</dd>
248<dt><strong>Pmw.END</strong></dt><dd>Specifies the right (or bottom) button.<p></p>
249
250</dd></dl>
251
252
253</dd></dl>
254<a name=method.invoke></a>
255<dl><dt> <strong>invoke</strong>(<em>index</em>)</dt><dd>
256Calling this method is the same as clicking on the button
257 specified by <em>index</em>: the buttons are displayed selected or
258 deselected according to the selection mode and <strong>command</strong> is
259 called. <em>index</em> may have any of the forms accepted by the
260 <code>index()</code> method. The value returned by <strong>command</strong> is returned.</p>
261
262
263</dd></dl>
264<a name=method.numbuttons></a>
265<dl><dt> <strong>numbuttons</strong>()</dt><dd>
266Return the number of buttons in the radio select.</p>
267
268
269</dd></dl>
270<a name=method.setvalue></a>
271<dl><dt> <strong>setvalue</strong>(<em>textOrList</em>)</dt><dd>
272Set the current selection for the radio select to <em>textOrList</em>,
273 but do not invoke <strong>command</strong>.</p>
274<p> In single selection mode, select only the button specified by the
275 string <em>textOrList</em>.</p>
276
277<p> In multiple selection mode, select only the buttons specified by
278 the list <em>textOrList</em>.</p>
279
280
281
282</dd></dl>
283</dd>
284<dt> <h3>Example</h3></dt><dd>
285The image at the top of this manual is a snapshot
286of the window (or part of the window) produced
287by the following code.<p></p>
288<pre>
289class Demo:
290 def __init__(self, parent):
291 # Create and pack a horizontal RadioSelect widget.
292 horiz = Pmw.RadioSelect(parent,
293 labelpos = 'w',
294 command = self.callback,
295 label_text = 'Horizontal',
296 frame_borderwidth = 2,
297 frame_relief = 'ridge'
298 )
299 horiz.pack(fill = 'x', padx = 10, pady = 10)
300
301 # Add some buttons to the horizontal RadioSelect.
302 for text in ('Fruit', 'Vegetables', 'Cereals', 'Legumes'):
303 horiz.add(text)
304 horiz.invoke('Cereals')
305
306 # Create and pack a multiple selection RadioSelect widget.
307 self.multiple = Pmw.RadioSelect(parent,
308 labelpos = 'w',
309 command = self.multcallback,
310 label_text = 'Multiple\nselection',
311 frame_borderwidth = 2,
312 frame_relief = 'ridge',
313 selectmode = 'multiple',
314 )
315 self.multiple.pack(fill = 'x', padx = 10)
316
317 # Add some buttons to the multiple selection RadioSelect.
318 for text in ('Apricots', 'Eggplant', 'Rice', 'Lentils'):
319 self.multiple.add(text)
320 self.multiple.invoke('Rice')
321
322 # Create and pack a vertical RadioSelect widget, with checkbuttons.
323 self.checkbuttons = Pmw.RadioSelect(parent,
324 buttontype = 'checkbutton',
325 orient = 'vertical',
326 labelpos = 'w',
327 command = self.checkbuttoncallback,
328 label_text = 'Vertical,\nusing\ncheckbuttons',
329 hull_borderwidth = 2,
330 hull_relief = 'ridge',
331 )
332 self.checkbuttons.pack(side = 'left', expand = 1, padx = 10, pady = 10)
333
334 # Add some buttons to the checkbutton RadioSelect.
335 for text in ('Male', 'Female'):
336 self.checkbuttons.add(text)
337 self.checkbuttons.invoke('Male')
338 self.checkbuttons.invoke('Female')
339
340 # Create and pack a RadioSelect widget, with radiobuttons.
341 radiobuttons = Pmw.RadioSelect(parent,
342 buttontype = 'radiobutton',
343 orient = 'vertical',
344 labelpos = 'w',
345 command = self.callback,
346 label_text = 'Vertical,\nusing\nradiobuttons',
347 hull_borderwidth = 2,
348 hull_relief = 'ridge',
349 )
350 radiobuttons.pack(side = 'left', expand = 1, padx = 10, pady = 10)
351
352 # Add some buttons to the radiobutton RadioSelect.
353 for text in ('Male', 'Female', 'Both', 'Neither'):
354 radiobuttons.add(text)
355 radiobuttons.invoke('Both')
356
357 def callback(self, tag):
358 # This is called whenever the user clicks on a button
359 # in a single select RadioSelect widget.
360 print 'Button', tag, 'was pressed.'
361
362 def multcallback(self, tag, state):
363 # This is called whenever the user clicks on a button
364 # in the multiple select RadioSelect widget.
365 if state:
366 action = 'pressed.'
367 else:
368 action = 'released.'
369
370 print 'Button', tag, 'was', action, \
371 'Selection:', self.multiple.getcurselection()
372
373 def checkbuttoncallback(self, tag, state):
374 # This is called whenever the user clicks on a button
375 # in the checkbutton RadioSelect widget.
376 if state:
377 action = 'pressed.'
378 else:
379 action = 'released.'
380
381 print 'Button', tag, 'was', action, \
382 'Selection:', self.checkbuttons.getcurselection()
383
384
385</pre>
386</dd>
387</dl>
388
389 <center><P ALIGN="CENTER">
390 <IMG SRC = blue_line.gif ALT = "" WIDTH=320 HEIGHT=5>
391 </p></center>
392
393
394 <font size=-1>
395 <center><P ALIGN="CENTER">
396 Pmw 1.2 -
397 5 Aug 2003
398 - <a href="index.html">Home</a>
399 <br>Manual page last reviewed: 6 June 2002
400 </p></center>
401 </font>
402
403 </body>
404 </html>
405