Guido van Rossum | dfa70a9 | 1995-01-10 17:05:37 +0000 | [diff] [blame] | 1 | # Tk backend -- unfinished |
| 2 | |
| 3 | debug = 0 |
| 4 | |
| 5 | from fmt import * |
| 6 | |
| 7 | class TkFormatter: |
| 8 | |
| 9 | def __init__(self, text): |
| 10 | self.text = text # The text widget to draw in |
| 11 | self.nospace = 1 |
| 12 | self.blanklines = 0 |
| 13 | self.font = '' |
| 14 | |
| 15 | # Methods called by htmllib.FormattingParser: |
| 16 | |
| 17 | def setfont(self, font): |
| 18 | if 1 or debug: print "setfont(%s)" % `font` |
| 19 | self.font = font |
| 20 | |
| 21 | def resetfont(self): |
| 22 | if debug: print "resetfont()" |
| 23 | self.font = '' |
| 24 | |
| 25 | def flush(self): |
| 26 | if debug: print "flush()" |
| 27 | self.needvspace(1) |
| 28 | |
| 29 | def setleftindent(self, n): |
| 30 | if debug: print "setleftindent(%d)" % n |
| 31 | |
| 32 | def needvspace(self, n): |
| 33 | if debug: print "needvspace(%d)" % n |
| 34 | self.blanklines = max(n, self.blanklines) |
| 35 | self.nospace = 1 |
| 36 | |
| 37 | def addword(self, word, nspaces): |
| 38 | if debug: print "addword(%s, %d)" % (`word`, nspaces) |
| 39 | if self.nospace and not word: |
| 40 | return |
| 41 | if self.blanklines > 0: |
| 42 | word = '\n'*self.blanklines + word |
| 43 | self.blanklines = 0 |
| 44 | self.nospace = 0 |
| 45 | here = self.text.index('end') |
| 46 | self.text.insert('end', word + nspaces*' ') |
| 47 | if not self.font: |
| 48 | self.tag_remo |
| 49 | |
| 50 | def setjust(self, c): |
| 51 | if debug: print "setjust(%s)" % `c` |
| 52 | |
| 53 | def bgn_anchor(self): |
| 54 | if debug: print "bgn_anchor()" |
| 55 | |
| 56 | def end_anchor(self): |
| 57 | if debug: print "end_anchor()" |
| 58 | |
| 59 | def hrule(self): |
| 60 | if debug: print "hrule()" |
| 61 | self.flush() |
| 62 | self.addword('_'*60, 0) |
| 63 | self.flush() |