Guido van Rossum | c636014 | 1990-10-13 19:23:40 +0000 | [diff] [blame] | 1 | # Module 'filewin' |
| 2 | # File windows, a subclass of textwin (which is a subclass of gwin) |
| 3 | |
| 4 | import stdwin |
| 5 | import textwin |
| 6 | import path |
| 7 | |
| 8 | builtin_open = open |
| 9 | |
| 10 | def readfile(fn): # Return a string containing the file's contents |
| 11 | fp = builtin_open(fn, 'r') |
| 12 | a = '' |
| 13 | n = 8096 |
| 14 | while 1: |
| 15 | b = fp.read(n) |
| 16 | if not b: break |
| 17 | a = a + b |
| 18 | return a |
| 19 | |
| 20 | |
| 21 | # FILE WINDOW |
| 22 | |
| 23 | def open_readonly(fn): # Open a file window |
| 24 | w = textwin.open_readonly(fn, readfile(fn)) |
| 25 | w.fn = fn |
| 26 | return w |
| 27 | |
| 28 | def open(fn): # Open a file window |
| 29 | w = textwin.open(fn, readfile(fn)) |
| 30 | w.fn = fn |
| 31 | return w |