[reportlab-users] Preformatted problem with split and join error
Remy C. Cool
reportlab-users@reportlab.com
Mon, 9 Dec 2002 14:59:34 +0100
Still busy with a reportlab test project, I stumbled into the
following problems.
1)
preformatted text ie:
<pre>this is preformatted text ... <b>t h i s i s f a t</b></pre>
is 'made' into a Preformatted text flowable with:
flowable = Preformatted('<pre>this is preformatted text ... <b>t h i s
i s f a t</b></pre>', self.styleN, bulletText=None, dedent=0))
When I want to check if this text will fit into the frame (object), I
use:
flowables = self.document.object.split(flowable, self.canvas)
The result is a list with 2 flowables ... one with the text and one
empty with just a newline character. This happens even if the
flowable fits nicely into the frame. No problems with Paragraph or
XPreformatted flowables.
2)
When I insert a print statement right after the split function above,
to printout the returned flowables and use the AddFromList function
later on to add the flowable to the frame ... I get an error:
File
"/usr/lib/python2.1/site-packages/reportlab/platypus/flowables.py",
line 222, in __repr__
text = join(self.lines, "\n")
NameError: global name 'join' is not defined
Examining this file I found:
class Preformatted(Flowable):
"""This is like the HTML <PRE> tag.
It attempts to display text exactly as you typed it in a fixed
width "typewriter" font.
The line breaks are exactly where you put
them, and it will not be wrapped."""
def __init__(self, text, style, bulletText = None, dedent=0):
"""text is the text to display. If dedent is set then common
leading space
will be chopped off the front (for example if the entire
text is indented
6 spaces or more then each line will have 6 spaces removed
from the front).
"""
self.style = style
self.bulletText = bulletText
self.lines = _dedenter(text,dedent)
def __repr__(self):
bT = self.bulletText
H = "Preformatted("
if bT is not None:
H = "Preformatted(bulletText=%s," % repr(bT)
import string
text = join(self.lines, "\n")
return "%s'''\\ \n%s''')" % (H, text)
Join could never work since it's not imported. It works when I change
the line from:
text = join(self.lines, "\n")
to:
text = string.join(self.lines, "\n")
Regards,
Remy