blob: bc972a88d26cff885da08e95933d62ff61698c89 [file] [log] [blame]
Guido van Rossum17448e21995-01-30 11:53:55 +00001# Create hierarchical menus for some volumes.
2
3import os
4from Menu import *
Jack Jansenb81cf9d1995-06-06 13:08:40 +00005import macfs
6import sys
Guido van Rossum17448e21995-01-30 11:53:55 +00007
8def main():
9 global oldbar
Jack Jansenb81cf9d1995-06-06 13:08:40 +000010 my_volumes = []
11 while 1:
12 fss, ok = macfs.GetDirectory()
13 if not ok:
14 break
15 my_volumes.append(fss.as_pathname())
16 if not my_volumes:
17 return
Guido van Rossum17448e21995-01-30 11:53:55 +000018 oldbar = GetMenuBar()
19 ClearMenuBar()
20 makevolmenus(my_volumes)
21 DrawMenuBar()
22
23def reset():
24 oldbar.SetMenuBar()
25 DrawMenuBar()
26
27id = 1
28def nextid():
29 global id
30 nid = id
31 id = id+1
32 return nid
33
34def makevolmenus(volumes):
35 for vol in volumes:
36 makevolmenu(vol)
37
38def makevolmenu(vol):
39 menu = NewMenu(nextid(), vol)
40 adddirectory(menu, vol)
41 menu.InsertMenu(0)
42
43def adddirectory(menu, dir, maxdepth = 1):
44 print "adddirectory:", `dir`, maxdepth
45 files = os.listdir(dir)
46 item = 0
47 for file in files:
48 item = item+1
49 menu.AppendMenu('x') # add a dummy string
Jack Jansenb81cf9d1995-06-06 13:08:40 +000050 menu.SetMenuItemText(item, file) # set the actual text
Guido van Rossum17448e21995-01-30 11:53:55 +000051 fullname = os.path.join(dir, file)
52 if os.path.isdir(fullname):
Jack Jansenb81cf9d1995-06-06 13:08:40 +000053 menu.SetMenuItemText(item, ':' + file + ':') # append colons
Guido van Rossum17448e21995-01-30 11:53:55 +000054 if maxdepth > 0:
55 id = nextid()
56 submenu = NewMenu(id, fullname)
57 adddirectory(submenu, fullname, maxdepth-1)
58 submenu.InsertMenu(-1)
59 # If the 'Cmd' is 0x1B, then the 'Mark' is the submenu id
60 menu.SetItemMark(item, id)
61 menu.SetItemCmd(item, 0x1B)
62 if not files:
63 menu.AppendMenu(':') # dummy item to make it selectable
64 return menu
65
66if __name__ == '__main__':
67 main()
Jack Jansenb81cf9d1995-06-06 13:08:40 +000068 sys.exit(1) # To allow the user to interact...