home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pytho152.zip / emx / lib / python1.5 / lib-stdwin / DirList.py < prev    next >
Text File  |  2000-08-10  |  1KB  |  59 lines

  1. # DirList -- Directory Listing widget
  2.  
  3. # XXX Displays messy paths when following '..'
  4.  
  5. import os
  6. import stdwin, rect
  7. from stdwinevents import *
  8. from Buttons import PushButton
  9. from WindowParent import WindowParent
  10. from HVSplit import HSplit, VSplit
  11.  
  12. class DirList(VSplit):
  13.     #
  14.     def create(self, parent, dirname):
  15.         self = VSplit.create(self, parent)
  16.         names = os.listdir(dirname)
  17.         for name in names:
  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)
  23.             else:
  24.                 btn = FileButton().definetext(self, name)
  25.         return self
  26.     #
  27.  
  28. class DirListWindow(WindowParent):
  29.     #
  30.     def create(self, dirname):
  31.         self = WindowParent.create(self, dirname, (0, 0))
  32.         child = DirList().create(self, dirname)
  33.         self.realize()
  34.         return self
  35.     #
  36.  
  37. class SubdirButton(PushButton):
  38.     #
  39.     def drawpict(self, d):
  40.         PushButton.drawpict(self, d)
  41.         d.box(rect.inset(self.bounds, (3, 1)))
  42.     #
  43.     def up_trigger(self):
  44.         window = DirListWindow().create(self.text)
  45.     #
  46.  
  47. class FileButton(PushButton):
  48.     #
  49.     def up_trigger(self):
  50.         stdwin.fleep()
  51.     #
  52.  
  53. class ModuleButton(FileButton):
  54.     #
  55.     def drawpict(self, d):
  56.         PushButton.drawpict(self, d)
  57.         d.box(rect.inset(self.bounds, (1, 3)))
  58.     #
  59.