Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | import Pmw |
2 | ||
3 | # A Dialog with a counter | |
4 | ||
5 | class CounterDialog(Pmw.Dialog): | |
6 | ||
7 | def __init__(self, parent = None, **kw): | |
8 | ||
9 | # Define the megawidget options. | |
10 | INITOPT = Pmw.INITOPT | |
11 | optiondefs = ( | |
12 | ('borderx', 20, INITOPT), | |
13 | ('bordery', 20, INITOPT), | |
14 | ) | |
15 | self.defineoptions(kw, optiondefs) | |
16 | ||
17 | # Initialise the base class (after defining the options). | |
18 | Pmw.Dialog.__init__(self, parent) | |
19 | ||
20 | # Create the components. | |
21 | interior = self.interior() | |
22 | ||
23 | # Create the counter. | |
24 | aliases = ( | |
25 | ('entryfield', 'counter_entryfield'), | |
26 | ('entry', 'counter_entryfield_entry'), | |
27 | ('label', 'counter_label') | |
28 | ) | |
29 | self._cdCounter = self.createcomponent('counter', | |
30 | aliases, None, | |
31 | Pmw.Counter, (interior,)) | |
32 | self._cdCounter.pack(fill='x', expand=1, | |
33 | padx = self['borderx'], pady = self['bordery']) | |
34 | ||
35 | if not kw.has_key('activatecommand'): | |
36 | # Whenever this dialog is activated, set the focus to the | |
37 | # Counter's entry widget. | |
38 | tkentry = self.component('entry') | |
39 | self.configure(activatecommand = tkentry.focus_set) | |
40 | ||
41 | # Check keywords and initialise options. | |
42 | self.initialiseoptions() | |
43 | ||
44 | # Supply aliases to some of the entry component methods. | |
45 | def insertentry(self, index, text): | |
46 | self._cdCounter.insert(index, text) | |
47 | ||
48 | def deleteentry(self, first, last=None): | |
49 | self._cdCounter.delete(first, last) | |
50 | ||
51 | def indexentry(self, index): | |
52 | return self._cdCounter.index(index) | |
53 | ||
54 | Pmw.forwardmethods(CounterDialog, Pmw.Counter, '_cdCounter') |