Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / src / nas,5.n2.os.2 / lib / python / lib / python2.4 / site-packages / Pmw / Pmw_1_2 / doc / Counter.html
CommitLineData
86530b38
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.Counter 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.Counter</h1>
13
14<center><IMG SRC=Counter.gif ALT="" WIDTH=400 HEIGHT=110></center>
15<dl>
16<dt> <h3>Name</h3></dt><dd>
17<p>Pmw.Counter() -
18 entry field with up and down arrow buttons
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 counter contains an entry field and two arrow buttons to
29 increment and decrement the value in the entry field. Standard
30 counting types include numbers, times and dates. A user defined
31 counting function may also be supplied for specialised counting.
32 Counting can be used in combination with the entry field's
33 validation. The components may be laid out horizontally or
34 vertically.</p>
35
36<p> Each time an arrow button is pressed the value displayed in the
37 entry field is incremented or decremented by the value of the
38 <strong>increment</strong> option. If the new value is invalid (according to the
39 entry field's <strong>validate</strong> option, perhaps due to exceeding minimum
40 or maximum limits), the old value is restored.</p>
41
42<p> When an arrow button is pressed and the value displayed is not an
43 exact multiple of the <strong>increment</strong>, it is "truncated" up or down to
44 the nearest increment.</p>
45
46<p></p>
47
48
49</dd>
50<dt> <h3>Options</h3></dt><dd>
51Options for this megawidget and its base
52classes are described below.<p></p>
53<a name=option.autorepeat></a>
54<dl><dt> <strong>autorepeat
55</strong></dt><dd>
56If true, the counter will continue to count up or down while an
57 arrow button is held pressed down. The default is <strong>1</strong>.</p>
58
59
60</dd></dl>
61<a name=option.buttonaspect></a>
62<dl><dt> <strong>buttonaspect
63</strong></dt><dd>
64Initialisation option. Specifies the width of the arrow buttons as a proportion of their
65 height. Values less than <strong>1.0</strong> will produce thin arrow buttons.
66 Values greater than <strong>1.0</strong> will produce fat arrow buttons. The default is <strong>1.0</strong>.</p>
67
68
69</dd></dl>
70<a name=option.datatype></a>
71<dl><dt> <strong>datatype
72</strong></dt><dd>
73Specifies how the counter should count up and down.</p>
74<p> The most general way to specify the <strong>datatype</strong> option is as a
75 dictionary. The kind of counting is specified by the <strong>'counter'</strong>
76 dictionary field, which may be either a function or the name of
77 one of the standard counters described below. If the dictionary
78 does not have a <strong>'counter'</strong> field, the field defaults to
79 <strong>'numeric'</strong>.</p>
80
81<p> Any other fields in the dictionary are passed on to the <em>counter</em>
82 function as keyword arguments.</p>
83
84<p> If <strong>datatype</strong> is not a dictionary, then it is equivalent to
85 specifying it as a dictionary with a single <strong>'counter'</strong> field.
86 For example, <code>datatype = 'real'</code> is equivalent to
87 <code>datatype = {'counter' : 'real'}</code>.</p>
88
89<p> The standard counters are:</p>
90
91<dl><dt><strong>'numeric'</strong></dt><dd>An integer number, as accepted by <code>string.atol()</code>.<p></p>
92
93</dd>
94<dt><strong>'integer'</strong></dt><dd>Same as <strong>'numeric'</strong>.<p></p>
95
96</dd>
97<dt><strong>'real'</strong></dt><dd>A real number, as accepted by <code>string.atof()</code>. This
98 counter accepts a <strong>'separator'</strong> argument, which specifies
99 the character used to represent the decimal point. The
100 default <strong>'separator'</strong> is <strong>'.'</strong>.<p></p>
101
102</dd>
103<dt><strong>'time'</strong></dt><dd>A time specification, as accepted by
104 <code>Pmw.timestringtoseconds()</code>. This counter accepts a
105 <strong>'separator'</strong> argument, which specifies the character used to
106 separate the time fields. The default separator is <strong>':'</strong>.
107 This counter also accepts a <strong>'time24'</strong> argument. If this is
108 true, the time value is converted to a value between
109 <strong>'00:00:00'</strong> and <strong>'23:59:59'</strong>. The default is false.<p></p>
110
111</dd>
112<dt><strong>'date'</strong></dt><dd>A date specification, as accepted by
113 <code>Pmw.datestringtojdn()</code>. This counter accepts a <strong>'separator'</strong>
114 argument, which specifies the character used to separate the
115 three date fields. The default is <strong>'/'</strong>. This counter also
116 accepts a <strong>'format'</strong> argument, which is passed to
117 <code>Pmw.datestringtojdn()</code> to specify the desired ordering of the
118 fields. The default is <strong>'ymd'</strong>.
119 This counter also accepts a <strong>'yyyy'</strong> argument. If this is
120 false, the year field will be displayed as the year within the
121 century, otherwise it will be fully displayed. In both cases
122 it will be displayed with at least 2 digits, using leading
123 zeroes. The default is false.<p></p>
124
125</dd></dl>
126<p> If the <strong>'counter'</strong> dictionary field is a function, then it will be
127 called whenever the counter is to be incremented or decremented.
128 The function is called with at least three arguments, the first
129 three being (<em>text</em>, <em>factor</em>, <em>increment</em>), where <em>text</em> is the
130 current contents of the entry field, <em>factor</em> is <strong>1</strong> when
131 incrementing or <strong>-1</strong> when decrementing, and <em>increment</em> is the
132 value of the <strong>increment</strong> megawidget option.</p>
133
134<p> The other arguments are keyword arguments made up of the fields of
135 the <strong>datatype</strong> dictionary (excluding the <strong>'counter'</strong> field).</p>
136
137<p> The <em>counter</em> function should return a string representing the
138 incremented or decremented value. It should raise a
139 <strong>ValueError</strong> exception if the <em>text</em> is invalid. In this case the
140 bell is rung and the entry text is not changed.</p>
141
142<p> The default for <strong>datatype</strong> is <strong>numeric</strong>.</p>
143
144
145
146</dd></dl>
147<a name=option.increment></a>
148<dl><dt> <strong>increment
149</strong></dt><dd>
150Specifies how many units should be added or subtracted when the
151 counter is incremented or decremented. If the currently displayed
152 value is not a multiple of <strong>increment</strong>, the value is changed to
153 the next multiple greater or less than the current value.</p>
154<p> For the number datatypes, the value of <strong>increment</strong> is a number.
155 For the <strong>'time'</strong> datatype, the value is in seconds. For the
156 <strong>'date'</strong> datatype, the value is in days. The default is <strong>1</strong>.</p>
157
158
159
160</dd></dl>
161<a name=option.initwait></a>
162<dl><dt> <strong>initwait
163</strong></dt><dd>
164Specifies the initial delay (in milliseconds) before a depressed
165 arrow button automatically starts to repeat counting. The default is <strong>300</strong>.</p>
166
167
168</dd></dl>
169<a name=option.labelmargin></a>
170<dl><dt> <strong>labelmargin
171</strong></dt><dd>
172Initialisation option. If the <strong>labelpos</strong> option is not <strong>None</strong>, this specifies the
173 distance between the <strong>label</strong> component and the rest of the
174 megawidget. The default is <strong>0</strong>.</p>
175
176
177</dd></dl>
178<a name=option.labelpos></a>
179<dl><dt> <strong>labelpos
180</strong></dt><dd>
181Initialisation option. Specifies where to place the <strong>label</strong> component. If not
182 <strong>None</strong>, it should be a concatenation of one or two of the
183 letters <strong>'n'</strong>, <strong>'s'</strong>, <strong>'e'</strong> and <strong>'w'</strong>. The first letter
184 specifies on which side of the megawidget to place the label.
185 If a second letter is specified, it indicates where on that
186 side to place the label. For example, if <strong>labelpos</strong> is <strong>'w'</strong>,
187 the label is placed in the center of the left hand side; if
188 it is <strong>'wn'</strong>, the label is placed at the top of the left
189 hand side; if it is <strong>'ws'</strong>, the label is placed at the
190 bottom of the left hand side.</p>
191<p> If <strong>None</strong>, a label component is not created. The default is <strong>None</strong>.</p>
192
193
194
195</dd></dl>
196<a name=option.orient></a>
197<dl><dt> <strong>orient
198</strong></dt><dd>
199Initialisation option. Specifies whether the arrow buttons should appear to the left and
200 right of the entry field (<strong>'horizontal'</strong>) or above and below
201 (<strong>'vertical'</strong>). The default is <strong>'horizontal'</strong>.</p>
202
203
204</dd></dl>
205<a name=option.padx></a>
206<dl><dt> <strong>padx
207</strong></dt><dd>
208Initialisation option. Specifies a padding distance to leave around the arrow buttons in
209 the x direction. The default is <strong>0</strong>.</p>
210
211
212</dd></dl>
213<a name=option.pady></a>
214<dl><dt> <strong>pady
215</strong></dt><dd>
216Initialisation option. Specifies a padding distance to leave around the arrow buttons in
217 the y direction. The default is <strong>0</strong>.</p>
218
219
220</dd></dl>
221<a name=option.repeatrate></a>
222<dl><dt> <strong>repeatrate
223</strong></dt><dd>
224Specifies the delay (in milliseconds) between automatic counts
225 while an arrow button is held pressed down. The default is <strong>50</strong>.</p>
226
227
228</dd></dl>
229<a name=option.sticky></a>
230<dl><dt> <strong>sticky
231</strong></dt><dd>
232Initialisation option. The default is <strong>'ew'</strong>.</p>
233
234
235</dd></dl>
236</dd>
237<dt> <h3>Components</h3></dt><dd>
238Components created by this megawidget and its base
239classes are described below.<p></p>
240<a name=component.downarrow></a>
241<dl><dt> <strong>downarrow
242</strong></dt><dd>
243The arrow button used for decrementing the counter. Depending on
244 the value of <strong>orient</strong>, it will appear on the left or below the
245 entry field. By default, this component is a Tkinter.Canvas. Its component group is <strong>Arrow</strong>.</p>
246
247
248</dd></dl>
249<a name=component.entryfield></a>
250<dl><dt> <strong>entryfield
251</strong></dt><dd>
252The entry field widget where the text is entered, displayed and
253 validated. By default, this component is a <a href="EntryField.html">Pmw.EntryField</a>.</p>
254
255
256</dd></dl>
257<a name=component.frame></a>
258<dl><dt> <strong>frame
259</strong></dt><dd>
260If the <strong>label</strong> component has been created (that is, the <strong>labelpos</strong>
261 option is not <strong>None</strong>), the <strong>frame</strong> component is created to act as
262 the container of the entry field and arrow buttons. If there is
263 no <strong>label</strong> component, then no <strong>frame</strong> component is created and the
264 <strong>hull</strong> component acts as the container. In either case the border
265 around the container of the entry field and arrow buttons will be
266 raised (but not around the label). By default, this component is a Tkinter.Frame.</p>
267
268
269</dd></dl>
270<a name=component.hull></a>
271<dl><dt> <strong>hull
272</strong></dt><dd>
273This acts as the body for the entire megawidget. Other components
274 are created as children of the hull to further specialise this
275 class. By default, this component is a Tkinter.Frame.</p>
276
277
278</dd></dl>
279<a name=component.label></a>
280<dl><dt> <strong>label
281</strong></dt><dd>
282If the <strong>labelpos</strong> option is not <strong>None</strong>, this component is
283 created as a text label for the megawidget. See the
284 <strong>labelpos</strong> option for details. Note that to set, for example,
285 the <strong>text</strong> option of the label, you need to use the <strong>label_text</strong>
286 component option. By default, this component is a Tkinter.Label.</p>
287
288
289</dd></dl>
290<a name=component.uparrow></a>
291<dl><dt> <strong>uparrow
292</strong></dt><dd>
293The arrow button used for incrementing the counter. Depending on
294 the value of <strong>orient</strong>, it will appear on the right or above the
295 entry field. By default, this component is a Tkinter.Canvas. Its component group is <strong>Arrow</strong>.</p>
296
297
298</dd></dl>
299</dd>
300<dt> <h3>Component aliases</h3></dt><dd>
301Sub-components of components of this megawidget
302may be accessed via the following aliases.<p></p>
303<dl><dt> <strong>entry
304</strong></dt><dd>
305Alias for <strong>entryfield_entry</strong>.
306</dd></dl>
307</dd>
308<a name=methods></a>
309<dt> <h3>Methods</h3></dt><dd>
310Only methods specific to this megawidget are described below.
311For a description of its inherited methods, see the
312manual for its base class
313<strong><a href="MegaWidget.html#methods">Pmw.MegaWidget</a></strong>.
314In addition, methods from the
315<strong><a href="EntryField.html#methods">Pmw.EntryField</a></strong> class
316are forwarded by this megawidget to the
317<strong>entryfield</strong> component.
318<p></p>
319<a name=method.decrement></a>
320<dl><dt> <strong>decrement</strong>()</dt><dd>
321Decrement the counter once, as if the down arrow had been pressed.</p>
322
323
324</dd></dl>
325<a name=method.increment></a>
326<dl><dt> <strong>increment</strong>()</dt><dd>
327Increment the counter once, as if the up arrow had been pressed.</p>
328
329
330</dd></dl>
331</dd>
332<dt> <h3>Example</h3></dt><dd>
333The image at the top of this manual is a snapshot
334of the window (or part of the window) produced
335by the following code.<p></p>
336<pre>
337class Demo:
338 def __init__(self, parent):
339 # Need to use long ints here because on the Macintosh the maximum size
340 # of an integer is smaller than the value returned by time.time().
341 now = (long(time.time()) / 300) * 300
342
343 # Create the Counters.
344 self._date = Pmw.Counter(parent,
345 labelpos = 'w',
346 label_text = 'Date (4-digit year):',
347 entryfield_value =
348 time.strftime('%d/%m/%Y', time.localtime(now)),
349 entryfield_command = self.execute,
350 entryfield_validate = {'validator' : 'date', 'format' : 'dmy'},
351 datatype = {'counter' : 'date', 'format' : 'dmy', 'yyyy' : 1})
352
353 self._isodate = Pmw.Counter(parent,
354 labelpos = 'w',
355 label_text = 'ISO-Date (4-digit year):',
356 entryfield_value =
357 time.strftime('%Y-%m-%d', time.localtime(now)),
358 entryfield_command = self.execute,
359 entryfield_validate = {'validator' : 'date', 'format' : 'ymd',
360 'separator' : '-' },
361 datatype = {'counter' : 'date', 'format' : 'ymd', 'yyyy' : 1,
362 'separator' : '-' })
363
364 self._time = Pmw.Counter(parent,
365 labelpos = 'w',
366 label_text = 'Time:',
367 entryfield_value =
368 time.strftime('%H:%M:%S', time.localtime(now)),
369 entryfield_validate = {'validator' : 'time',
370 'min' : '00:00:00', 'max' : '23:59:59',
371 'minstrict' : 0, 'maxstrict' : 0},
372 datatype = {'counter' : 'time', 'time24' : 1},
373 increment=5*60)
374 self._real = Pmw.Counter(parent,
375 labelpos = 'w',
376 label_text = 'Real (with comma)\nand extra\nlabel lines:',
377 label_justify = 'left',
378 entryfield_value = '1,5',
379 datatype = {'counter' : 'real', 'separator' : ','},
380 entryfield_validate = {'validator' : 'real',
381 'min' : '-2,0', 'max' : '5,0',
382 'separator' : ','},
383 increment = 0.1)
384 self._custom = Pmw.Counter(parent,
385 labelpos = 'w',
386 label_text = 'Custom:',
387 entryfield_value = specialword[:4],
388 datatype = _custom_counter,
389 entryfield_validate = _custom_validate)
390 self._int = Pmw.Counter(parent,
391 labelpos = 'w',
392 label_text = 'Vertical integer:',
393 orient = 'vertical',
394 entry_width = 2,
395 entryfield_value = 50,
396 entryfield_validate = {'validator' : 'integer',
397 'min' : 0, 'max' : 99}
398 )
399
400 counters = (self._date, self._isodate, self._time, self._real,
401 self._custom)
402 Pmw.alignlabels(counters)
403
404 # Pack them all.
405 for counter in counters:
406 counter.pack(fill='both', expand=1, padx=10, pady=5)
407 self._int.pack(padx=10, pady=5)
408
409 def execute(self):
410 print 'Return pressed, value is', self._date.get()
411
412specialword = 'Monti Python ik den Holie Grailen (Bok)'
413
414def _custom_validate(text):
415 if string.find(specialword, text) == 0:
416 return 1
417 else:
418 return -1
419
420def _custom_counter(text, factor, increment):
421 # increment is ignored here.
422 if string.find(specialword, text) == 0:
423 length = len(text)
424 if factor == 1:
425 if length &gt;= len(specialword):
426 raise ValueError, 'maximum length reached'
427 return specialword[:length + 1]
428 else:
429 if length == 0:
430 raise ValueError, 'empty string'
431 return specialword[:length - 1]
432 else:
433 raise ValueError, 'bad string ' + text
434
435</pre>
436</dd>
437</dl>
438
439 <center><P ALIGN="CENTER">
440 <IMG SRC = blue_line.gif ALT = "" WIDTH=320 HEIGHT=5>
441 </p></center>
442
443
444 <font size=-1>
445 <center><P ALIGN="CENTER">
446 Pmw 1.2 -
447 5 Aug 2003
448 - <a href="index.html">Home</a>
449 <br>Manual page last reviewed: 24 May 1998
450 </p></center>
451 </font>
452
453 </body>
454 </html>
455