3 # A Dialog with a counter
5 class CounterDialog(Pmw.Dialog):
7 def __init__(self, parent = None, **kw):
9 # Define the megawidget options.
12 ('borderx', 20, INITOPT),
13 ('bordery', 20, INITOPT),
15 self.defineoptions(kw, optiondefs)
17 # Initialise the base class (after defining the options).
18 Pmw.Dialog.__init__(self, parent)
20 # Create the components.
21 interior = self.interior()
25 ('entryfield', 'counter_entryfield'),
26 ('entry', 'counter_entryfield_entry'),
27 ('label', 'counter_label')
29 self._cdCounter = self.createcomponent('counter',
31 Pmw.Counter, (interior,))
32 self._cdCounter.pack(fill='x', expand=1,
33 padx = self['borderx'], pady = self['bordery'])
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)
41 # Check keywords and initialise options.
42 self.initialiseoptions()
44 # Supply aliases to some of the entry component methods.
45 def insertentry(self, index, text):
46 self._cdCounter.insert(index, text)
48 def deleteentry(self, first, last=None):
49 self._cdCounter.delete(first, last)
51 def indexentry(self, index):
52 return self._cdCounter.index(index)
54 Pmw.forwardmethods(CounterDialog, Pmw.Counter, '_cdCounter')