dabo Commit
Revision 6989
Date: 2011-11-29 13:46:34 -0800 (Tue, 29 Nov 2011)
Author: Paul
Trac: http://trac.dabodev.com/changeset/6989
Changed:
U trunk/dabo/lib/reportWriter.py
Log:
Fixed-height memos with data too long to fit would result in "< string too long
>"
as the output.
This commit fixes that to print all data possible, followed by "..." to indicate
the data was truncated.
Diff:
Modified: trunk/dabo/lib/reportWriter.py
===================================================================
--- trunk/dabo/lib/reportWriter.py 2011-11-25 19:25:01 UTC (rev 6988)
+++ trunk/dabo/lib/reportWriter.py 2011-11-29 21:46:34 UTC (rev 6989)
@@ -1872,6 +1872,7 @@
s.leftIndent =
fobject.getProp("leftIndent")
s.firstLineIndent =
fobject.getProp("firstLineIndent")
paras = expr.splitlines()
+ prior_para = ""
for idx, para in enumerate(paras):
if len(para) == 0:
# Blank line
@@ -1886,12 +1887,47 @@
word =
word.replace("<", "<")
words[idx] =
word
return " ".join(words)
- para = escapePara(para)
+ para = prior_para =
escapePara(para)
p = ParaClass(para, s)
p_height =
p.wrap(columnWidth-padLeft-padRight, None)[1]
+ if height is not None and
objNeededHeight + p_height > height and not overrideExpr:
+ # We are going to need to
truncate the output; find the amount of data we can print
+ # and print that, followed by
"..."
+ availableHeight = height -
objNeededHeight
+ p = ParaClass("...", s)
+ p_height =
p.wrap(columnWidth-padLeft-padRight, None)[1]
+ if p_height > availableHeight:
+ # don't even have space
for the "..."
+ # go to prior paragraph
and append it:
+ prior_p, prior_height =
story.pop()
+ objNeededHeight -=
prior_height
+ availableHeight =
height - objNeededHeight
+ trial_p =
ParaClass("%s..." % prior_para, s)
+ trial_height =
trial_p.wrap(columnWidth-padLeft-padRight, None)[1]
+ if trial_height >
availableHeight:
+ # It worked
before, so just remove the final 3 chars and be done with it:
+ p =
ParaClass("%s..." % prior_para[:-3], s)
+ p_height =
p.wrap(columnWidth-padLeft-padRight, None)[1]
+ objNeededHeight
+= p_height
+
story.append((p, p_height))
+ break
+ else:
+ # Get the max. chars to
print in the alloted space that we can:
+ for trial_len in
range(len(para)):
+ p =
ParaClass("%s..." % para[:trial_len+1], s)
+ p_height =
p.wrap(columnWidth-padLeft-padRight, None)[1]
+ if p_height >
availableHeight:
+ p =
ParaClass("%s..." % para[:trial_len], s)
+
p_height = p.wrap(columnWidth-padLeft-padRight, None)[1]
+ break
+ objNeededHeight +=
p_height
+ story.append((p,
p_height))
+ break
+
objNeededHeight += p_height
story.append((p, p_height))
+
def hackDeferredPara():
"""When a paragraph wraps to the next
page, the last line won't print if this isn't done."""
append_p = ParaClass("Hack: see
hackDeferredPara() in reportWriter.py", s)
@@ -1902,7 +1938,11 @@
neededHeight = objNeededHeight + padTop + padBottom
if height is not None and neededHeight > height and not
overrideExpr:
- return self.getStory(obj, overrideExpr="<<< string too
long >>>", overrideFontSize=7)
+ if not story:
+ return self.getStory(obj, overrideExpr="<<<
string too long >>>", overrideFontSize=7)
+ else:
+ # return the story as-is, but will be truncated:
+ return story, height
return story, neededHeight
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message:
http://leafe.com/archives/byMID/[email protected]