Bump version to 0.9.1.
[python/dscho.git] / Mac / Lib / test / tlist_dialog.py
blobd27a61cb1bdcf290f96cc34fbea45d55a3ce1fcb
1 from Dlg import *
2 from Events import *
3 from Evt import *
4 from List import *
5 from Qd import *
6 import Res
7 import string
8 import MacOS
10 ID = 513
12 def dodialog(items):
13 print 'This is to create a window'
15 # Create the dialog
17 d = GetNewDialog(ID, -1)
19 # Create the list and fill it
21 tp, h, rect = d.GetDialogItem(2)
22 rect = rect[0], rect[1], rect[2]-15, rect[3]-15 # Space for scrollbars
23 length = (len(items)+1) / 2
24 list = LNew(rect, (0, 0, 2, length), (0, 0), 0, d, 0, 1, 1, 1)
25 for i in range(len(items)):
26 list.LSetCell(items[i], (i%2, i/2))
28 # Draw it.
30 list.LSetDrawingMode(1)
31 list.LUpdate(self.wid.GetWindowPort().visRgn)
33 # Do the (modeless) dialog
35 while 1:
36 ok, ev = WaitNextEvent(0xffff, 10)
37 if not ok:
38 # No event.
39 continue
40 (what, message, when, where, modifiers) = ev
41 if what == updateEvt:
42 # XXXX We just always update our list (sigh...)
43 SetPort(window)
44 list.LUpdate(self.wid.GetWindowPort().visRgn)
45 if IsDialogEvent(ev):
46 # It is a dialog event. See if it's ours.
47 ok, window, item = DialogSelect(ev)
48 if ok:
49 if window == d:
50 # Yes, it is ours.
51 if item == 1: # OK button
52 break
53 elif item == 2: # List
54 (what, message, when, where, modifiers) = ev
55 SetPort(window)
56 if what == mouseDown:
57 local = GlobalToLocal(where)
58 list.LClick(local, modifiers)
59 else:
60 print 'Unexpected item hit'
61 else:
62 print 'Unexpected dialog hit'
63 else:
64 MacOS.HandleEvent(ev)
65 sel = []
66 for i in range(len(items)):
67 ok, dummycell = list.LGetSelect(0, (i%2, i/2))
68 if ok:
69 sel.append(list.LGetCell(256, (i%2, i/2)))
70 print 'Your selection:', sel
72 def test():
73 import os, sys
74 Res.FSpOpenResFile('tlist_dialog.rsrc', 1)
75 dodialog(os.listdir(':'))
76 sys.exit(1)
78 if __name__ == '__main__':
79 test()