Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | # Based on iwidgets2.2.0/tests/dialog.test code. |
2 | ||
3 | import sys | |
4 | import Tkinter | |
5 | import Test | |
6 | import Pmw | |
7 | ||
8 | Test.initialise() | |
9 | ||
10 | if Tkinter.TkVersion >= 8.3: | |
11 | version = sys.version_info | |
12 | if version[0] > 2 or (version[0] == 2 and version[1] > 0): | |
13 | expected1 = "AttributeError: Dialog instance has no attribute 'bogus'" | |
14 | else: | |
15 | expected1 = "AttributeError: 'Dialog' instance has no attribute 'bogus'" | |
16 | else: | |
17 | expected1 = 'AttributeError: bogus' | |
18 | ||
19 | c = Pmw.Dialog | |
20 | ||
21 | def _addListbox(): | |
22 | global _lb | |
23 | w = Test.currentWidget() | |
24 | _lb = Tkinter.Listbox(w.interior(), relief = 'sunken') | |
25 | _lb.pack(fill = 'both', expand = 'yes') | |
26 | ||
27 | def _addListEntry(text): | |
28 | _lb.insert('end', text) | |
29 | ||
30 | def _test_deactivate(result): | |
31 | w = Test.currentWidget() | |
32 | w.after(Test.delay() + 4000, | |
33 | lambda widget=w, r=result: widget.deactivate(r)) | |
34 | ||
35 | def _createOtherToplevel(): | |
36 | global tempToplevel | |
37 | Test.root.deiconify() | |
38 | Test.root.geometry('+0+0') | |
39 | tempToplevel = Tkinter.Toplevel() | |
40 | tempToplevel.geometry('+0+0') | |
41 | label = Tkinter.Label(tempToplevel, text = | |
42 | 'The cursor should turn to a\n' + | |
43 | 'clock over this window if the\n' + | |
44 | 'blt busy command is available.\n' + | |
45 | 'In any case, the button will be inactive\n' + | |
46 | 'while the modal dialog is active.') | |
47 | label.pack(padx=100, pady=100) | |
48 | button = Tkinter.Button(tempToplevel, text = 'Try to press me') | |
49 | button.pack(pady=100, expand=1) | |
50 | ||
51 | def _hideOtherToplevel(): | |
52 | global tempToplevel | |
53 | tempToplevel.withdraw() | |
54 | Test.root.withdraw() | |
55 | ||
56 | def _bogus(): | |
57 | w = Test.currentWidget() | |
58 | w.bogus() | |
59 | ||
60 | kw_1 = { | |
61 | 'buttons' : (), | |
62 | 'buttonbox_padx': 30, | |
63 | } | |
64 | tests_1 = ( | |
65 | ('buttons', ('OK',)), | |
66 | ('buttons', ('OK', 'Cancel',)), | |
67 | ('defaultbutton', 'OK'), | |
68 | (_addListbox, ()), | |
69 | (Test.num_options, (), 9), | |
70 | ('hull_background', '#d9d9d9'), | |
71 | ('buttons', ('A', 'B', 'C', 'D')), | |
72 | ('hull_cursor', 'gumby'), | |
73 | (c.title, 'Dialog Shell', ''), | |
74 | (c.interior, (), Tkinter.Frame), | |
75 | ('buttons', ()), | |
76 | ('buttons', ('OK',)), | |
77 | ('buttons', ('OK', 'Cancel')), | |
78 | ('buttons', ('OK', 'Cancel', 'Help')), | |
79 | ('defaultbutton', 'OK'), | |
80 | ('buttons', ('Apply', 'OK', 'Cancel', 'Help')), | |
81 | ('buttons', ('Apply', 'OK', 'Cancel')), | |
82 | ('defaultbutton', 'Cancel'), | |
83 | (c.invoke, 'OK', 'None'), | |
84 | ('buttonbox_OK_text', 'OOOOOKKKKK'), | |
85 | (c.show, ()), | |
86 | (c.withdraw, (), ''), | |
87 | ('buttons', ('Apply', 'OK', 'Cancel', 'Foo')), | |
88 | ('buttons', ('Apply', 'OK', 'Cancel')), | |
89 | (c.show, ()), | |
90 | (c.withdraw, (), ''), | |
91 | (_createOtherToplevel, ()), | |
92 | (_addListEntry, 'Testing application activate/deactivate'), | |
93 | (_addListEntry, 'Please wait'), | |
94 | (_test_deactivate, 'Hello World'), | |
95 | (c.activate, (), 'Hello World'), | |
96 | ('defaultbutton', ''), | |
97 | (_addListEntry, 'Now testing global activate/deactivate'), | |
98 | (_addListEntry, 'Please wait a bit more'), | |
99 | (_test_deactivate, 'Hello World'), | |
100 | (c.activate, (1), 'Hello World'), | |
101 | (_hideOtherToplevel, ()), | |
102 | ('buttons', ('Apply', 'OK', 'Cancel', 'Foo', '1')), | |
103 | (c.show, (), {}), | |
104 | (_bogus, (), expected1), | |
105 | ) | |
106 | ||
107 | kw_2 = {'buttonboxpos' : 'e', 'separatorwidth' : 5} | |
108 | tests_2 = ( | |
109 | ('buttons', ('OK',)), | |
110 | ('buttons', ('OK', 'Cancel',)), | |
111 | ('defaultbutton', 'OK'), | |
112 | ) | |
113 | ||
114 | alltests = ( | |
115 | (tests_1, kw_1), | |
116 | (tests_2, kw_2), | |
117 | ) | |
118 | ||
119 | testData = ((c, alltests),) | |
120 | ||
121 | if __name__ == '__main__': | |
122 | Test.runTests(testData) |