Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / src / nas,5.n2.os.2 / lib / python / lib / python2.4 / site-packages / Pmw / Pmw_1_2 / demos / MessageDialog.py
CommitLineData
86530b38
AT
1title = 'Pmw.MessageDialog 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 self.parent = parent
13
14 # Create dialog 1.
15 self.dialog1 = Pmw.MessageDialog(parent,
16 title = 'Simple message dialog',
17 defaultbutton = 0,
18 message_text = 'A simple message dialog\nwith no callback.')
19 self.dialog1.iconname('Simple message dialog')
20 self.dialog1.withdraw()
21
22 # Create dialog 2.
23 self.dialog2 = Pmw.MessageDialog(parent,
24 title = 'Bell ringing dialog',
25 message_text = 'This message dialog\nwill ring the bell ' +
26 'when\nyou click on the buttons.',
27 iconpos = 'w',
28 icon_bitmap = 'error',
29 command = self.execute2,
30 buttons = ('One', 'Two', 'Three', 'Close'))
31 self.dialog2.iconname('Bell ringing dialog')
32 self.dialog2.withdraw()
33
34 # Create dialog 3.
35 self.dialog3 = Pmw.MessageDialog(parent,
36 title = 'Vertical button dialog',
37 message_text = 'This message dialog\nhas the buttons on the\n' +
38 'right hand side.',
39 buttonboxpos = 'e',
40 iconpos = 'n',
41 icon_bitmap = 'warning',
42 buttons = ('Goodbye', 'Au revoir', 'Sayonara', 'Close'),
43 defaultbutton = 'Close')
44 self.dialog3.iconname('Vertical button dialog')
45 self.dialog3.withdraw()
46
47 # Create some buttons to launch the dialogs.
48 w = Tkinter.Button(parent, text = 'Simple dialog',
49 command = lambda self = self:
50 self.dialog1.activate(geometry = 'first+100+100'))
51 w.pack(padx = 8, pady = 8)
52
53 w = Tkinter.Button(parent, text = 'Bell ringing dialog',
54 command = self.dialog2.activate)
55 w.pack(padx = 8, pady = 8)
56
57 w = Tkinter.Button(parent, text = 'Vertical buttons',
58 command = self.dialog3.activate)
59 w.pack(padx = 8, pady = 8)
60
61 w = Tkinter.Button(parent, text = 'On the fly dialog',
62 command = self._createOnTheFly)
63 w.pack(padx = 8, pady = 8)
64
65 def execute2(self, result):
66 print 'You clicked on', result
67 if result is None:
68 self.dialog2.deactivate(result)
69 elif result == 'Close':
70 self.dialog2.deactivate(result)
71 else:
72 for count in range({'One': 1, 'Two': 2, 'Three': 3}[result]):
73 if count != 0:
74 self.dialog2.after(200)
75 self.dialog2.bell()
76
77 def _createOnTheFly(self):
78 dialog = Pmw.MessageDialog(self.parent,
79 title = 'On the fly dialog',
80 defaultbutton = 0,
81 buttons = ('OK', 'Apply', 'Cancel', 'Help'),
82 message_text = 'This dialog was created when you clicked ' +
83 'on the button.')
84 dialog.iconname('Simple message dialog')
85 result = dialog.activate()
86
87 print 'You selected', result
88
89
90
91######################################################################
92
93# Create demo in root window for testing.
94if __name__ == '__main__':
95 root = Tkinter.Tk()
96 Pmw.initialise(root)
97 root.title(title)
98
99 exitButton = Tkinter.Button(root, text = 'Exit', command = root.destroy)
100 exitButton.pack(side = 'bottom')
101 widget = Demo(root)
102 root.mainloop()