blob: 0066c58fe9987057eb2d87e9b6281f6bb0665e9d [file] [log] [blame]
Guido van Rossum2d844d11991-04-07 13:41:50 +00001# DirList -- Directory Listing widget
2
Guido van Rossumac62b9e1991-08-16 13:14:46 +00003# XXX Displays messy paths when following '..'
4
Guido van Rossum2d844d11991-04-07 13:41:50 +00005try:
6 import posix, path
7 os = posix
Guido van Rossum2f242581991-12-26 13:00:45 +00008except ImportError:
Guido van Rossum2d844d11991-04-07 13:41:50 +00009 import mac, macpath
10 os = mac
11 path = macpath
12
13import stdwin, rect
14from stdwinevents import *
15from Buttons import PushButton
16from WindowParent import WindowParent
17from HVSplit import HSplit, VSplit
18
Guido van Rossum2f242581991-12-26 13:00:45 +000019class DirList(VSplit):
Guido van Rossum2d844d11991-04-07 13:41:50 +000020 #
21 def create(self, (parent, dirname)):
22 self = VSplit.create(self, parent)
23 names = os.listdir(dirname)
24 for name in names:
Guido van Rossumac62b9e1991-08-16 13:14:46 +000025 if path.isdir(path.join(dirname, name)):
26 fullname = path.join(dirname, name)
Guido van Rossum2d844d11991-04-07 13:41:50 +000027 btn = SubdirButton().definetext(self, fullname)
Guido van Rossumbdfcfcc1992-01-01 19:35:13 +000028 elif name[-3:] == '.py':
Guido van Rossum2d844d11991-04-07 13:41:50 +000029 btn = ModuleButton().definetext(self, name)
30 else:
31 btn = FileButton().definetext(self, name)
32 return self
33 #
34
Guido van Rossum2f242581991-12-26 13:00:45 +000035class DirListWindow(WindowParent):
Guido van Rossum2d844d11991-04-07 13:41:50 +000036 #
37 def create(self, dirname):
38 self = WindowParent.create(self, (dirname, (0, 0)))
39 child = DirList().create(self, dirname)
40 self.realize()
41 return self
42 #
43
Guido van Rossum2f242581991-12-26 13:00:45 +000044class SubdirButton(PushButton):
Guido van Rossum2d844d11991-04-07 13:41:50 +000045 #
46 def drawpict(self, d):
47 PushButton.drawpict(self, d)
48 d.box(rect.inset(self.bounds, (3, 1)))
49 #
50 def up_trigger(self):
51 window = DirListWindow().create(self.text)
52 #
53
Guido van Rossum2f242581991-12-26 13:00:45 +000054class FileButton(PushButton):
Guido van Rossum2d844d11991-04-07 13:41:50 +000055 #
56 def up_trigger(self):
57 stdwin.fleep()
58 #
59
Guido van Rossum2f242581991-12-26 13:00:45 +000060class ModuleButton(FileButton):
Guido van Rossum2d844d11991-04-07 13:41:50 +000061 #
62 def drawpict(self, d):
63 PushButton.drawpict(self, d)
64 d.box(rect.inset(self.bounds, (1, 3)))
65 #