File: PmwCounter.py.html

package info (click to toggle)
python-pmw 0.6.2-0.1
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 1,652 kB
  • ctags: 2,716
  • sloc: python: 10,720; makefile: 44; sh: 24
file content (535 lines) | stat: -rw-r--r-- 22,138 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
<!DOCTYPE HTML PUBLIC "-//Netscape_Microsoft//DTD HTML 3.0//EN">
<HTML>

<!-- This file generated using the Python HTMLgen module. -->
<HEAD>
  <META NAME="GENERATOR" CONTENT="HTMLgen 1.1">
        <TITLE>PmwCounter.py</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<PRE>
import string
import sys
import Tkinter
import Pmw

<STRONG>def _changeNumber</STRONG>(text, factor, increment, min, max):
  value = string.atoi(text)

  if factor > 0:
    if max != <FONT COLOR="#009900">''</FONT> and value >= max:
      raise ValueError
    value = (value / increment) * increment + increment
  else:
    if min != <FONT COLOR="#009900">''</FONT> and value <= min:
      raise ValueError
    value = ((value - 1) / increment) * increment

  if min != <FONT COLOR="#009900">''</FONT> and value < min:
    value = min
  if max != <FONT COLOR="#009900">''</FONT> and value > max:
    value = max

  return str(value)

<STRONG>def _changeReal</STRONG>(text, factor, increment, min, max):
  value = string.atof(text)

  if factor > 0:
    if max != <FONT COLOR="#009900">''</FONT> and value >= max:
      raise ValueError
  else:
    if min != <FONT COLOR="#009900">''</FONT> and value <= min:
      raise ValueError

  <FONT COLOR="#DD0000"># Compare reals using str() to avoid problems caused by binary</FONT>
  <FONT COLOR="#DD0000"># numbers being only approximations to decimal numbers.</FONT>
  div = int(value / increment)
  text = str(value)
  if text == str(div * increment) or text == str((div + 1) * increment):
    value = value + factor * increment
  elif factor > 0:
    value = (div + 1) * increment
  else:
    value = div * increment

  if min != <FONT COLOR="#009900">''</FONT> and value < min:
    value = min
  if max != <FONT COLOR="#009900">''</FONT> and value > max:
    value = max

  return str(value)

<STRONG>def _changeDate_formatted</STRONG>(format, value, factor, increment, min, max, yyyy):
  jdn = datestringtojdn(value, format) + factor * increment
  if min != <FONT COLOR="#009900">''</FONT>:
    min = datestringtojdn(min, format)
    if jdn < min:
      jdn = min
  if max != <FONT COLOR="#009900">''</FONT>:
    max = datestringtojdn(max, format)
    if jdn > max:
      jdn = max

  y, m, d = jdntoymd(jdn)
  result = <FONT COLOR="#009900">''</FONT>
  for index in range(3):
    if index > 0:
      result = result + <FONT COLOR="#009900">'/'</FONT>
    f = format[index]
    if f == <FONT COLOR="#009900">'y'</FONT>:
      if yyyy:
        result = result + <FONT COLOR="#009900">'%02d'</FONT> % y
      else:
        result = result + <FONT COLOR="#009900">'%02d'</FONT> % (y % 100)
    elif f == <FONT COLOR="#009900">'m'</FONT>:
      result = result + <FONT COLOR="#009900">'%02d'</FONT> % m
    elif f == <FONT COLOR="#009900">'d'</FONT>:
      result = result + <FONT COLOR="#009900">'%02d'</FONT> % d

  return result

<STRONG>def _changeDate_dmy</STRONG>(value, factor, increment, min, max):
  return _changeDate_formatted(<FONT COLOR="#009900">'dmy'</FONT>, value, factor, increment, min, max, 0)

<STRONG>def _changeDate_mdy</STRONG>(value, factor, increment, min, max):
  return _changeDate_formatted(<FONT COLOR="#009900">'mdy'</FONT>, value, factor, increment, min, max, 0)

<STRONG>def _changeDate_ymd</STRONG>(value, factor, increment, min, max):
  return _changeDate_formatted(<FONT COLOR="#009900">'ymd'</FONT>, value, factor, increment, min, max, 0)

<STRONG>def _changeDate_dmy4</STRONG>(value, factor, increment, min, max):
  return _changeDate_formatted(<FONT COLOR="#009900">'dmy'</FONT>, value, factor, increment, min, max, 1)

<STRONG>def _changeDate_mdy4</STRONG>(value, factor, increment, min, max):
  return _changeDate_formatted(<FONT COLOR="#009900">'mdy'</FONT>, value, factor, increment, min, max, 1)

<STRONG>def _changeDate_y4md</STRONG>(value, factor, increment, min, max):
  return _changeDate_formatted(<FONT COLOR="#009900">'ymd'</FONT>, value, factor, increment, min, max, 1)

<STRONG>def _changeTime24</STRONG>(value, factor, increment, min, max):
    return _changeTimeN(value, factor, increment, min, max, 1)

_SECSPERDAY = 24 * 60 * 60
<STRONG>def _changeTimeN</STRONG>(value, factor, increment, min, max, time24 = 0):
  unixTime = timestringtoseconds(value)
  if factor > 0:
    chunks = unixTime / increment + 1
  else:
    chunks = (unixTime - 1) / increment
  unixTime = chunks * increment
  if time24:
      while unixTime < 0:
	  unixTime = unixTime + _SECSPERDAY
      while unixTime >= _SECSPERDAY:
	  unixTime = unixTime - _SECSPERDAY
  if min != <FONT COLOR="#009900">''</FONT>:
    min = timestringtoseconds(min)
    if unixTime < min:
      unixTime = min
  if max != <FONT COLOR="#009900">''</FONT>:
    max = timestringtoseconds(max)
    if unixTime > max:
      unixTime = max
  if unixTime < 0:
    unixTime = -unixTime
    sign = <FONT COLOR="#009900">'-'</FONT>
  else:
    sign = <FONT COLOR="#009900">''</FONT>
  secs = unixTime % 60
  unixTime = unixTime / 60
  mins = unixTime % 60
  hours = unixTime / 60
  return <FONT COLOR="#009900">'%s%02d:%02d:%02d'</FONT> % (sign, hours, mins, secs)

<STRONG>def timestringtoseconds</STRONG>(text):
  inputList = string.split(text, <FONT COLOR="#009900">':'</FONT>)
  if len(inputList) != 3:
    raise TypeError, <FONT COLOR="#009900">'invalid value: '</FONT> + text

  if inputList[0][0] == <FONT COLOR="#009900">'-'</FONT>:
    inputList[0] = inputList[0][1:]
    sign = -1
  else:
    sign = 1
  hour = string.atoi(inputList[0])
  minute = string.atoi(inputList[1])
  second = string.atoi(inputList[2])
  return sign * (hour * 60 * 60 + minute * 60 + second)

_year_pivot = 50
_century = 2000

<STRONG>def setyearpivot</STRONG>(pivot, century = None):
    global _year_pivot
    _year_pivot = pivot
    if century is not None:
	global _century
	_century = century

<STRONG>def datestringtojdn</STRONG>(text, format):
  inputList = string.split(text, <FONT COLOR="#009900">'/'</FONT>)
  if len(inputList) != 3:
    raise TypeError, <FONT COLOR="#009900">'invalid value: '</FONT> + text

  if format not in (<FONT COLOR="#009900">'dmy'</FONT>, <FONT COLOR="#009900">'mdy'</FONT>, <FONT COLOR="#009900">'ymd'</FONT>):
    raise TypeError, <FONT COLOR="#009900">'invalid format: '</FONT> + format
    
  formatList = list(format)
  day = string.atoi(inputList[formatList.index(<FONT COLOR="#009900">'d'</FONT>)])
  month = string.atoi(inputList[formatList.index(<FONT COLOR="#009900">'m'</FONT>)])
  year = string.atoi(inputList[formatList.index(<FONT COLOR="#009900">'y'</FONT>)])

  if _year_pivot is not None:
    if year >= 0 and year < 100:
      if year <= _year_pivot:
	year = year + _century
      else:
	year = year + _century - 100

  return ymdtojdn(year, month, day)

<STRONG>def _cdiv</STRONG>(a, b):
    <FONT COLOR="#DD0000"># Return a / b as calculated by most C language implementations,</FONT>
    <FONT COLOR="#DD0000"># assuming both a and b are integers.</FONT>

    if a * b > 0:
	return a / b
    else:
	return -(abs(a) / abs(b))

<STRONG>def ymdtojdn</STRONG>(y, m, d, julian = -1, papal = 1):

    <FONT COLOR="#DD0000"># set Julian flag if auto set</FONT>
    if julian < 0:
	if papal:                          <FONT COLOR="#DD0000"># Pope Gregory XIII's decree</FONT>
	    lastJulianDate = 15821004L     <FONT COLOR="#DD0000"># last day to use Julian calendar</FONT>
	else:                              <FONT COLOR="#DD0000"># British-American usage</FONT>
	    lastJulianDate = 17520902L     <FONT COLOR="#DD0000"># last day to use Julian calendar</FONT>

	julian = ((y * 100L) + m) * 100 + d  <=  lastJulianDate

    if y < 0:
	<FONT COLOR="#DD0000"># Adjust BC year</FONT>
	y = y + 1

    if julian:
	return 367L * y - _cdiv(7 * (y + 5001L + _cdiv((m - 9), 7)), 4) + \
	    _cdiv(275 * m, 9) + d + 1729777L
    else:
	return (d - 32076L) + \
	    _cdiv(1461L * (y + 4800L + _cdiv((m - 14), 12)), 4) + \
	    _cdiv(367 * (m - 2 - _cdiv((m - 14), 12) * 12), 12) - \
	    _cdiv((3 * _cdiv((y + 4900L + _cdiv((m - 14), 12)), 100)), 4) + \
	    1            <FONT COLOR="#DD0000"># correction by rdg</FONT>

<STRONG>def jdntoymd</STRONG>(jdn, julian = -1, papal = 1):

    <FONT COLOR="#DD0000"># set Julian flag if auto set</FONT>
    if julian < 0:
	if papal:                          <FONT COLOR="#DD0000"># Pope Gregory XIII's decree</FONT>
	    lastJulianJdn = 2299160L       <FONT COLOR="#DD0000"># last jdn to use Julian calendar</FONT>
	else:                              <FONT COLOR="#DD0000"># British-American usage</FONT>
	    lastJulianJdn = 2361221L       <FONT COLOR="#DD0000"># last jdn to use Julian calendar</FONT>

	julian = (jdn <= lastJulianJdn);

    x = jdn + 68569L
    if julian:
	x = x + 38
	daysPer400Years = 146100L
	fudgedDaysPer4000Years = 1461000L + 1
    else:
	daysPer400Years = 146097L
	fudgedDaysPer4000Years = 1460970L + 31

    z = _cdiv(4 * x, daysPer400Years)
    x = x - _cdiv((daysPer400Years * z + 3), 4)
    y = _cdiv(4000 * (x + 1), fudgedDaysPer4000Years)
    x = x - _cdiv(1461 * y, 4) + 31
    m = _cdiv(80 * x, 2447)
    d = x - _cdiv(2447 * m, 80)
    x = _cdiv(m, 11)
    m = m + 2 - 12 * x
    y = 100 * (z - 49) + y + x

    <FONT COLOR="#DD0000"># Convert from longs to integers.</FONT>
    yy = int(y)
    mm = int(m)
    dd = int(d)

    if yy <= 0:
	<FONT COLOR="#DD0000"># Adjust BC years.</FONT>
	    yy = yy - 1

    return (yy, mm, dd)

<FONT COLOR="#DD0000"># hexadecimal, alphabetic, alphanumeric not implemented</FONT>
_counterCommands = {
    <FONT COLOR="#009900">'numeric'</FONT>   : _changeNumber,      # } integer
    <FONT COLOR="#009900">'integer'</FONT>   : _changeNumber,      # } these two use the same function
    <FONT COLOR="#009900">'real'</FONT>      : _changeReal,        # real number
    <FONT COLOR="#009900">'timeN'</FONT>     : _changeTimeN,       # HH:MM:SS
    <FONT COLOR="#009900">'time24'</FONT>    : _changeTime24,      # HH:MM:SS (wraps around at 23:59:59)
    <FONT COLOR="#009900">'date_dmy'</FONT>  : _changeDate_dmy,    # DD/MM/YY
    <FONT COLOR="#009900">'date_mdy'</FONT>  : _changeDate_mdy,    # MM/DD/YY
    <FONT COLOR="#009900">'date_ymd'</FONT>  : _changeDate_ymd,    # YY/MM/DD
    <FONT COLOR="#009900">'date_dmy4'</FONT> : _changeDate_dmy4,   # DD/MM/YYYY
    <FONT COLOR="#009900">'date_mdy4'</FONT> : _changeDate_mdy4,   # MM/DD/YYYY
    <FONT COLOR="#009900">'date_y4md'</FONT> : _changeDate_y4md,   # YYYY/MM/DD
}

<STRONG><FONT COLOR="#CC6600">class Counter</FONT></STRONG>(Pmw.MegaWidget):
    <FONT COLOR="#DD0000"># Up-down counter</FONT>

    <FONT COLOR="#DD0000"># A Counter is a single-line entry widget with Up and Down arrows</FONT>
    <FONT COLOR="#DD0000"># which increment and decrement the value in the entry.  By</FONT>
    <FONT COLOR="#DD0000"># default, may be used for entering dates, times, numbers.  User</FONT>
    <FONT COLOR="#DD0000"># defined functions may be specified for specialised counting.</FONT>

<STRONG>    def __init__</STRONG>(self, parent = None, **kw):

	<FONT COLOR="#DD0000"># Define the megawidget options.</FONT>
	INITOPT = Pmw.INITOPT
	optiondefs = (
	    (<FONT COLOR="#009900">'autorepeat'</FONT>,     1,             INITOPT),
	    (<FONT COLOR="#009900">'buttonaspect'</FONT>,   1.0,           INITOPT),
	    (<FONT COLOR="#009900">'datatype'</FONT>,       <FONT COLOR="#009900">'numeric'</FONT>,     self._datatype),
	    (<FONT COLOR="#009900">'increment'</FONT>,      1,             None),
	    (<FONT COLOR="#009900">'initwait'</FONT>,       300,           INITOPT),
	    (<FONT COLOR="#009900">'labelmargin'</FONT>,    0,             INITOPT),
	    (<FONT COLOR="#009900">'labelpos'</FONT>,       None,          INITOPT),
	    (<FONT COLOR="#009900">'max'</FONT>,            <FONT COLOR="#009900">''</FONT>,            None),
	    (<FONT COLOR="#009900">'min'</FONT>,            <FONT COLOR="#009900">''</FONT>,            None),
	    (<FONT COLOR="#009900">'orient'</FONT>,         <FONT COLOR="#009900">'horizontal'</FONT>,  INITOPT),
	    (<FONT COLOR="#009900">'padx'</FONT>,           0,             INITOPT),
	    (<FONT COLOR="#009900">'pady'</FONT>,           0,             INITOPT),
	    (<FONT COLOR="#009900">'repeatrate'</FONT>,     50,            INITOPT),
	)
	self.defineoptions(kw, optiondefs)

	<FONT COLOR="#DD0000"># Initialise the base class (after defining the options).</FONT>
	Pmw.MegaWidget.__init__(self, parent)

	<FONT COLOR="#DD0000"># Create the components.</FONT>
	interior = self.interior()

	<FONT COLOR="#DD0000"># If there is no label, put the arrows and the entry directly</FONT>
	<FONT COLOR="#DD0000"># into the interior, otherwise create a frame for them.  In</FONT>
	<FONT COLOR="#DD0000"># either case the border around the arrows and the entry will</FONT>
	<FONT COLOR="#DD0000"># be raised (but not around the label).</FONT>
	if self[<FONT COLOR="#009900">'labelpos'</FONT>] is None:
	    frame = interior
	else:
	    frame = self.createcomponent(<FONT COLOR="#009900">'frame'</FONT>,
		    (), None,
		    Tkinter.Frame, (interior,))
	    frame.grid(column=2, row=2, sticky=<FONT COLOR="#009900">'nsew'</FONT>)
	    interior.grid_columnconfigure(2, weight=1)
	    interior.grid_rowconfigure(2, weight=1)

	frame.configure(relief = <FONT COLOR="#009900">'raised'</FONT>, borderwidth = 1)

	<FONT COLOR="#DD0000"># Create the down arrow.</FONT>
	self._downArrowBtn = self.createcomponent(<FONT COLOR="#009900">'downarrow'</FONT>,
		(), <FONT COLOR="#009900">'Arrow'</FONT>,
		Tkinter.Canvas, (frame,),
		width = 16, height = 16, relief = <FONT COLOR="#009900">'raised'</FONT>, borderwidth = 2)

	<FONT COLOR="#DD0000"># Create the entry field.</FONT>
	self._counterEntry = self.createcomponent(<FONT COLOR="#009900">'entryfield'</FONT>,
		((<FONT COLOR="#009900">'entry'</FONT>, <FONT COLOR="#009900">'entryfield_entry'</FONT>),), None,
		Pmw.EntryField, (frame,))

	<FONT COLOR="#DD0000"># Create the up arrow.</FONT>
	self._upArrowBtn = self.createcomponent(<FONT COLOR="#009900">'uparrow'</FONT>,
		(), <FONT COLOR="#009900">'Arrow'</FONT>,
		Tkinter.Canvas, (frame,),
		width = 16, height = 16, relief = <FONT COLOR="#009900">'raised'</FONT>, borderwidth = 2)

	padx = self[<FONT COLOR="#009900">'padx'</FONT>]
	pady = self[<FONT COLOR="#009900">'pady'</FONT>]
	if self[<FONT COLOR="#009900">'orient'</FONT>] == <FONT COLOR="#009900">'horizontal'</FONT>:
	    self._downArrowBtn.grid(column = 0, row = 0)
	    self._counterEntry.grid(column = 1, row = 0, sticky = <FONT COLOR="#009900">'news'</FONT>)
	    self._upArrowBtn.grid(column = 2, row = 0)
	    frame.grid_columnconfigure(1, weight = 1)
	    frame.grid_rowconfigure(0, weight = 1)
	    if Tkinter.TkVersion >= 4.2:
		frame.grid_columnconfigure(0, pad = padx)
		frame.grid_columnconfigure(2, pad = padx)
		frame.grid_rowconfigure(0, pad = pady)
	else:
	    self._upArrowBtn.grid(column = 0, row = 0)
	    self._counterEntry.grid(column = 0, row = 1, sticky = <FONT COLOR="#009900">'news'</FONT>)
	    self._downArrowBtn.grid(column = 0, row = 2)
	    frame.grid_columnconfigure(0, weight = 1)
	    frame.grid_rowconfigure(1, weight = 1)
	    if Tkinter.TkVersion >= 4.2:
		frame.grid_rowconfigure(0, pad = pady)
		frame.grid_rowconfigure(2, pad = pady)
		frame.grid_columnconfigure(0, pad = padx)

	self.createlabel(interior)

	self._upArrowBtn.bind(<FONT COLOR="#009900">'&lt;Configure&gt;'</FONT>, self._drawUpArrow)
	self._upArrowBtn.bind(<FONT COLOR="#009900">'&lt;1&gt;'</FONT>, self._countUp)
	self._upArrowBtn.bind(<FONT COLOR="#009900">'&lt;Any-ButtonRelease-1&gt;'</FONT>, self._stopUp)
	self._downArrowBtn.bind(<FONT COLOR="#009900">'&lt;Configure&gt;'</FONT>, self._drawDownArrow)
	self._downArrowBtn.bind(<FONT COLOR="#009900">'&lt;1&gt;'</FONT>, self._countDown)
	self._downArrowBtn.bind(<FONT COLOR="#009900">'&lt;Any-ButtonRelease-1&gt;'</FONT>, self._stopDown)
	self._counterEntry.bind(<FONT COLOR="#009900">'&lt;Configure&gt;'</FONT>, self._resizeArrow)
	entry = self._counterEntry.component(<FONT COLOR="#009900">'entry'</FONT>)
	entry.bind(<FONT COLOR="#009900">'&lt;Down&gt;'</FONT>, lambda event, s = self: s.decrement())
	entry.bind(<FONT COLOR="#009900">'&lt;Up&gt;'</FONT>, lambda event, s = self: s.increment())

	<FONT COLOR="#DD0000"># Initialise instance variables.</FONT>
	self._flag = <FONT COLOR="#009900">'stopped'</FONT>
	self._timerId = None

	<FONT COLOR="#DD0000"># Check keywords and initialise options.</FONT>
	self.initialiseoptions(Counter)

<STRONG>    def _resizeArrow</STRONG>(self, event):
	for btn in (self._upArrowBtn, self._downArrowBtn):
	    bw = (string.atoi(btn[<FONT COLOR="#009900">'borderwidth'</FONT>]) + \
		    string.atoi(btn[<FONT COLOR="#009900">'highlightthickness'</FONT>]))
	    newHeight = self._counterEntry.winfo_reqheight() - 2 * bw
	    newWidth = newHeight * self[<FONT COLOR="#009900">'buttonaspect'</FONT>]
	    btn.configure(width=newWidth, height=newHeight)
	    self._drawArrow(btn)

<STRONG>    def _drawUpArrow</STRONG>(self, event):
	self._drawArrow(self._upArrowBtn)

<STRONG>    def _drawDownArrow</STRONG>(self, event):
	self._drawArrow(self._downArrowBtn)

<STRONG>    def _drawArrow</STRONG>(self, arrow):
	arrow.delete(<FONT COLOR="#009900">'arrow'</FONT>)

	fg = self._counterEntry.cget(<FONT COLOR="#009900">'entry_foreground'</FONT>)

	bw = (string.atoi(arrow[<FONT COLOR="#009900">'borderwidth'</FONT>]) +
		string.atoi(arrow[<FONT COLOR="#009900">'highlightthickness'</FONT>])) / 2
	h = string.atoi(arrow[<FONT COLOR="#009900">'height'</FONT>]) + 2 * bw
	w =  string.atoi(arrow[<FONT COLOR="#009900">'width'</FONT>]) + 2 * bw

	if arrow == self._downArrowBtn:
	    if self[<FONT COLOR="#009900">'orient'</FONT>] == <FONT COLOR="#009900">'horizontal'</FONT>:
		arrow.create_polygon(
		    0.25 * w + bw, 0.5 * h + bw,
		    0.75 * w + bw, 0.25 * h + bw,
		    0.75 * w + bw, 0.75 * h + bw,
		    fill=fg, tag=<FONT COLOR="#009900">'arrow'</FONT>)
	    else:
		arrow.create_polygon(
		    0.25 * w + bw, 0.25 * h + bw,
		    0.75 * w + bw, 0.25 * h + bw,
		    0.50 * w + bw, 0.75 * h + bw,
		    fill=fg, tag=<FONT COLOR="#009900">'arrow'</FONT>)
	else:
	    if self[<FONT COLOR="#009900">'orient'</FONT>] == <FONT COLOR="#009900">'horizontal'</FONT>:
		arrow.create_polygon(
		    0.75 * w + bw, 0.5 * h + bw,
		    0.25 * w + bw, 0.25 * h + bw,
		    0.25 * w + bw, 0.75 * h + bw,
		    fill=fg, tag=<FONT COLOR="#009900">'arrow'</FONT>)
	    else:
		arrow.create_polygon(
		    0.5  * w + bw, 0.25 * h + bw,
		    0.25 * w + bw, 0.75 * h + bw,
		    0.75 * w + bw, 0.75 * h + bw,
		    fill=fg, tag=<FONT COLOR="#009900">'arrow'</FONT>)

<STRONG>    def _countUp</STRONG>(self, event):
	self._upRelief = self._upArrowBtn.cget(<FONT COLOR="#009900">'relief'</FONT>)
	self._upArrowBtn.configure(relief=<FONT COLOR="#009900">'sunken'</FONT>)
	self._count(1, <FONT COLOR="#009900">'start'</FONT>)

<STRONG>    def _countDown</STRONG>(self, event):
	self._downRelief = self._downArrowBtn.cget(<FONT COLOR="#009900">'relief'</FONT>)
	self._downArrowBtn.configure(relief=<FONT COLOR="#009900">'sunken'</FONT>)
	self._count(-1, <FONT COLOR="#009900">'start'</FONT>)

<STRONG>    def increment</STRONG>(self):
	self._count(1, <FONT COLOR="#009900">'force'</FONT>)

<STRONG>    def decrement</STRONG>(self):
	self._count(-1, <FONT COLOR="#009900">'force'</FONT>)

<STRONG>    def _datatype</STRONG>(self):
	datatype = self[<FONT COLOR="#009900">'datatype'</FONT>]
	if _counterCommands.has_key(datatype):
	    self._counterCommand = _counterCommands[datatype]
	elif callable(datatype):
	    self._counterCommand = datatype
	else:
	    validValues = _counterCommands.keys()
	    validValues.sort()
	    raise ValueError, (<FONT COLOR="#009900">'bad datatype value "%s":  must be a'</FONT> +
		    <FONT COLOR="#009900">' function or one of %s'</FONT>) % (datatype, validValues)

<STRONG>    def _count</STRONG>(self, factor, newFlag=None):
	if newFlag != <FONT COLOR="#009900">'force'</FONT>:
	  if newFlag is not None:
	    self._flag = newFlag

	  if self._flag == <FONT COLOR="#009900">'stopped'</FONT>:
	    return

	value = self._counterEntry.get()
	try:
	  value = self._counterCommand(value, factor,
		  self[<FONT COLOR="#009900">'increment'</FONT>], self[<FONT COLOR="#009900">'min'</FONT>], self[<FONT COLOR="#009900">'max'</FONT>])
	except:
	  sys.exc_traceback = None   <FONT COLOR="#DD0000"># Clean up object references</FONT>
	  if newFlag != <FONT COLOR="#009900">'force'</FONT>:
	    if factor == 1:
	      self._upArrowBtn.configure(relief=self._upRelief)
	    else:
	      self._downArrowBtn.configure(relief=self._downRelief)
	    self._flag = <FONT COLOR="#009900">'stopped'</FONT>
	  self.bell()
	  return

	<FONT COLOR="#DD0000"># If incrementing produces an invalid value, stop counting.</FONT>
	if not self._counterEntry.setentry(value):
	  self._flag = <FONT COLOR="#009900">'stopped'</FONT>
	  return

	if newFlag != <FONT COLOR="#009900">'force'</FONT>:
	  if self[<FONT COLOR="#009900">'autorepeat'</FONT>]:
	    if self._flag == <FONT COLOR="#009900">'start'</FONT>:
	      delay = self[<FONT COLOR="#009900">'initwait'</FONT>]
	      self._flag = <FONT COLOR="#009900">'running'</FONT>
	    else:
	      delay = self[<FONT COLOR="#009900">'repeatrate'</FONT>]
	    self._timerId = self.after(
		delay, lambda self=self, factor=factor: self._count(factor))

<STRONG>    def _stopUp</STRONG>(self, event):
        if self._timerId is not None:
            self.after_cancel(self._timerId)
	    self._timerId = None
        self._upArrowBtn.configure(relief=self._upRelief)
        self._flag = <FONT COLOR="#009900">'stopped'</FONT>

<STRONG>    def _stopDown</STRONG>(self, event):
        if self._timerId is not None:
            self.after_cancel(self._timerId)
	    self._timerId = None
        self._downArrowBtn.configure(relief=self._downRelief)
        self._flag = <FONT COLOR="#009900">'stopped'</FONT>

<STRONG>    def destroy</STRONG>(self):
        if self._timerId is not None:
            self.after_cancel(self._timerId)
	    self._timerId = None
        Pmw.MegaWidget.destroy(self)

Pmw.forwardmethods(Counter, Pmw.EntryField, <FONT COLOR="#009900">'_counterEntry'</FONT>)

</PRE>

 </BODY> </HTML>