Added ref to Misc/NEWS file; added hint to run regen script on Linux.
[python/dscho.git] / Mac / Lib / test / tlist.py
blob48c8c22fa672142297d67a0a8429fb744833a89d
1 # Test List module.
2 # Draw a window with all the files in the current folder.
3 # double-clicking will change folder.
5 # This test expects Win, Evt and FrameWork (and anything used by those)
6 # to work.
8 # Actually, it is more a test of FrameWork by now....
10 from FrameWork import *
11 import Win
12 import Qd
13 import List
14 import os
16 class ListWindow(Window):
17 def open(self, name, where):
18 self.where = where
19 r = (40, 40, 400, 300)
20 w = Win.NewWindow(r, name, 1, 0, -1, 1, 0x55555555)
21 r2 = (0, 0, 345, 245)
22 self.list = List.LNew(r2, (0, 0, 1, 1), (0,0), 0, w, 0, 1, 1, 1)
23 self.filllist()
24 w.DrawGrowIcon()
25 self.wid = w
26 self.do_postopen()
28 def do_activate(self, onoff, evt):
29 self.list.LActivate(onoff)
31 def do_rawupdate(self, window, event):
32 window.BeginUpdate()
33 self.do_update(window, event)
34 window.EndUpdate()
36 def do_update(self, *args):
37 self.list.LUpdate()
39 def do_contentclick(self, local, modifiers, evt):
40 dclick = self.list.LClick(local, modifiers)
41 if dclick:
42 h, v = self.list.LLastClick()
43 file = self.list.LGetCell(1000, (h, v))
44 self.where = os.path.join(self.where, file)
45 self.filllist()
47 def filllist(self):
48 """Fill the list with the contents of the current directory"""
49 l = self.list
50 l.LSetDrawingMode(0)
51 l.LDelRow(0, 0)
52 contents = os.listdir(self.where)
53 l.LAddRow(len(contents), 0)
54 for i in range(len(contents)):
55 l.LSetCell(contents[i], (0, i))
56 l.LSetDrawingMode(1)
57 l.LUpdate()
60 class TestList(Application):
61 def __init__(self):
62 Application.__init__(self)
63 self.num = 0
64 self.listoflists = []
66 def makeusermenus(self):
67 self.filemenu = m = Menu(self.menubar, "File")
68 self.newitem = MenuItem(m, "New window...", "O", self.open)
69 self.quititem = MenuItem(m, "Quit", "Q", self.quit)
71 def open(self, *args):
72 import macfs
73 fss, ok = macfs.GetDirectory()
74 if not ok:
75 return
76 w = ListWindow(self)
77 w.open('Window %d'%self.num, fss.as_pathname())
78 self.num = self.num + 1
79 self.listoflists.append(w)
81 def quit(self, *args):
82 raise self
84 def do_about(self, id, item, window, event):
85 EasyDialogs.Message("""Test the List Manager interface.
86 Simple inward-only folder browser""")
88 def main():
89 App = TestList()
90 App.mainloop()
92 if __name__ == '__main__':
93 main()