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 '..'
|
|
|
|
|
1992-03-31 19:07:25 +00:00
|
|
|
import os
|
1991-04-07 13:41:50 +00:00
|
|
|
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
|
|
|
#
|
1992-12-14 12:57:56 +00:00
|
|
|
def create(self, parent, dirname):
|
1991-04-07 13:41:50 +00:00
|
|
|
self = VSplit.create(self, parent)
|
|
|
|
names = os.listdir(dirname)
|
|
|
|
for name in names:
|
1992-03-31 19:07:25 +00:00
|
|
|
if os.path.isdir(os.path.join(dirname, name)):
|
|
|
|
fullname = os.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):
|
1993-01-04 09:16:51 +00:00
|
|
|
self = WindowParent.create(self, dirname, (0, 0))
|
1991-04-07 13:41:50 +00:00
|
|
|
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)))
|
|
|
|
#
|