Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | title = 'Subclassing Pmw.Counter' |
2 | ||
3 | # Import Pmw from this directory tree. | |
4 | import sys | |
5 | sys.path[:0] = ['../../..'] | |
6 | ||
7 | import string | |
8 | import time | |
9 | import types | |
10 | import Tkinter | |
11 | import Pmw | |
12 | ||
13 | class LabeledDateCounter(Pmw.Counter): | |
14 | ||
15 | def __init__(self, parent=None , **kw): | |
16 | ||
17 | # Need to use long ints here because on the Macintosh the maximum size | |
18 | # of an integer is smaller than the value returned by time.time(). | |
19 | now = (long(time.time()) / 300) * 300 | |
20 | text = time.strftime('%y/%m/%d', time.localtime(now)) | |
21 | ||
22 | kw['datatype'] = 'date' | |
23 | kw['entryfield_validate'] = 'date' | |
24 | kw['entryfield_value'] = text | |
25 | kw['labelpos'] = 'w' | |
26 | ||
27 | apply(Pmw.Counter.__init__, (self, parent), kw) | |
28 | ||
29 | class LabeledRealCounter(Pmw.Counter): | |
30 | ||
31 | def __init__(self, parent=None , **kw): | |
32 | ||
33 | # Define the validate option dictionary. | |
34 | validate = {'validator' : 'real', 'min' : 0.0, 'max' : 100.0} | |
35 | ||
36 | kw['datatype'] = 'real' | |
37 | kw['entryfield_validate'] = validate | |
38 | kw['entryfield_value'] = 50.0 | |
39 | kw['labelpos'] = 'w' | |
40 | ||
41 | apply(Pmw.Counter.__init__, (self, parent), kw) | |
42 | ||
43 | class Demo: | |
44 | def __init__(self, parent): | |
45 | # Create and pack some LabeledDateCounters and LabeledRealCounter. | |
46 | self._date1 = LabeledDateCounter(parent, label_text = 'Date:') | |
47 | self._date2 = LabeledDateCounter(parent, label_text = 'Another Date:') | |
48 | self._real1 = LabeledRealCounter(parent, label_text = 'Real:') | |
49 | self._real2 = LabeledRealCounter(parent, label_text = 'Another Real:') | |
50 | ||
51 | counters = (self._date1, self._date2, self._real1, self._real2) | |
52 | ||
53 | for counter in counters: | |
54 | counter.pack(fill='x', expand=1, padx=10, pady=5) | |
55 | Pmw.alignlabels(counters) | |
56 | ||
57 | ###################################################################### | |
58 | ||
59 | # Create demo in root window for testing. | |
60 | if __name__ == '__main__': | |
61 | root = Tkinter.Tk() | |
62 | Pmw.initialise(root) | |
63 | root.title(title) | |
64 | ||
65 | exitButton = Tkinter.Button(root, text = 'Exit', command = root.destroy) | |
66 | exitButton.pack(side = 'bottom') | |
67 | widget = Demo(root) | |
68 | root.mainloop() |