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