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