Guido van Rossum | 2d844d1 | 1991-04-07 13:41:50 +0000 | [diff] [blame^] | 1 | # DirList -- Directory Listing widget |
| 2 | |
| 3 | try: |
| 4 | import posix, path |
| 5 | os = posix |
| 6 | except NameError: |
| 7 | import mac, macpath |
| 8 | os = mac |
| 9 | path = macpath |
| 10 | |
| 11 | import stdwin, rect |
| 12 | from stdwinevents import * |
| 13 | from Buttons import PushButton |
| 14 | from WindowParent import WindowParent |
| 15 | from HVSplit import HSplit, VSplit |
| 16 | |
| 17 | class DirList() = VSplit(): |
| 18 | # |
| 19 | def create(self, (parent, dirname)): |
| 20 | self = VSplit.create(self, parent) |
| 21 | names = os.listdir(dirname) |
| 22 | for name in names: |
| 23 | if path.isdir(path.cat(dirname, name)): |
| 24 | fullname = path.cat(dirname, name) |
| 25 | btn = SubdirButton().definetext(self, fullname) |
| 26 | elif name[-3:] = '.py': |
| 27 | btn = ModuleButton().definetext(self, name) |
| 28 | else: |
| 29 | btn = FileButton().definetext(self, name) |
| 30 | return self |
| 31 | # |
| 32 | |
| 33 | class DirListWindow() = WindowParent(): |
| 34 | # |
| 35 | def create(self, dirname): |
| 36 | self = WindowParent.create(self, (dirname, (0, 0))) |
| 37 | child = DirList().create(self, dirname) |
| 38 | self.realize() |
| 39 | return self |
| 40 | # |
| 41 | |
| 42 | class SubdirButton() = PushButton(): |
| 43 | # |
| 44 | def drawpict(self, d): |
| 45 | PushButton.drawpict(self, d) |
| 46 | d.box(rect.inset(self.bounds, (3, 1))) |
| 47 | # |
| 48 | def up_trigger(self): |
| 49 | window = DirListWindow().create(self.text) |
| 50 | # |
| 51 | |
| 52 | class FileButton() = PushButton(): |
| 53 | # |
| 54 | def up_trigger(self): |
| 55 | stdwin.fleep() |
| 56 | # |
| 57 | |
| 58 | class ModuleButton() = FileButton(): |
| 59 | # |
| 60 | def drawpict(self, d): |
| 61 | PushButton.drawpict(self, d) |
| 62 | d.box(rect.inset(self.bounds, (1, 3))) |
| 63 | # |