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