cpython/Lib/lib-stdwin/DirList.py

66 lines
1.4 KiB
Python
Raw Normal View History

1991-04-07 13:41:50 +00:00
# DirList -- Directory Listing widget
1991-08-16 13:14:46 +00:00
# XXX Displays messy paths when following '..'
1991-04-07 13:41:50 +00:00
try:
import posix, path
os = posix
1991-12-26 13:00:45 +00:00
except ImportError:
1991-04-07 13:41:50 +00:00
import mac, macpath
os = mac
path = macpath
import stdwin, rect
from stdwinevents import *
from Buttons import PushButton
from WindowParent import WindowParent
from HVSplit import HSplit, VSplit
1991-12-26 13:00:45 +00:00
class DirList(VSplit):
1991-04-07 13:41:50 +00:00
#
def create(self, (parent, dirname)):
self = VSplit.create(self, parent)
names = os.listdir(dirname)
for name in names:
1991-08-16 13:14:46 +00:00
if path.isdir(path.join(dirname, name)):
fullname = path.join(dirname, name)
1991-04-07 13:41:50 +00:00
btn = SubdirButton().definetext(self, fullname)
1992-01-01 19:35:13 +00:00
elif name[-3:] == '.py':
1991-04-07 13:41:50 +00:00
btn = ModuleButton().definetext(self, name)
else:
btn = FileButton().definetext(self, name)
return self
#
1991-12-26 13:00:45 +00:00
class DirListWindow(WindowParent):
1991-04-07 13:41:50 +00:00
#
def create(self, dirname):
self = WindowParent.create(self, (dirname, (0, 0)))
child = DirList().create(self, dirname)
self.realize()
return self
#
1991-12-26 13:00:45 +00:00
class SubdirButton(PushButton):
1991-04-07 13:41:50 +00:00
#
def drawpict(self, d):
PushButton.drawpict(self, d)
d.box(rect.inset(self.bounds, (3, 1)))
#
def up_trigger(self):
window = DirListWindow().create(self.text)
#
1991-12-26 13:00:45 +00:00
class FileButton(PushButton):
1991-04-07 13:41:50 +00:00
#
def up_trigger(self):
stdwin.fleep()
#
1991-12-26 13:00:45 +00:00
class ModuleButton(FileButton):
1991-04-07 13:41:50 +00:00
#
def drawpict(self, d):
PushButton.drawpict(self, d)
d.box(rect.inset(self.bounds, (1, 3)))
#