1 # DirList -- Directory Listing widget
3 # XXX Displays messy paths when following '..'
7 from stdwinevents
import *
8 from Buttons
import PushButton
9 from WindowParent
import WindowParent
10 from HVSplit
import HSplit
, VSplit
12 class DirList(VSplit
):
14 def create(self
, parent
, dirname
):
15 self
= VSplit
.create(self
, parent
)
16 names
= os
.listdir(dirname
)
18 if os
.path
.isdir(os
.path
.join(dirname
, name
)):
19 fullname
= os
.path
.join(dirname
, name
)
20 btn
= SubdirButton().definetext(self
, fullname
)
21 elif name
[-3:] == '.py':
22 btn
= ModuleButton().definetext(self
, name
)
24 btn
= FileButton().definetext(self
, name
)
28 class DirListWindow(WindowParent
):
30 def create(self
, dirname
):
31 self
= WindowParent
.create(self
, dirname
, (0, 0))
32 child
= DirList().create(self
, dirname
)
37 class SubdirButton(PushButton
):
39 def drawpict(self
, d
):
40 PushButton
.drawpict(self
, d
)
41 d
.box(rect
.inset(self
.bounds
, (3, 1)))
44 window
= DirListWindow().create(self
.text
)
47 class FileButton(PushButton
):
53 class ModuleButton(FileButton
):
55 def drawpict(self
, d
):
56 PushButton
.drawpict(self
, d
)
57 d
.box(rect
.inset(self
.bounds
, (1, 3)))