Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | # Based on iwidgets2.2.0/promptdialog.itk code. |
2 | ||
3 | import Pmw | |
4 | ||
5 | # A Dialog with an entryfield | |
6 | ||
7 | class PromptDialog(Pmw.Dialog): | |
8 | def __init__(self, parent = None, **kw): | |
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 | aliases = ( | |
23 | ('entry', 'entryfield_entry'), | |
24 | ('label', 'entryfield_label'), | |
25 | ) | |
26 | self._promptDialogEntry = self.createcomponent('entryfield', | |
27 | aliases, None, | |
28 | Pmw.EntryField, (interior,)) | |
29 | self._promptDialogEntry.pack(fill='x', expand=1, | |
30 | padx = self['borderx'], pady = self['bordery']) | |
31 | ||
32 | if not kw.has_key('activatecommand'): | |
33 | # Whenever this dialog is activated, set the focus to the | |
34 | # EntryField's entry widget. | |
35 | tkentry = self.component('entry') | |
36 | self.configure(activatecommand = tkentry.focus_set) | |
37 | ||
38 | # Check keywords and initialise options. | |
39 | self.initialiseoptions() | |
40 | ||
41 | # Supply aliases to some of the entry component methods. | |
42 | def insertentry(self, index, text): | |
43 | self._promptDialogEntry.insert(index, text) | |
44 | ||
45 | def deleteentry(self, first, last=None): | |
46 | self._promptDialogEntry.delete(first, last) | |
47 | ||
48 | def indexentry(self, index): | |
49 | return self._promptDialogEntry.index(index) | |
50 | ||
51 | Pmw.forwardmethods(PromptDialog, Pmw.EntryField, '_promptDialogEntry') |