cpython/Lib/stdwin/DirList.py

59 lines
1.3 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 '..'
1992-03-31 15:07:25 -04:00
import os
1991-04-07 10:41:50 -03:00
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):
1991-04-07 10:41:50 -03:00
self = VSplit.create(self, parent)
names = os.listdir(dirname)
for name in names:
1992-03-31 15:07:25 -04:00
if os.path.isdir(os.path.join(dirname, name)):
fullname = os.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))
1991-04-07 10:41:50 -03:00
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)))
#