summaryrefslogtreecommitdiffstats
path: root/Demo/tkinter/www/tkfmt.py
blob: adbb002eb15384b1d2d58c3f3856ef4e9ecb728e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Tk backend -- unfinished

debug = 0

from fmt import *

class TkFormatter:

	def __init__(self, text):
		self.text = text	# The text widget to draw in
		self.nospace = 1
		self.blanklines = 0
		self.font = ''

	# Methods called by htmllib.FormattingParser:

	def setfont(self, font):
		if 1 or debug: print "setfont(%s)" % `font`
		self.font = font

	def resetfont(self):
		if debug: print "resetfont()"
		self.font = ''

	def flush(self):
		if debug: print "flush()"
		self.needvspace(1)

	def setleftindent(self, n):
		if debug: print "setleftindent(%d)" % n

	def needvspace(self, n):
		if debug: print "needvspace(%d)" % n
		self.blanklines = max(n, self.blanklines)
		self.nospace = 1

	def addword(self, word, nspaces):
		if debug: print "addword(%s, %d)" % (`word`, nspaces)
		if self.nospace and not word:
			return
		if self.blanklines > 0:
			word = '\n'*self.blanklines + word
		self.blanklines = 0
		self.nospace = 0
		here = self.text.index('end')
		self.text.insert('end', word + nspaces*' ')
		if not self.font:
			self.tag_remo

	def setjust(self, c):
		if debug: print "setjust(%s)" % `c`

	def bgn_anchor(self):
		if debug: print "bgn_anchor()"

	def end_anchor(self):
		if debug: print "end_anchor()"

	def hrule(self):
		if debug: print "hrule()"
		self.flush()
		self.addword('_'*60, 0)
		self.flush()