author | rgbecker |
Tue, 03 May 2005 11:40:11 +0000 | |
changeset 2488 | 8bc9673fffa6 |
parent 2466 | 0edb3b4ab6ff |
child 2491 | 69140e8a8285 |
permissions | -rw-r--r-- |
2332 | 1 |
#Copyright ReportLab Europe Ltd. 2000-2004 |
494 | 2 |
#see license.txt for license details |
2332 | 3 |
#history http://www.reportlab.co.uk/cgi-bin/viewcvs.cgi/public/reportlab/trunk/reportlab/platypus/doctemplate.py |
565 | 4 |
|
2332 | 5 |
__version__=''' $Id$ ''' |
565 | 6 |
|
197 | 7 |
__doc__=""" |
268 | 8 |
This module contains the core structure of platypus. |
9 |
||
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
10 |
Platypus constructs documents. Document styles are determined by DocumentTemplates. |
268 | 11 |
|
12 |
Each DocumentTemplate contains one or more PageTemplates which defines the look of the |
|
13 |
pages of the document. |
|
14 |
||
15 |
Each PageTemplate has a procedure for drawing the "non-flowing" part of the page |
|
16 |
(for example the header, footer, page number, fixed logo graphic, watermark, etcetera) and |
|
17 |
a set of Frames which enclose the flowing part of the page (for example the paragraphs, |
|
18 |
tables, or non-fixed diagrams of the text). |
|
19 |
||
20 |
A document is built when a DocumentTemplate is fed a sequence of Flowables. |
|
21 |
The action of the build consumes the flowables in order and places them onto |
|
22 |
frames on pages as space allows. When a frame runs out of space the next frame |
|
23 |
of the page is used. If no frame remains a new page is created. A new page |
|
24 |
can also be created if a page break is forced. |
|
25 |
||
26 |
The special invisible flowable NextPageTemplate can be used to specify |
|
27 |
the page template for the next page (which by default is the one being used |
|
28 |
for the current frame). |
|
197 | 29 |
""" |
565 | 30 |
|
279 | 31 |
from reportlab.platypus.flowables import * |
32 |
from reportlab.platypus.paragraph import Paragraph |
|
33 |
from reportlab.platypus.frames import Frame |
|
1530 | 34 |
from reportlab.rl_config import defaultPageSize, verbose |
279 | 35 |
import reportlab.lib.sequencer |
565 | 36 |
|
197 | 37 |
from types import * |
38 |
import sys |
|
39 |
||
2192 | 40 |
class LayoutError(Exception): |
41 |
pass |
|
565 | 42 |
|
253 | 43 |
def _doNothing(canvas, doc): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
44 |
"Dummy callback for onPage" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
45 |
pass |
512 | 46 |
|
565 | 47 |
|
1440
243d35446390
Removed 0 from multiBuild stuff prior to further changes;
andy_robinson
parents:
1428
diff
changeset
|
48 |
class IndexingFlowable(Flowable): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
49 |
"""Abstract interface definition for flowables which might |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
50 |
hold references to other pages or themselves be targets |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
51 |
of cross-references. XRefStart, XRefDest, Table of Contents, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
52 |
Indexes etc.""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
53 |
def isIndexing(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
54 |
return 1 |
512 | 55 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
56 |
def isSatisfied(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
57 |
return 1 |
512 | 58 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
59 |
def notify(self, kind, stuff): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
60 |
"""This will be called by the framework wherever 'stuff' happens. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
61 |
'kind' will be a value that can be used to decide whether to |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
62 |
pay attention or not.""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
63 |
pass |
512 | 64 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
65 |
def beforeBuild(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
66 |
"""Called by multiBuild before it starts; use this to clear |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
67 |
old contents""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
68 |
pass |
1428 | 69 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
70 |
def afterBuild(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
71 |
"""Called after build ends but before isSatisfied""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
72 |
pass |
253 | 73 |
|
197 | 74 |
class ActionFlowable(Flowable): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
75 |
'''This Flowable is never drawn, it can be used for data driven controls |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
76 |
For example to change a page template (from one column to two, for example) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
77 |
use NextPageTemplate which creates an ActionFlowable. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
78 |
''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
79 |
def __init__(self,action=()): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
80 |
if type(action) not in (ListType, TupleType): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
81 |
action = (action,) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
82 |
self.action = tuple(action) |
197 | 83 |
|
84 |
||
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
85 |
def apply(self,doc): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
86 |
''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
87 |
This is called by the doc.build processing to allow the instance to |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
88 |
implement its behaviour |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
89 |
''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
90 |
action = self.action[0] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
91 |
args = tuple(self.action[1:]) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
92 |
arn = 'handle_'+action |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
93 |
try: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
94 |
apply(getattr(doc,arn), args) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
95 |
except AttributeError, aerr: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
96 |
if aerr.args[0]==arn: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
97 |
raise NotImplementedError, "Can't handle ActionFlowable(%s)" % action |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
98 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
99 |
raise |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
100 |
except "bogus": |
2098 | 101 |
t, v, unused = sys.exc_info() |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
102 |
raise t, "%s\n handle_%s args=%s"%(v,action,args) |
197 | 103 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
104 |
def __call__(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
105 |
return self |
218
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
106 |
|
2192 | 107 |
def identity(self, maxLen=None): |
108 |
return "ActionFlowable: %s" % str(self.action) |
|
2200
be0cfccc662a
Fixed up tabs and whitespace in all source files
andy_robinson
parents:
2196
diff
changeset
|
109 |
|
2449
47b15f941325
platypus: attempt to make KeepTogether/keepWithNext more robust
rgbecker
parents:
2418
diff
changeset
|
110 |
class LCActionFlowable(ActionFlowable): |
47b15f941325
platypus: attempt to make KeepTogether/keepWithNext more robust
rgbecker
parents:
2418
diff
changeset
|
111 |
locChanger = 1 #we cause a frame or page change |
47b15f941325
platypus: attempt to make KeepTogether/keepWithNext more robust
rgbecker
parents:
2418
diff
changeset
|
112 |
|
2450 | 113 |
def wrap(self, availWidth, availHeight): |
114 |
'''Should never be called.''' |
|
115 |
raise NotImplementedError |
|
116 |
||
117 |
def draw(self): |
|
118 |
'''Should never be called.''' |
|
119 |
raise NotImplementedError |
|
120 |
||
1324 | 121 |
class NextFrameFlowable(ActionFlowable): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
122 |
def __init__(self,ix,resume=0): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
123 |
ActionFlowable.__init__(self,('nextFrame',ix,resume)) |
565 | 124 |
|
2449
47b15f941325
platypus: attempt to make KeepTogether/keepWithNext more robust
rgbecker
parents:
2418
diff
changeset
|
125 |
class CurrentFrameFlowable(LCActionFlowable): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
126 |
def __init__(self,ix,resume=0): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
127 |
ActionFlowable.__init__(self,('currentFrame',ix,resume)) |
1324 | 128 |
|
2449
47b15f941325
platypus: attempt to make KeepTogether/keepWithNext more robust
rgbecker
parents:
2418
diff
changeset
|
129 |
class _FrameBreak(LCActionFlowable): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
130 |
''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
131 |
A special ActionFlowable that allows setting doc._nextFrameIndex |
1324 | 132 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
133 |
eg story.append(FrameBreak('mySpecialFrame')) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
134 |
''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
135 |
def __call__(self,ix=None,resume=0): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
136 |
r = self.__class__(self.action+(resume,)) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
137 |
r._ix = ix |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
138 |
return r |
1324 | 139 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
140 |
def apply(self,doc): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
141 |
if getattr(self,'_ix',None): doc._nextFrameIndex = self._ix |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
142 |
ActionFlowable.apply(self,doc) |
1324 | 143 |
|
144 |
FrameBreak = _FrameBreak('frameEnd') |
|
2449
47b15f941325
platypus: attempt to make KeepTogether/keepWithNext more robust
rgbecker
parents:
2418
diff
changeset
|
145 |
PageBegin = LCActionFlowable('pageBegin') |
197 | 146 |
|
2366 | 147 |
def _evalMeasurement(n): |
148 |
if type(n) is type(''): |
|
149 |
from paraparser import _num |
|
150 |
n = _num(n) |
|
151 |
if type(n) is type(()): n = n[1] |
|
152 |
return n |
|
153 |
||
1923 | 154 |
class Indenter(ActionFlowable): |
155 |
"""Increases or decreases left and right margins of frame. |
|
156 |
||
157 |
This allows one to have a 'context-sensitive' indentation |
|
158 |
and makes nested lists way easier. |
|
2200
be0cfccc662a
Fixed up tabs and whitespace in all source files
andy_robinson
parents:
2196
diff
changeset
|
159 |
""" |
1923 | 160 |
|
161 |
def __init__(self, left=0, right=0): |
|
2366 | 162 |
self.left = _evalMeasurement(left) |
163 |
self.right = _evalMeasurement(right) |
|
1923 | 164 |
|
165 |
def apply(self, doc): |
|
166 |
doc.frame._leftExtraIndent = doc.frame._leftExtraIndent + self.left |
|
167 |
doc.frame._rightExtraIndent = doc.frame._rightExtraIndent + self.right |
|
2200
be0cfccc662a
Fixed up tabs and whitespace in all source files
andy_robinson
parents:
2196
diff
changeset
|
168 |
|
512 | 169 |
|
197 | 170 |
class NextPageTemplate(ActionFlowable): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
171 |
"""When you get to the next page, use the template specified (change to two column, for example) """ |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
172 |
def __init__(self,pt): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
173 |
ActionFlowable.__init__(self,('nextPageTemplate',pt)) |
197 | 174 |
|
565 | 175 |
|
197 | 176 |
class PageTemplate: |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
177 |
""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
178 |
essentially a list of Frames and an onPage routine to call at the start |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
179 |
of a page when this is selected. onPageEnd gets called at the end. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
180 |
derived classes can also implement beforeDrawPage and afterDrawPage if they want |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
181 |
""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
182 |
def __init__(self,id=None,frames=[],onPage=_doNothing, onPageEnd=_doNothing, |
1926 | 183 |
pagesize=None): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
184 |
if type(frames) not in (ListType,TupleType): frames = [frames] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
185 |
assert filter(lambda x: not isinstance(x,Frame), frames)==[], "frames argument error" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
186 |
self.id = id |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
187 |
self.frames = frames |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
188 |
self.onPage = onPage |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
189 |
self.onPageEnd = onPageEnd |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
190 |
self.pagesize = pagesize |
512 | 191 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
192 |
def beforeDrawPage(self,canv,doc): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
193 |
"""Override this if you want additional functionality or prefer |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
194 |
a class based page routine. Called before any flowables for |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
195 |
this page are processed.""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
196 |
pass |
197 | 197 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
198 |
def checkPageSize(self,canv,doc): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
199 |
'''This gets called by the template framework |
1926 | 200 |
If canv size != template size then the canv size is set to |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
201 |
the template size or if that's not available to the |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
202 |
doc size. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
203 |
''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
204 |
#### NEVER EVER EVER COMPARE FLOATS FOR EQUALITY |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
205 |
#RGB converting pagesizes to ints means we are accurate to one point |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
206 |
#RGB I suggest we should be aiming a little better |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
207 |
cp = None |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
208 |
dp = None |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
209 |
sp = None |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
210 |
if canv._pagesize: cp = map(int, canv._pagesize) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
211 |
if self.pagesize: sp = map(int, self.pagesize) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
212 |
if doc.pagesize: dp = map(int, doc.pagesize) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
213 |
if cp!=sp: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
214 |
if sp: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
215 |
canv.setPageSize(self.pagesize) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
216 |
elif cp!=dp: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
217 |
canv.setPageSize(doc.pagesize) |
936 | 218 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
219 |
def afterDrawPage(self, canv, doc): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
220 |
"""This is called after the last flowable for the page has |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
221 |
been processed. You might use this if the page header or |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
222 |
footer needed knowledge of what flowables were drawn on |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
223 |
this page.""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
224 |
pass |
1428 | 225 |
|
565 | 226 |
|
512 | 227 |
class BaseDocTemplate: |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
228 |
""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
229 |
First attempt at defining a document template class. |
512 | 230 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
231 |
The basic idea is simple. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
232 |
0) The document has a list of data associated with it |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
233 |
this data should derive from flowables. We'll have |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
234 |
special classes like PageBreak, FrameBreak to do things |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
235 |
like forcing a page end etc. |
512 | 236 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
237 |
1) The document has one or more page templates. |
512 | 238 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
239 |
2) Each page template has one or more frames. |
512 | 240 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
241 |
3) The document class provides base methods for handling the |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
242 |
story events and some reasonable methods for getting the |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
243 |
story flowables into the frames. |
214 | 244 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
245 |
4) The document instances can override the base handler routines. |
1428 | 246 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
247 |
Most of the methods for this class are not called directly by the user, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
248 |
but in some advanced usages they may need to be overridden via subclassing. |
1428 | 249 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
250 |
EXCEPTION: doctemplate.build(...) must be called for most reasonable uses |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
251 |
since it builds a document using the page template. |
1428 | 252 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
253 |
Each document template builds exactly one document into a file specified |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
254 |
by the filename argument on initialization. |
197 | 255 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
256 |
Possible keyword arguments for the initialization: |
1428 | 257 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
258 |
pageTemplates: A list of templates. Must be nonempty. Names |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
259 |
assigned to the templates are used for referring to them so no two used |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
260 |
templates should have the same name. For example you might want one template |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
261 |
for a title page, one for a section first page, one for a first page of |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
262 |
a chapter and two more for the interior of a chapter on odd and even pages. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
263 |
If this argument is omitted then at least one pageTemplate should be provided |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
264 |
using the addPageTemplates method before the document is built. |
2216 | 265 |
pageSize: a 2-tuple or a size constant from reportlab/lib/pagesizes.pu. |
266 |
Used by the SimpleDocTemplate subclass which does NOT accept a list of |
|
267 |
pageTemplates but makes one for you; ignored when using pageTemplates. |
|
268 |
||
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
269 |
showBoundary: if set draw a box around the frame boundaries. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
270 |
leftMargin: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
271 |
rightMargin: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
272 |
topMargin: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
273 |
bottomMargin: Margin sizes in points (default 1 inch) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
274 |
These margins may be overridden by the pageTemplates. They are primarily of interest |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
275 |
for the SimpleDocumentTemplate subclass. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
276 |
allowSplitting: If set flowables (eg, paragraphs) may be split across frames or pages |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
277 |
(default: 1) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
278 |
title: Internal title for document (does not automatically display on any page) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
279 |
author: Internal author for document (does not automatically display on any page) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
280 |
""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
281 |
_initArgs = { 'pagesize':defaultPageSize, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
282 |
'pageTemplates':[], |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
283 |
'showBoundary':0, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
284 |
'leftMargin':inch, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
285 |
'rightMargin':inch, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
286 |
'topMargin':inch, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
287 |
'bottomMargin':inch, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
288 |
'allowSplitting':1, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
289 |
'title':None, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
290 |
'author':None, |
1839
084e4af662dc
Passing invariant argument through to canvas
andy_robinson
parents:
1838
diff
changeset
|
291 |
'invariant':None, |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
292 |
'_pageBreakQuick':1} |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
293 |
_invalidInitArgs = () |
2104 | 294 |
_firstPageTemplateIndex = 0 |
197 | 295 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
296 |
def __init__(self, filename, **kw): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
297 |
"""create a document template bound to a filename (see class documentation for keyword arguments)""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
298 |
self.filename = filename |
512 | 299 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
300 |
for k in self._initArgs.keys(): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
301 |
if not kw.has_key(k): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
302 |
v = self._initArgs[k] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
303 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
304 |
if k in self._invalidInitArgs: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
305 |
raise ValueError, "Invalid argument %s" % k |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
306 |
v = kw[k] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
307 |
setattr(self,k,v) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
308 |
#print "pagesize is", self.pagesize |
310 | 309 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
310 |
p = self.pageTemplates |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
311 |
self.pageTemplates = [] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
312 |
self.addPageTemplates(p) |
1428 | 313 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
314 |
# facility to assist multi-build and cross-referencing. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
315 |
# various hooks can put things into here - key is what |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
316 |
# you want, value is a page number. This can then be |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
317 |
# passed to indexing flowables. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
318 |
self._pageRefs = {} |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
319 |
self._indexingFlowables = [] |
512 | 320 |
|
321 |
||
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
322 |
#callback facility for progress monitoring |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
323 |
self._onPage = None |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
324 |
self._onProgress = None |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
325 |
self._flowableCount = 0 # so we know how far to go |
1668
448a9205be12
Provision for callback progress monitoring in basic doctemplate class
andy_robinson
parents:
1530
diff
changeset
|
326 |
|
2192 | 327 |
|
328 |
#infinite loop detection if we start doing lots of empty pages |
|
329 |
self._curPageFlowableCount = 0 |
|
330 |
self._emptyPages = 0 |
|
2193 | 331 |
self._emptyPagesAllowed = 10 |
2192 | 332 |
|
1923 | 333 |
#context sensitive margins - set by story, not from outside |
334 |
self._leftExtraIndent = 0.0 |
|
335 |
self._rightExtraIndent = 0.0 |
|
2200
be0cfccc662a
Fixed up tabs and whitespace in all source files
andy_robinson
parents:
2196
diff
changeset
|
336 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
337 |
self._calc() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
338 |
self.afterInit() |
1502 | 339 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
340 |
def _calc(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
341 |
self._rightMargin = self.pagesize[0] - self.rightMargin |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
342 |
self._topMargin = self.pagesize[1] - self.topMargin |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
343 |
self.width = self._rightMargin - self.leftMargin |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
344 |
self.height = self._topMargin - self.bottomMargin |
1502 | 345 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
346 |
def setPageCallBack(self, func): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
347 |
'Simple progress monitor - func(pageNo) called on each new page' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
348 |
self._onPage = func |
197 | 349 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
350 |
def setProgressCallBack(self, func): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
351 |
'''Cleverer progress monitor - func(typ, value) called regularly''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
352 |
self._onProgress = func |
1668
448a9205be12
Provision for callback progress monitoring in basic doctemplate class
andy_robinson
parents:
1530
diff
changeset
|
353 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
354 |
def clean_hanging(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
355 |
'handle internal postponed actions' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
356 |
while len(self._hanging): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
357 |
self.handle_flowable(self._hanging) |
1428 | 358 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
359 |
def addPageTemplates(self,pageTemplates): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
360 |
'add one or a sequence of pageTemplates' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
361 |
if type(pageTemplates) not in (ListType,TupleType): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
362 |
pageTemplates = [pageTemplates] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
363 |
#this test below fails due to inconsistent imports! |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
364 |
#assert filter(lambda x: not isinstance(x,PageTemplate), pageTemplates)==[], "pageTemplates argument error" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
365 |
for t in pageTemplates: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
366 |
self.pageTemplates.append(t) |
1502 | 367 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
368 |
def handle_documentBegin(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
369 |
'''implement actions at beginning of document''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
370 |
self._hanging = [PageBegin] |
2104 | 371 |
self.pageTemplate = self.pageTemplates[self._firstPageTemplateIndex] |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
372 |
self.page = 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
373 |
self.beforeDocument() |
253 | 374 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
375 |
def handle_pageBegin(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
376 |
'''Perform actions required at beginning of page. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
377 |
shouldn't normally be called directly''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
378 |
self.page = self.page + 1 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
379 |
self.pageTemplate.beforeDrawPage(self.canv,self) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
380 |
self.pageTemplate.checkPageSize(self.canv,self) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
381 |
self.pageTemplate.onPage(self.canv,self) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
382 |
for f in self.pageTemplate.frames: f._reset() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
383 |
self.beforePage() |
2192 | 384 |
#keep a count of flowables added to this page. zero indicates bad stuff |
385 |
self._curPageFlowableCount = 0 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
386 |
if hasattr(self,'_nextFrameIndex'): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
387 |
del self._nextFrameIndex |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
388 |
self.frame = self.pageTemplate.frames[0] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
389 |
self.handle_frameBegin() |
197 | 390 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
391 |
def handle_pageEnd(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
392 |
''' show the current page |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
393 |
check the next page template |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
394 |
hang a page begin |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
395 |
''' |
2192 | 396 |
#detect infinite loops... |
397 |
if self._curPageFlowableCount == 0: |
|
398 |
self._emptyPages = self._emptyPages + 1 |
|
399 |
else: |
|
400 |
self._emptyPages = 0 |
|
401 |
if self._emptyPages >= self._emptyPagesAllowed: |
|
2196 | 402 |
if 1: |
2466 | 403 |
ident = "More than %d pages generated without content - halting layout. Likely that a flowable is too large for any frame." % self._emptyPagesAllowed |
404 |
#leave to keep apart from the raise |
|
405 |
raise LayoutError(ident) |
|
2196 | 406 |
else: |
407 |
pass #attempt to restore to good state |
|
408 |
else: |
|
409 |
if self._onProgress: |
|
410 |
self._onProgress('PAGE', self.canv.getPageNumber()) |
|
411 |
self.pageTemplate.afterDrawPage(self.canv, self) |
|
412 |
self.pageTemplate.onPageEnd(self.canv, self) |
|
413 |
self.afterPage() |
|
2488
8bc9673fffa6
doctemplate.py: support for canvasmaker and rotation
rgbecker
parents:
2466
diff
changeset
|
414 |
self.canv.setPageRotation(getattr(self.pageTemplate,'rotation',0) |
2196 | 415 |
self.canv.showPage() |
2418 | 416 |
|
417 |
if hasattr(self,'_nextPageTemplateCycle'): |
|
418 |
#they are cycling through pages'; we keep the index |
|
419 |
cyc = self._nextPageTemplateCycle |
|
420 |
idx = self._nextPageTemplateIndex |
|
421 |
self.pageTemplate = cyc[idx] #which is one of the ones in the list anyway |
|
422 |
#bump up by 1 |
|
423 |
self._nextPageTemplateIndex = (idx + 1) % len(cyc) |
|
424 |
elif hasattr(self,'_nextPageTemplateIndex'): |
|
2196 | 425 |
self.pageTemplate = self.pageTemplates[self._nextPageTemplateIndex] |
426 |
del self._nextPageTemplateIndex |
|
427 |
if self._emptyPages==0: |
|
428 |
pass #store good state here |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
429 |
self._hanging.append(PageBegin) |
197 | 430 |
|
2408 | 431 |
def handle_pageBreak(self,slow=None): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
432 |
'''some might choose not to end all the frames''' |
2408 | 433 |
if self._pageBreakQuick and not slow: |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
434 |
self.handle_pageEnd() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
435 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
436 |
n = len(self._hanging) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
437 |
while len(self._hanging)==n: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
438 |
self.handle_frameEnd() |
512 | 439 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
440 |
def handle_frameBegin(self,resume=0): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
441 |
'''What to do at the beginning of a frame''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
442 |
f = self.frame |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
443 |
if f._atTop: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
444 |
if self.showBoundary or self.frame.showBoundary: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
445 |
self.frame.drawBoundary(self.canv) |
1923 | 446 |
f._leftExtraIndent = self._leftExtraIndent |
447 |
f._rightExtraIndent = self._rightExtraIndent |
|
197 | 448 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
449 |
def handle_frameEnd(self,resume=0): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
450 |
''' Handles the semantics of the end of a frame. This includes the selection of |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
451 |
the next frame or if this is the last frame then invoke pageEnd. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
452 |
''' |
2200
be0cfccc662a
Fixed up tabs and whitespace in all source files
andy_robinson
parents:
2196
diff
changeset
|
453 |
|
1923 | 454 |
self._leftExtraIndent = self.frame._leftExtraIndent |
455 |
self._rightExtraIndent = self.frame._rightExtraIndent |
|
456 |
||
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
457 |
if hasattr(self,'_nextFrameIndex'): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
458 |
frame = self.pageTemplate.frames[self._nextFrameIndex] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
459 |
del self._nextFrameIndex |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
460 |
self.handle_frameBegin(resume) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
461 |
elif hasattr(self.frame,'lastFrame') or self.frame is self.pageTemplate.frames[-1]: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
462 |
self.handle_pageEnd() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
463 |
self.frame = None |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
464 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
465 |
f = self.frame |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
466 |
self.frame = self.pageTemplate.frames[self.pageTemplate.frames.index(f) + 1] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
467 |
self.handle_frameBegin() |
197 | 468 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
469 |
def handle_nextPageTemplate(self,pt): |
2449
47b15f941325
platypus: attempt to make KeepTogether/keepWithNext more robust
rgbecker
parents:
2418
diff
changeset
|
470 |
'''On endPage change to the page template with name or index pt''' |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
471 |
if type(pt) is StringType: |
2418 | 472 |
if hasattr(self, '_nextPageTemplateCycle'): del self._nextPageTemplateCycle |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
473 |
for t in self.pageTemplates: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
474 |
if t.id == pt: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
475 |
self._nextPageTemplateIndex = self.pageTemplates.index(t) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
476 |
return |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
477 |
raise ValueError, "can't find template('%s')"%pt |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
478 |
elif type(pt) is IntType: |
2418 | 479 |
if hasattr(self, '_nextPageTemplateCycle'): del self._nextPageTemplateCycle |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
480 |
self._nextPageTemplateIndex = pt |
2418 | 481 |
elif type(pt) in (ListType, TupleType): |
482 |
#used for alternating left/right pages |
|
483 |
#collect the refs to the template objects, complain if any are bad |
|
484 |
cycle = [] |
|
485 |
for templateName in pt: |
|
486 |
found = 0 |
|
487 |
for t in self.pageTemplates: |
|
488 |
if t.id == templateName: |
|
489 |
cycle.append(t) |
|
490 |
found = 1 |
|
491 |
if not found: |
|
492 |
raise ValueError("Cannot find page template called %s" % templateName) |
|
493 |
#double-check all of them are there... |
|
494 |
||
495 |
first = cycle[0] |
|
496 |
#ensure we start on the first one |
|
497 |
self._nextPageTemplateCycle = cycle |
|
498 |
self._nextPageTemplateIndex = 0 #indexes into the cycle |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
499 |
else: |
2418 | 500 |
raise TypeError, "argument pt should be string or integer or list" |
197 | 501 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
502 |
def handle_nextFrame(self,fx): |
2449
47b15f941325
platypus: attempt to make KeepTogether/keepWithNext more robust
rgbecker
parents:
2418
diff
changeset
|
503 |
'''On endFrame change to the frame with name or index fx''' |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
504 |
if type(fx) is StringType: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
505 |
for f in self.pageTemplate.frames: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
506 |
if f.id == fx: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
507 |
self._nextFrameIndex = self.pageTemplate.frames.index(f) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
508 |
return |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
509 |
raise ValueError, "can't find frame('%s')"%fx |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
510 |
elif type(fx) is IntType: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
511 |
self._nextFrameIndex = fx |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
512 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
513 |
raise TypeError, "argument fx should be string or integer" |
512 | 514 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
515 |
def handle_currentFrame(self,fx): |
2449
47b15f941325
platypus: attempt to make KeepTogether/keepWithNext more robust
rgbecker
parents:
2418
diff
changeset
|
516 |
'''change to the frame with name or index fx''' |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
517 |
if type(fx) is StringType: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
518 |
for f in self.pageTemplate.frames: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
519 |
if f.id == fx: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
520 |
self._nextFrameIndex = self.pageTemplate.frames.index(f) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
521 |
return |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
522 |
raise ValueError, "can't find frame('%s')"%fx |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
523 |
elif type(fx) is IntType: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
524 |
self._nextFrameIndex = fx |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
525 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
526 |
raise TypeError, "argument fx should be string or integer" |
197 | 527 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
528 |
def handle_breakBefore(self, flowables): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
529 |
'''preprocessing step to allow pageBreakBefore and frameBreakBefore attributes''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
530 |
first = flowables[0] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
531 |
# if we insert a page break before, we'll process that, see it again, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
532 |
# and go in an infinite loop. So we need to set a flag on the object |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
533 |
# saying 'skip me'. This should be unset on the next pass |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
534 |
if hasattr(first, '_skipMeNextTime'): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
535 |
delattr(first, '_skipMeNextTime') |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
536 |
return |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
537 |
# this could all be made much quicker by putting the attributes |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
538 |
# in to the flowables with a defult value of 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
539 |
if hasattr(first,'pageBreakBefore') and first.pageBreakBefore == 1: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
540 |
first._skipMeNextTime = 1 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
541 |
first.insert(0, PageBreak()) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
542 |
return |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
543 |
if hasattr(first,'style') and hasattr(first.style, 'pageBreakBefore') and first.style.pageBreakBefore == 1: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
544 |
first._skipMeNextTime = 1 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
545 |
flowables.insert(0, PageBreak()) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
546 |
return |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
547 |
if hasattr(first,'frameBreakBefore') and first.frameBreakBefore == 1: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
548 |
first._skipMeNextTime = 1 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
549 |
flowables.insert(0, FrameBreak()) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
550 |
return |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
551 |
if hasattr(first,'style') and hasattr(first.style, 'frameBreakBefore') and first.style.frameBreakBefore == 1: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
552 |
first._skipMeNextTime = 1 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
553 |
flowables.insert(0, FrameBreak()) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
554 |
return |
1428 | 555 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
556 |
def handle_keepWithNext(self, flowables): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
557 |
"implements keepWithNext" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
558 |
i = 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
559 |
n = len(flowables) |
2449
47b15f941325
platypus: attempt to make KeepTogether/keepWithNext more robust
rgbecker
parents:
2418
diff
changeset
|
560 |
while i<n and flowables[i].getKeepWithNext(): i += 1 |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
561 |
if i: |
2449
47b15f941325
platypus: attempt to make KeepTogether/keepWithNext more robust
rgbecker
parents:
2418
diff
changeset
|
562 |
if not getattr(flowables[i],'locChanger',None): i += 1 |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
563 |
K = KeepTogether(flowables[:i]) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
564 |
for f in K._flowables: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
565 |
f.keepWithNext = 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
566 |
del flowables[:i] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
567 |
flowables.insert(0,K) |
1425 | 568 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
569 |
def handle_flowable(self,flowables): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
570 |
'''try to handle one flowable from the front of list flowables.''' |
1428 | 571 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
572 |
#allow document a chance to look at, modify or ignore |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
573 |
#the object(s) about to be processed |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
574 |
self.filterFlowables(flowables) |
1428 | 575 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
576 |
self.handle_breakBefore(flowables) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
577 |
self.handle_keepWithNext(flowables) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
578 |
f = flowables[0] |
2192 | 579 |
#print 'handling flowable %s' % f.identity() |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
580 |
del flowables[0] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
581 |
if f is None: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
582 |
return |
197 | 583 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
584 |
if isinstance(f,PageBreak): |
2408 | 585 |
if isinstance(f,SlowPageBreak): |
586 |
self.handle_pageBreak(slow=1) |
|
587 |
else: |
|
588 |
self.handle_pageBreak() |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
589 |
self.afterFlowable(f) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
590 |
elif isinstance(f,ActionFlowable): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
591 |
f.apply(self) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
592 |
self.afterFlowable(f) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
593 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
594 |
#try to fit it then draw it |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
595 |
if self.frame.add(f, self.canv, trySplit=self.allowSplitting): |
2192 | 596 |
self._curPageFlowableCount = self._curPageFlowableCount + 1 |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
597 |
self.afterFlowable(f) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
598 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
599 |
#if isinstance(f, KeepTogether): print 'could not add it to frame' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
600 |
if self.allowSplitting: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
601 |
# see if this is a splittable thing |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
602 |
S = self.frame.split(f,self.canv) |
1838
f7eeee67832c
Changes to allow invariant documents when needed
andy_robinson
parents:
1829
diff
changeset
|
603 |
#print '%d parts to sequence on page %d' % (len(S), self.page) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
604 |
n = len(S) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
605 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
606 |
n = 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
607 |
#if isinstance(f, KeepTogether): print 'n=%d' % n |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
608 |
if n: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
609 |
if self.frame.add(S[0], self.canv, trySplit=0): |
2192 | 610 |
self._curPageFlowableCount = self._curPageFlowableCount + 1 |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
611 |
self.afterFlowable(S[0]) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
612 |
else: |
2466 | 613 |
ident = "Splitting error(n==%d) on page %d in\n%s" % (n,self.page,f.identity(30)) |
614 |
#leave to keep apart from the raise |
|
615 |
raise LayoutError(ident) |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
616 |
del S[0] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
617 |
for f in xrange(n-1): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
618 |
flowables.insert(f,S[f]) # put split flowables back on the list |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
619 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
620 |
if hasattr(f,'_postponed'): |
2466 | 621 |
ident = "Flowable %s too large on page %d" % (f.identity(30), self.page) |
622 |
#leave to keep apart from the raise |
|
623 |
raise LayoutError(ident) |
|
2196 | 624 |
# this ought to be cleared when they are finally drawn! |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
625 |
f._postponed = 1 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
626 |
flowables.insert(0,f) # put the flowable back |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
627 |
self.handle_frameEnd() |
197 | 628 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
629 |
#these are provided so that deriving classes can refer to them |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
630 |
_handle_documentBegin = handle_documentBegin |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
631 |
_handle_pageBegin = handle_pageBegin |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
632 |
_handle_pageEnd = handle_pageEnd |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
633 |
_handle_frameBegin = handle_frameBegin |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
634 |
_handle_frameEnd = handle_frameEnd |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
635 |
_handle_flowable = handle_flowable |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
636 |
_handle_nextPageTemplate = handle_nextPageTemplate |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
637 |
_handle_currentFrame = handle_currentFrame |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
638 |
_handle_nextFrame = handle_nextFrame |
1505 | 639 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
640 |
def _startBuild(self, filename=None, canvasmaker=canvas.Canvas): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
641 |
self._calc() |
1839
084e4af662dc
Passing invariant argument through to canvas
andy_robinson
parents:
1838
diff
changeset
|
642 |
self.canv = canvasmaker(filename or self.filename, |
084e4af662dc
Passing invariant argument through to canvas
andy_robinson
parents:
1838
diff
changeset
|
643 |
pagesize=self.pagesize, |
084e4af662dc
Passing invariant argument through to canvas
andy_robinson
parents:
1838
diff
changeset
|
644 |
invariant=self.invariant) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
645 |
if self._onPage: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
646 |
self.canv.setPageCallBack(self._onPage) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
647 |
self.handle_documentBegin() |
512 | 648 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
649 |
def _endBuild(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
650 |
if self._hanging!=[] and self._hanging[-1] is PageBegin: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
651 |
del self._hanging[-1] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
652 |
self.clean_hanging() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
653 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
654 |
self.clean_hanging() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
655 |
self.handle_pageBreak() |
1505 | 656 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
657 |
if getattr(self,'_doSave',1): self.canv.save() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
658 |
if self._onPage: self.canv.setPageCallBack(None) |
512 | 659 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
660 |
def build(self, flowables, filename=None, canvasmaker=canvas.Canvas): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
661 |
"""Build the document from a list of flowables. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
662 |
If the filename argument is provided then that filename is used |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
663 |
rather than the one provided upon initialization. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
664 |
If the canvasmaker argument is provided then it will be used |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
665 |
instead of the default. For example a slideshow might use |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
666 |
an alternate canvas which places 6 slides on a page (by |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
667 |
doing translations, scalings and redefining the page break |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
668 |
operations). |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
669 |
""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
670 |
#assert filter(lambda x: not isinstance(x,Flowable), flowables)==[], "flowables argument error" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
671 |
flowableCount = len(flowables) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
672 |
if self._onProgress: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
673 |
self._onProgress('STARTED',0) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
674 |
self._onProgress('SIZE_EST', len(flowables)) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
675 |
self._startBuild(filename,canvasmaker) |
512 | 676 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
677 |
while len(flowables): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
678 |
self.clean_hanging() |
2113
e82d8b3880d8
Preliminary support for tracing through doc builds
andy_robinson
parents:
2104
diff
changeset
|
679 |
try: |
e82d8b3880d8
Preliminary support for tracing through doc builds
andy_robinson
parents:
2104
diff
changeset
|
680 |
first = flowables[0] |
e82d8b3880d8
Preliminary support for tracing through doc builds
andy_robinson
parents:
2104
diff
changeset
|
681 |
self.handle_flowable(flowables) |
e82d8b3880d8
Preliminary support for tracing through doc builds
andy_robinson
parents:
2104
diff
changeset
|
682 |
except: |
e82d8b3880d8
Preliminary support for tracing through doc builds
andy_robinson
parents:
2104
diff
changeset
|
683 |
#if it has trace info, add it to the traceback message. |
2127
d5e43db37d59
Allowing for strange flowables with no _traceIfo object
william_ng
parents:
2113
diff
changeset
|
684 |
if hasattr(first, '_traceInfo') and first._traceInfo: |
2113
e82d8b3880d8
Preliminary support for tracing through doc builds
andy_robinson
parents:
2104
diff
changeset
|
685 |
exc = sys.exc_info()[1] |
e82d8b3880d8
Preliminary support for tracing through doc builds
andy_robinson
parents:
2104
diff
changeset
|
686 |
args = list(exc.args) |
e82d8b3880d8
Preliminary support for tracing through doc builds
andy_robinson
parents:
2104
diff
changeset
|
687 |
tr = first._traceInfo |
e82d8b3880d8
Preliminary support for tracing through doc builds
andy_robinson
parents:
2104
diff
changeset
|
688 |
args[0] = args[0] + '\n(srcFile %s, line %d char %d to line %d char %d)' % ( |
e82d8b3880d8
Preliminary support for tracing through doc builds
andy_robinson
parents:
2104
diff
changeset
|
689 |
tr.srcFile, |
e82d8b3880d8
Preliminary support for tracing through doc builds
andy_robinson
parents:
2104
diff
changeset
|
690 |
tr.startLineNo, |
e82d8b3880d8
Preliminary support for tracing through doc builds
andy_robinson
parents:
2104
diff
changeset
|
691 |
tr.startLinePos, |
e82d8b3880d8
Preliminary support for tracing through doc builds
andy_robinson
parents:
2104
diff
changeset
|
692 |
tr.endLineNo, |
e82d8b3880d8
Preliminary support for tracing through doc builds
andy_robinson
parents:
2104
diff
changeset
|
693 |
tr.endLinePos |
e82d8b3880d8
Preliminary support for tracing through doc builds
andy_robinson
parents:
2104
diff
changeset
|
694 |
) |
e82d8b3880d8
Preliminary support for tracing through doc builds
andy_robinson
parents:
2104
diff
changeset
|
695 |
exc.args = tuple(args) |
e82d8b3880d8
Preliminary support for tracing through doc builds
andy_robinson
parents:
2104
diff
changeset
|
696 |
raise |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
697 |
if self._onProgress: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
698 |
self._onProgress('PROGRESS',flowableCount - len(flowables)) |
1505 | 699 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
700 |
self._endBuild() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
701 |
if self._onProgress: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
702 |
self._onProgress('FINISHED',0) |
512 | 703 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
704 |
def _allSatisfied(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
705 |
"""Called by multi-build - are all cross-references resolved?""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
706 |
allHappy = 1 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
707 |
for f in self._indexingFlowables: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
708 |
if not f.isSatisfied(): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
709 |
allHappy = 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
710 |
break |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
711 |
return allHappy |
197 | 712 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
713 |
def notify(self, kind, stuff): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
714 |
""""Forward to any listeners""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
715 |
for l in self._indexingFlowables: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
716 |
l.notify(kind, stuff) |
1505 | 717 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
718 |
def pageRef(self, label): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
719 |
"""hook to register a page number""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
720 |
if verbose: print "pageRef called with label '%s' on page %d" % ( |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
721 |
label, self.page) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
722 |
self._pageRefs[label] = self.page |
1428 | 723 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
724 |
def multiBuild(self, story, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
725 |
filename=None, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
726 |
canvasmaker=canvas.Canvas, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
727 |
maxPasses = 10): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
728 |
"""Makes multiple passes until all indexing flowables |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
729 |
are happy.""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
730 |
self._indexingFlowables = [] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
731 |
#scan the story and keep a copy |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
732 |
for thing in story: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
733 |
if thing.isIndexing(): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
734 |
self._indexingFlowables.append(thing) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
735 |
#print 'scanned story, found these indexing flowables:\n' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
736 |
#print self._indexingFlowables |
1683 | 737 |
|
1829
ce5ceec32eab
Fix up multiBuild to be cleverer about initial saves
rgbecker
parents:
1824
diff
changeset
|
738 |
#better fix for filename is a 'file' problem |
ce5ceec32eab
Fix up multiBuild to be cleverer about initial saves
rgbecker
parents:
1824
diff
changeset
|
739 |
self._doSave = 0 |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
740 |
passes = 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
741 |
while 1: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
742 |
passes = passes + 1 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
743 |
if self._onProgress: |
2460
dc28c1738ea9
doctemplate.py: fix buglet reported by Steve Halasz
rgbecker
parents:
2450
diff
changeset
|
744 |
self._onProgress('PASS', passes) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
745 |
if verbose: print 'building pass '+str(passes) + '...', |
197 | 746 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
747 |
for fl in self._indexingFlowables: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
748 |
fl.beforeBuild() |
218
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
749 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
750 |
# work with a copy of the story, since it is consumed |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
751 |
tempStory = story[:] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
752 |
self.build(tempStory, filename, canvasmaker) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
753 |
#self.notify('debug',None) |
512 | 754 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
755 |
#clean up so multi-build does not go wrong - the frame |
2196 | 756 |
#packer might have tacked an attribute onto some flowables |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
757 |
for elem in story: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
758 |
if hasattr(elem, '_postponed'): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
759 |
del elem._postponed |
218
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
760 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
761 |
for fl in self._indexingFlowables: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
762 |
fl.afterBuild() |
218
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
763 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
764 |
happy = self._allSatisfied() |
221 | 765 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
766 |
if happy: |
1829
ce5ceec32eab
Fix up multiBuild to be cleverer about initial saves
rgbecker
parents:
1824
diff
changeset
|
767 |
self._doSave = 0 |
ce5ceec32eab
Fix up multiBuild to be cleverer about initial saves
rgbecker
parents:
1824
diff
changeset
|
768 |
self.canv.save() |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
769 |
break |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
770 |
if passes > maxPasses: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
771 |
raise IndexError, "Index entries not resolved after %d passes" % maxPasses |
1428 | 772 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
773 |
if verbose: print 'saved' |
284
eabeb5f4e851
Added UserDocTemplate class, and paragraph.getPlainText()
andy_robinson
parents:
279
diff
changeset
|
774 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
775 |
#these are pure virtuals override in derived classes |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
776 |
#NB these get called at suitable places by the base class |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
777 |
#so if you derive and override the handle_xxx methods |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
778 |
#it's up to you to ensure that they maintain the needed consistency |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
779 |
def afterInit(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
780 |
"""This is called after initialisation of the base class.""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
781 |
pass |
284
eabeb5f4e851
Added UserDocTemplate class, and paragraph.getPlainText()
andy_robinson
parents:
279
diff
changeset
|
782 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
783 |
def beforeDocument(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
784 |
"""This is called before any processing is |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
785 |
done on the document.""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
786 |
pass |
284
eabeb5f4e851
Added UserDocTemplate class, and paragraph.getPlainText()
andy_robinson
parents:
279
diff
changeset
|
787 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
788 |
def beforePage(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
789 |
"""This is called at the beginning of page |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
790 |
processing, and immediately before the |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
791 |
beforeDrawPage method of the current page |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
792 |
template.""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
793 |
pass |
284
eabeb5f4e851
Added UserDocTemplate class, and paragraph.getPlainText()
andy_robinson
parents:
279
diff
changeset
|
794 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
795 |
def afterPage(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
796 |
"""This is called after page processing, and |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
797 |
immediately after the afterDrawPage method |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
798 |
of the current page template.""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
799 |
pass |
284
eabeb5f4e851
Added UserDocTemplate class, and paragraph.getPlainText()
andy_robinson
parents:
279
diff
changeset
|
800 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
801 |
def filterFlowables(self,flowables): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
802 |
'''called to filter flowables at the start of the main handle_flowable method. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
803 |
Upon return if flowables[0] has been set to None it is discarded and the main |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
804 |
method returns. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
805 |
''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
806 |
pass |
1428 | 807 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
808 |
def afterFlowable(self, flowable): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
809 |
'''called after a flowable has been rendered''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
810 |
pass |
284
eabeb5f4e851
Added UserDocTemplate class, and paragraph.getPlainText()
andy_robinson
parents:
279
diff
changeset
|
811 |
|
565 | 812 |
|
221 | 813 |
class SimpleDocTemplate(BaseDocTemplate): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
814 |
"""A special case document template that will handle many simple documents. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
815 |
See documentation for BaseDocTemplate. No pageTemplates are required |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
816 |
for this special case. A page templates are inferred from the |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
817 |
margin information and the onFirstPage, onLaterPages arguments to the build method. |
1428 | 818 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
819 |
A document which has all pages with the same look except for the first |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
820 |
page may can be built using this special approach. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
821 |
""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
822 |
_invalidInitArgs = ('pageTemplates',) |
565 | 823 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
824 |
def handle_pageBegin(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
825 |
'''override base method to add a change of page template after the firstpage. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
826 |
''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
827 |
self._handle_pageBegin() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
828 |
self._handle_nextPageTemplate('Later') |
221 | 829 |
|
2488
8bc9673fffa6
doctemplate.py: support for canvasmaker and rotation
rgbecker
parents:
2466
diff
changeset
|
830 |
def build(self,flowables,onFirstPage=_doNothing, onLaterPages=_doNothing, canvasmaker=canvas.Canvas): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
831 |
"""build the document using the flowables. Annotate the first page using the onFirstPage |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
832 |
function and later pages using the onLaterPages function. The onXXX pages should follow |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
833 |
the signature |
1428 | 834 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
835 |
def myOnFirstPage(canvas, document): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
836 |
# do annotations and modify the document |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
837 |
... |
1428 | 838 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
839 |
The functions can do things like draw logos, page numbers, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
840 |
footers, etcetera. They can use external variables to vary |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
841 |
the look (for example providing page numbering or section names). |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
842 |
""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
843 |
self._calc() #in case we changed margins sizes etc |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
844 |
frameT = Frame(self.leftMargin, self.bottomMargin, self.width, self.height, id='normal') |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
845 |
self.addPageTemplates([PageTemplate(id='First',frames=frameT, onPage=onFirstPage,pagesize=self.pagesize), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
846 |
PageTemplate(id='Later',frames=frameT, onPage=onLaterPages,pagesize=self.pagesize)]) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
847 |
if onFirstPage is _doNothing and hasattr(self,'onFirstPage'): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
848 |
self.pageTemplates[0].beforeDrawPage = self.onFirstPage |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
849 |
if onLaterPages is _doNothing and hasattr(self,'onLaterPages'): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
850 |
self.pageTemplates[1].beforeDrawPage = self.onLaterPages |
2488
8bc9673fffa6
doctemplate.py: support for canvasmaker and rotation
rgbecker
parents:
2466
diff
changeset
|
851 |
BaseDocTemplate.build(self,flowables, canvasmaker=canvasmaker) |
512 | 852 |
|
565 | 853 |
|
1669 | 854 |
def progressCB(typ, value): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
855 |
"""Example prototype for progress monitoring. |
1669 | 856 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
857 |
This aims to provide info about what is going on |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
858 |
during a big job. It should enable, for example, a reasonably |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
859 |
smooth progress bar to be drawn. We design the argument |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
860 |
signature to be predictable and conducive to programming in |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
861 |
other (type safe) languages. If set, this will be called |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
862 |
repeatedly with pairs of values. The first is a string |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
863 |
indicating the type of call; the second is a numeric value. |
1669 | 864 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
865 |
typ 'STARTING', value = 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
866 |
typ 'SIZE_EST', value = numeric estimate of job size |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
867 |
typ 'PASS', value = number of this rendering pass |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
868 |
typ 'PROGRESS', value = number between 0 and SIZE_EST |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
869 |
typ 'PAGE', value = page number of page |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
870 |
type 'FINISHED', value = 0 |
1669 | 871 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
872 |
The sequence is |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
873 |
STARTING - always called once |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
874 |
SIZE_EST - always called once |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
875 |
PROGRESS - called often |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
876 |
PAGE - called often when page is emitted |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
877 |
FINISHED - called when really, really finished |
1683 | 878 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
879 |
some juggling is needed to accurately estimate numbers of |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
880 |
pages in pageDrawing mode. |
1669 | 881 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
882 |
NOTE: the SIZE_EST is a guess. It is possible that the |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
883 |
PROGRESS value may slightly exceed it, or may even step |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
884 |
back a little on rare occasions. The only way to be |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
885 |
really accurate would be to do two passes, and I don't |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
886 |
want to take that performance hit. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
887 |
""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
888 |
print 'PROGRESS MONITOR: %-10s %d' % (typ, value) |
1669 | 889 |
|
221 | 890 |
if __name__ == '__main__': |
891 |
||
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
892 |
def myFirstPage(canvas, doc): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
893 |
canvas.saveState() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
894 |
canvas.setStrokeColor(red) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
895 |
canvas.setLineWidth(5) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
896 |
canvas.line(66,72,66,PAGE_HEIGHT-72) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
897 |
canvas.setFont('Times-Bold',24) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
898 |
canvas.drawString(108, PAGE_HEIGHT-108, "TABLE OF CONTENTS DEMO") |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
899 |
canvas.setFont('Times-Roman',12) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
900 |
canvas.drawString(4 * inch, 0.75 * inch, "First Page") |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
901 |
canvas.restoreState() |
221 | 902 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
903 |
def myLaterPages(canvas, doc): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
904 |
canvas.saveState() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
905 |
canvas.setStrokeColor(red) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
906 |
canvas.setLineWidth(5) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
907 |
canvas.line(66,72,66,PAGE_HEIGHT-72) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
908 |
canvas.setFont('Times-Roman',12) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
909 |
canvas.drawString(4 * inch, 0.75 * inch, "Page %d" % doc.page) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
910 |
canvas.restoreState() |
221 | 911 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
912 |
def run(): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
913 |
objects_to_draw = [] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
914 |
from reportlab.lib.styles import ParagraphStyle |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
915 |
#from paragraph import Paragraph |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
916 |
from doctemplate import SimpleDocTemplate |
221 | 917 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
918 |
#need a style |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
919 |
normal = ParagraphStyle('normal') |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
920 |
normal.firstLineIndent = 18 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
921 |
normal.spaceBefore = 6 |
2083 | 922 |
from reportlab.lib.randomtext import randomText |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
923 |
import random |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
924 |
for i in range(15): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
925 |
height = 0.5 + (2*random.random()) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
926 |
box = XBox(6 * inch, height * inch, 'Box Number %d' % i) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
927 |
objects_to_draw.append(box) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
928 |
para = Paragraph(randomText(), normal) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
929 |
objects_to_draw.append(para) |
221 | 930 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
931 |
SimpleDocTemplate('doctemplate.pdf').build(objects_to_draw, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
932 |
onFirstPage=myFirstPage,onLaterPages=myLaterPages) |
221 | 933 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
934 |
run() |