Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / lib / python2.4 / site-packages / Pmw / Pmw_1_2 / demos / NestedDialogs.py
CommitLineData
920dae64
AT
1title = 'Modal dialog nesting demonstration'
2
3# Import Pmw from this directory tree.
4import sys
5sys.path[:0] = ['../../..']
6
7import Tkinter
8import Pmw
9
10class Demo:
11 def __init__(self, parent):
12 # Create button to launch the dialog.
13 w = Tkinter.Button(parent, text = 'Show first dialog',
14 command = self.showFirstDialog)
15 w.pack(padx = 8, pady = 8)
16
17 self.timerId = None
18
19 self.dialog1 = Pmw.MessageDialog(parent,
20 message_text = 'This is the first modal dialog.\n' +
21 'You can see how dialogs nest by\n' +
22 'clicking on the "Next" button.',
23 title = 'Dialog 1',
24 buttons = ('Next', 'Cancel'),
25 defaultbutton = 'Next',
26 command = self.next_dialog)
27 self.dialog1.withdraw()
28
29 self.dialog2 = Pmw.Dialog(self.dialog1.interior(),
30 title = 'Dialog 2',
31 buttons = ('Cancel',),
32 deactivatecommand = self.cancelTimer,
33 defaultbutton = 'Cancel')
34 self.dialog2.withdraw()
35 w = Tkinter.Label(self.dialog2.interior(),
36 text = 'This is the second modal dialog.\n' +
37 'It will automatically disappear shortly')
38 w.pack(padx = 10, pady = 10)
39
40 def showFirstDialog(self):
41 self.dialog1.activate()
42
43 def cancelTimer(self):
44 if self.timerId is not None:
45 self.dialog2.after_cancel(self.timerId)
46 self.timerId = None
47
48 def deactivateSecond(self):
49 self.timerId = None
50 self.dialog2.deactivate()
51
52 def next_dialog(self, result):
53 if result != 'Next':
54 self.dialog1.deactivate()
55 return
56
57 self.timerId = self.dialog2.after(3000, self.deactivateSecond)
58 self.dialog2.activate()
59
60######################################################################
61
62# Create demo in root window for testing.
63if __name__ == '__main__':
64 root = Tkinter.Tk()
65 Pmw.initialise(root)
66 root.title(title)
67
68 exitButton = Tkinter.Button(root, text = 'Exit', command = root.destroy)
69 exitButton.pack(side = 'bottom')
70 widget = Demo(root)
71 root.mainloop()