cpython/Lib/stdwin/DirList.py

66 lines
1.4 KiB
Python
Raw Normal View History

1991-04-07 10:41:50 -03:00
# DirList -- Directory Listing widget
1991-08-16 10:14:46 -03:00
# XXX Displays messy paths when following '..'
1991-04-07 10:41:50 -03:00
try:
import posix, path
os = posix
1991-12-26 09:00:45 -04:00
except ImportError:
1991-04-07 10:41:50 -03: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 09:00:45 -04:00
class DirList(VSplit):
1991-04-07 10:41:50 -03:00
#
def create(self, (parent, dirname)):
self = VSplit.create(self, parent)
names = os.listdir(dirname)
for name in names:
1991-08-16 10:14:46 -03:00
if path.isdir(path.join(dirname, name)):
fullname = path.join(dirname, name)
1991-04-07 10:41:50 -03:00
btn = SubdirButton().definetext(self, fullname)
1992-01-01 15:35:13 -04:00
elif name[-3:] == '.py':
1991-04-07 10:41:50 -03:00
btn = ModuleButton().definetext(self, name)
else:
btn = FileButton().definetext(self, name)
return self
#
1991-12-26 09:00:45 -04:00
class DirListWindow(WindowParent):
1991-04-07 10:41:50 -03:00
#
def create(self, dirname):
self = WindowParent.create(self, (dirname, (0, 0)))
child = DirList().create(self, dirname)
self.realize()
return self
#
1991-12-26 09:00:45 -04:00
class SubdirButton(PushButton):
1991-04-07 10:41:50 -03: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 09:00:45 -04:00
class FileButton(PushButton):
1991-04-07 10:41:50 -03:00
#
def up_trigger(self):
stdwin.fleep()
#
1991-12-26 09:00:45 -04:00
class ModuleButton(FileButton):
1991-04-07 10:41:50 -03:00
#
def drawpict(self, d):
PushButton.drawpict(self, d)
d.box(rect.inset(self.bounds, (1, 3)))
#