author | robin |
Thu, 26 Sep 2019 13:44:55 +0100 | |
changeset 4530 | 3f6cc4ae6211 |
parent 4528 | e09377955af8 |
parent 4529 | 0e81d462d3b9 |
child 4551 | d357e2acc856 |
permissions | -rw-r--r-- |
4330 | 1 |
#Copyright ReportLab Europe Ltd. 2000-2017 |
494 | 2 |
#see license.txt for license details |
4528 | 3 |
#history https://hg.reportlab.com/hg-public/reportlab/log/tip/src/reportlab/platypus/doctemplate.py |
4502
86c084dcb3a2
add preliminary MultiCol implementation; version --> 3.5.20
robin <robin@reportlab.com>
parents:
4498
diff
changeset
|
4 |
__all__ = ( |
86c084dcb3a2
add preliminary MultiCol implementation; version --> 3.5.20
robin <robin@reportlab.com>
parents:
4498
diff
changeset
|
5 |
'ActionFlowable', |
86c084dcb3a2
add preliminary MultiCol implementation; version --> 3.5.20
robin <robin@reportlab.com>
parents:
4498
diff
changeset
|
6 |
'BaseDocTemplate', |
86c084dcb3a2
add preliminary MultiCol implementation; version --> 3.5.20
robin <robin@reportlab.com>
parents:
4498
diff
changeset
|
7 |
'CurrentFrameFlowable', |
86c084dcb3a2
add preliminary MultiCol implementation; version --> 3.5.20
robin <robin@reportlab.com>
parents:
4498
diff
changeset
|
8 |
'FrameActionFlowable', |
86c084dcb3a2
add preliminary MultiCol implementation; version --> 3.5.20
robin <robin@reportlab.com>
parents:
4498
diff
changeset
|
9 |
'FrameBreak', |
86c084dcb3a2
add preliminary MultiCol implementation; version --> 3.5.20
robin <robin@reportlab.com>
parents:
4498
diff
changeset
|
10 |
'Indenter', |
86c084dcb3a2
add preliminary MultiCol implementation; version --> 3.5.20
robin <robin@reportlab.com>
parents:
4498
diff
changeset
|
11 |
'IndexingFlowable', |
86c084dcb3a2
add preliminary MultiCol implementation; version --> 3.5.20
robin <robin@reportlab.com>
parents:
4498
diff
changeset
|
12 |
'LayoutError', |
86c084dcb3a2
add preliminary MultiCol implementation; version --> 3.5.20
robin <robin@reportlab.com>
parents:
4498
diff
changeset
|
13 |
'LCActionFlowable', |
86c084dcb3a2
add preliminary MultiCol implementation; version --> 3.5.20
robin <robin@reportlab.com>
parents:
4498
diff
changeset
|
14 |
'NextFrameFlowable', |
86c084dcb3a2
add preliminary MultiCol implementation; version --> 3.5.20
robin <robin@reportlab.com>
parents:
4498
diff
changeset
|
15 |
'NextPageTemplate', |
86c084dcb3a2
add preliminary MultiCol implementation; version --> 3.5.20
robin <robin@reportlab.com>
parents:
4498
diff
changeset
|
16 |
'NotAtTopPageBreak', |
86c084dcb3a2
add preliminary MultiCol implementation; version --> 3.5.20
robin <robin@reportlab.com>
parents:
4498
diff
changeset
|
17 |
'NullActionFlowable', |
86c084dcb3a2
add preliminary MultiCol implementation; version --> 3.5.20
robin <robin@reportlab.com>
parents:
4498
diff
changeset
|
18 |
'PageAccumulator', |
86c084dcb3a2
add preliminary MultiCol implementation; version --> 3.5.20
robin <robin@reportlab.com>
parents:
4498
diff
changeset
|
19 |
'PageBegin', |
86c084dcb3a2
add preliminary MultiCol implementation; version --> 3.5.20
robin <robin@reportlab.com>
parents:
4498
diff
changeset
|
20 |
'PageTemplate', |
86c084dcb3a2
add preliminary MultiCol implementation; version --> 3.5.20
robin <robin@reportlab.com>
parents:
4498
diff
changeset
|
21 |
'SimpleDocTemplate', |
86c084dcb3a2
add preliminary MultiCol implementation; version --> 3.5.20
robin <robin@reportlab.com>
parents:
4498
diff
changeset
|
22 |
) |
86c084dcb3a2
add preliminary MultiCol implementation; version --> 3.5.20
robin <robin@reportlab.com>
parents:
4498
diff
changeset
|
23 |
__version__='3.5.20' |
565 | 24 |
|
197 | 25 |
__doc__=""" |
268 | 26 |
This module contains the core structure of platypus. |
27 |
||
2762 | 28 |
rlatypus constructs documents. Document styles are determined by DocumentTemplates. |
268 | 29 |
|
30 |
Each DocumentTemplate contains one or more PageTemplates which defines the look of the |
|
31 |
pages of the document. |
|
32 |
||
33 |
Each PageTemplate has a procedure for drawing the "non-flowing" part of the page |
|
34 |
(for example the header, footer, page number, fixed logo graphic, watermark, etcetera) and |
|
35 |
a set of Frames which enclose the flowing part of the page (for example the paragraphs, |
|
36 |
tables, or non-fixed diagrams of the text). |
|
37 |
||
38 |
A document is built when a DocumentTemplate is fed a sequence of Flowables. |
|
39 |
The action of the build consumes the flowables in order and places them onto |
|
40 |
frames on pages as space allows. When a frame runs out of space the next frame |
|
41 |
of the page is used. If no frame remains a new page is created. A new page |
|
42 |
can also be created if a page break is forced. |
|
43 |
||
44 |
The special invisible flowable NextPageTemplate can be used to specify |
|
45 |
the page template for the next page (which by default is the one being used |
|
46 |
for the current frame). |
|
197 | 47 |
""" |
565 | 48 |
|
279 | 49 |
from reportlab.platypus.flowables import * |
4279
f69571262c74
fix fake KeepTogether setup in handle_keepWithNext; version--> 3.3.13
robin
parents:
4278
diff
changeset
|
50 |
from reportlab.platypus.flowables import _ContainerSpace |
2525 | 51 |
from reportlab.lib.units import inch |
279 | 52 |
from reportlab.platypus.paragraph import Paragraph |
53 |
from reportlab.platypus.frames import Frame |
|
1530 | 54 |
from reportlab.rl_config import defaultPageSize, verbose |
279 | 55 |
import reportlab.lib.sequencer |
2525 | 56 |
from reportlab.pdfgen import canvas |
4018
c69c31436936
doctemplate.py: use annotateException & allow page templates to be any string type
robin
parents:
3975
diff
changeset
|
57 |
from reportlab.lib.utils import isSeq, encode_label, decode_label, annotateException, strTypes |
4367
9960d82643bf
remove ascii, cmp & xrange builtins abuse; version-->3.4.15
robin <robin@reportlab.com>
parents:
4347
diff
changeset
|
58 |
from reportlab import ascii |
4184 | 59 |
|
3083 | 60 |
try: |
61 |
set |
|
62 |
except NameError: |
|
63 |
from sets import Set as set |
|
565 | 64 |
|
197 | 65 |
import sys |
2500 | 66 |
import logging |
67 |
logger = logging.getLogger("reportlab.platypus") |
|
197 | 68 |
|
2192 | 69 |
class LayoutError(Exception): |
70 |
pass |
|
565 | 71 |
|
3131
0f15fabe9d8d
reportlab: improve information in doctemplate overflow error
rgbecker
parents:
3129
diff
changeset
|
72 |
def _fSizeString(f): |
3523 | 73 |
#used to get size during error messages |
3131
0f15fabe9d8d
reportlab: improve information in doctemplate overflow error
rgbecker
parents:
3129
diff
changeset
|
74 |
w=getattr(f,'width',None) |
0f15fabe9d8d
reportlab: improve information in doctemplate overflow error
rgbecker
parents:
3129
diff
changeset
|
75 |
if w is None: |
0f15fabe9d8d
reportlab: improve information in doctemplate overflow error
rgbecker
parents:
3129
diff
changeset
|
76 |
w=getattr(f,'_width',None) |
0f15fabe9d8d
reportlab: improve information in doctemplate overflow error
rgbecker
parents:
3129
diff
changeset
|
77 |
|
0f15fabe9d8d
reportlab: improve information in doctemplate overflow error
rgbecker
parents:
3129
diff
changeset
|
78 |
h=getattr(f,'height',None) |
0f15fabe9d8d
reportlab: improve information in doctemplate overflow error
rgbecker
parents:
3129
diff
changeset
|
79 |
if h is None: |
0f15fabe9d8d
reportlab: improve information in doctemplate overflow error
rgbecker
parents:
3129
diff
changeset
|
80 |
h=getattr(f,'_height',None) |
3523 | 81 |
#tables in particular may have some nasty large culprit |
82 |
if hasattr(f, '_culprit'): |
|
83 |
c = ', %s, ' % f._culprit() |
|
84 |
else: |
|
85 |
c = '' |
|
3131
0f15fabe9d8d
reportlab: improve information in doctemplate overflow error
rgbecker
parents:
3129
diff
changeset
|
86 |
if w is not None or h is not None: |
0f15fabe9d8d
reportlab: improve information in doctemplate overflow error
rgbecker
parents:
3129
diff
changeset
|
87 |
if w is None: w='???' |
0f15fabe9d8d
reportlab: improve information in doctemplate overflow error
rgbecker
parents:
3129
diff
changeset
|
88 |
if h is None: h='???' |
3523 | 89 |
return '(%s x %s)%s' % (w,h,c) |
3131
0f15fabe9d8d
reportlab: improve information in doctemplate overflow error
rgbecker
parents:
3129
diff
changeset
|
90 |
return '' |
0f15fabe9d8d
reportlab: improve information in doctemplate overflow error
rgbecker
parents:
3129
diff
changeset
|
91 |
|
253 | 92 |
def _doNothing(canvas, doc): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
93 |
"Dummy callback for onPage" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
94 |
pass |
512 | 95 |
|
2661
e179247ffea3
platypus: add * as shortcircuit template cycle notation
rgbecker
parents:
2654
diff
changeset
|
96 |
class PTCycle(list): |
4145
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
97 |
def __new__(cls,*args,**kwds): |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
98 |
self = list.__new__(cls,*args,**kwds) |
2661
e179247ffea3
platypus: add * as shortcircuit template cycle notation
rgbecker
parents:
2654
diff
changeset
|
99 |
self._restart = 0 |
e179247ffea3
platypus: add * as shortcircuit template cycle notation
rgbecker
parents:
2654
diff
changeset
|
100 |
self._idx = 0 |
4145
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
101 |
return self |
2661
e179247ffea3
platypus: add * as shortcircuit template cycle notation
rgbecker
parents:
2654
diff
changeset
|
102 |
|
4145
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
103 |
@property |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
104 |
def next_value(self): |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
105 |
v = self[self._idx] |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
106 |
self._idx += 1 |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
107 |
if self._idx>=len(self): |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
108 |
self._idx = self._restart |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
109 |
return v |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
110 |
|
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
111 |
@property |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
112 |
def peek(self): |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
113 |
return self[self._idx] |
565 | 114 |
|
1440
243d35446390
Removed 0 from multiBuild stuff prior to further changes;
andy_robinson
parents:
1428
diff
changeset
|
115 |
class IndexingFlowable(Flowable): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
116 |
"""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
|
117 |
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
|
118 |
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
|
119 |
Indexes etc.""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
120 |
def isIndexing(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
121 |
return 1 |
512 | 122 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
123 |
def isSatisfied(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
124 |
return 1 |
512 | 125 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
126 |
def notify(self, kind, stuff): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
127 |
"""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
|
128 |
'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
|
129 |
pay attention or not.""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
130 |
pass |
512 | 131 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
132 |
def beforeBuild(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
133 |
"""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
|
134 |
old contents""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
135 |
pass |
1428 | 136 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
137 |
def afterBuild(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
138 |
"""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
|
139 |
pass |
253 | 140 |
|
197 | 141 |
class ActionFlowable(Flowable): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
142 |
'''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
|
143 |
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
|
144 |
use NextPageTemplate which creates an ActionFlowable. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
145 |
''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
146 |
def __init__(self,action=()): |
2575 | 147 |
#must call super init to ensure it has a width and height (of zero), |
148 |
#as in some cases the packer might get called on it... |
|
149 |
Flowable.__init__(self) |
|
3731 | 150 |
if not isSeq(action): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
151 |
action = (action,) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
152 |
self.action = tuple(action) |
197 | 153 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
154 |
def apply(self,doc): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
155 |
''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
156 |
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
|
157 |
implement its behaviour |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
158 |
''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
159 |
action = self.action[0] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
160 |
args = tuple(self.action[1:]) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
161 |
arn = 'handle_'+action |
2762 | 162 |
if arn=="handle_nextPageTemplate" and args[0]=='main': |
163 |
pass |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
164 |
try: |
2762 | 165 |
getattr(doc,arn)(*args) |
3721 | 166 |
except AttributeError as aerr: |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
167 |
if aerr.args[0]==arn: |
3721 | 168 |
raise NotImplementedError("Can't handle ActionFlowable(%s)" % action) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
169 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
170 |
raise |
3175
bf81f5b13ba8
doctemplate.py: fix bogus exception and allow for build keyword args in multibuild
rgbecker
parents:
3161
diff
changeset
|
171 |
except: |
4018
c69c31436936
doctemplate.py: use annotateException & allow page templates to be any string type
robin
parents:
3975
diff
changeset
|
172 |
annotateException("\nhandle_%s args=%s"%(action,ascii(args))) |
197 | 173 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
174 |
def __call__(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
175 |
return self |
218
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
176 |
|
2192 | 177 |
def identity(self, maxLen=None): |
2531 | 178 |
return "ActionFlowable: %s%s" % (str(self.action),self._frameName()) |
2200
be0cfccc662a
Fixed up tabs and whitespace in all source files
andy_robinson
parents:
2196
diff
changeset
|
179 |
|
4278
5aa80e7cdba8
add NullActionFlowable, fix empty KeepTogether, version-->3.3.12
robin
parents:
4252
diff
changeset
|
180 |
class NullActionFlowable(ActionFlowable): |
5aa80e7cdba8
add NullActionFlowable, fix empty KeepTogether, version-->3.3.12
robin
parents:
4252
diff
changeset
|
181 |
'''an ActionFlowable that does nothing''' |
5aa80e7cdba8
add NullActionFlowable, fix empty KeepTogether, version-->3.3.12
robin
parents:
4252
diff
changeset
|
182 |
def apply(self,doc): |
5aa80e7cdba8
add NullActionFlowable, fix empty KeepTogether, version-->3.3.12
robin
parents:
4252
diff
changeset
|
183 |
pass |
5aa80e7cdba8
add NullActionFlowable, fix empty KeepTogether, version-->3.3.12
robin
parents:
4252
diff
changeset
|
184 |
|
2449
47b15f941325
platypus: attempt to make KeepTogether/keepWithNext more robust
rgbecker
parents:
2418
diff
changeset
|
185 |
class LCActionFlowable(ActionFlowable): |
47b15f941325
platypus: attempt to make KeepTogether/keepWithNext more robust
rgbecker
parents:
2418
diff
changeset
|
186 |
locChanger = 1 #we cause a frame or page change |
47b15f941325
platypus: attempt to make KeepTogether/keepWithNext more robust
rgbecker
parents:
2418
diff
changeset
|
187 |
|
2450 | 188 |
def wrap(self, availWidth, availHeight): |
189 |
'''Should never be called.''' |
|
4279
f69571262c74
fix fake KeepTogether setup in handle_keepWithNext; version--> 3.3.13
robin
parents:
4278
diff
changeset
|
190 |
raise NotImplementedError('%s.wrap should never be called' % self.__class__.__name__) |
2450 | 191 |
|
192 |
def draw(self): |
|
193 |
'''Should never be called.''' |
|
4279
f69571262c74
fix fake KeepTogether setup in handle_keepWithNext; version--> 3.3.13
robin
parents:
4278
diff
changeset
|
194 |
raise NotImplementedError('%s.draw should never be called' % self.__class__.__name__) |
2450 | 195 |
|
1324 | 196 |
class NextFrameFlowable(ActionFlowable): |
4279
f69571262c74
fix fake KeepTogether setup in handle_keepWithNext; version--> 3.3.13
robin
parents:
4278
diff
changeset
|
197 |
locChanger = 1 #we cause a frame or page change |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
198 |
def __init__(self,ix,resume=0): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
199 |
ActionFlowable.__init__(self,('nextFrame',ix,resume)) |
565 | 200 |
|
2449
47b15f941325
platypus: attempt to make KeepTogether/keepWithNext more robust
rgbecker
parents:
2418
diff
changeset
|
201 |
class CurrentFrameFlowable(LCActionFlowable): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
202 |
def __init__(self,ix,resume=0): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
203 |
ActionFlowable.__init__(self,('currentFrame',ix,resume)) |
1324 | 204 |
|
2575 | 205 |
class NullActionFlowable(ActionFlowable): |
3095
65e60a3bc048
doctemplate.py: standardize NullActionFlowable apply (bug fix from Hans Brand hans at marcans.nl)
rgbecker
parents:
3083
diff
changeset
|
206 |
def apply(self,doc): |
2575 | 207 |
pass |
208 |
||
2449
47b15f941325
platypus: attempt to make KeepTogether/keepWithNext more robust
rgbecker
parents:
2418
diff
changeset
|
209 |
class _FrameBreak(LCActionFlowable): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
210 |
''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
211 |
A special ActionFlowable that allows setting doc._nextFrameIndex |
1324 | 212 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
213 |
eg story.append(FrameBreak('mySpecialFrame')) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
214 |
''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
215 |
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
|
216 |
r = self.__class__(self.action+(resume,)) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
217 |
r._ix = ix |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
218 |
return r |
1324 | 219 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
220 |
def apply(self,doc): |
2529
dced304f8584
flowables.py: keepInFrame now truncates etc properly, doctemplate.py: fix handle_frameEnd
rgbecker
parents:
2525
diff
changeset
|
221 |
if getattr(self,'_ix',None): |
dced304f8584
flowables.py: keepInFrame now truncates etc properly, doctemplate.py: fix handle_frameEnd
rgbecker
parents:
2525
diff
changeset
|
222 |
doc.handle_nextFrame(self._ix) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
223 |
ActionFlowable.apply(self,doc) |
1324 | 224 |
|
225 |
FrameBreak = _FrameBreak('frameEnd') |
|
2449
47b15f941325
platypus: attempt to make KeepTogether/keepWithNext more robust
rgbecker
parents:
2418
diff
changeset
|
226 |
PageBegin = LCActionFlowable('pageBegin') |
197 | 227 |
|
2366 | 228 |
def _evalMeasurement(n): |
3731 | 229 |
if isinstance(n,str): |
3975
4a3599863c11
eliminate from . imports in favour of absolutes to allow running modules
robin
parents:
3884
diff
changeset
|
230 |
from reportlab.platypus.paraparser import _num |
2366 | 231 |
n = _num(n) |
3731 | 232 |
if isSeq(n): n = n[1] |
2366 | 233 |
return n |
234 |
||
2525 | 235 |
class FrameActionFlowable(Flowable): |
2762 | 236 |
_fixedWidth = _fixedHeight = 1 |
2525 | 237 |
def __init__(self,*arg,**kw): |
4279
f69571262c74
fix fake KeepTogether setup in handle_keepWithNext; version--> 3.3.13
robin
parents:
4278
diff
changeset
|
238 |
raise NotImplementedError('%s.__init__ should never be called for abstract Class'%self.__class__.__name__) |
2525 | 239 |
|
240 |
def frameAction(self,frame): |
|
4279
f69571262c74
fix fake KeepTogether setup in handle_keepWithNext; version--> 3.3.13
robin
parents:
4278
diff
changeset
|
241 |
raise NotImplementedError('%s.frameAction should never be called for abstract Class'%self.__class__.__name__) |
2525 | 242 |
|
243 |
class Indenter(FrameActionFlowable): |
|
1923 | 244 |
"""Increases or decreases left and right margins of frame. |
245 |
||
246 |
This allows one to have a 'context-sensitive' indentation |
|
247 |
and makes nested lists way easier. |
|
2200
be0cfccc662a
Fixed up tabs and whitespace in all source files
andy_robinson
parents:
2196
diff
changeset
|
248 |
""" |
3686 | 249 |
_ZEROSIZE=True |
250 |
width=0 |
|
251 |
height=0 |
|
1923 | 252 |
def __init__(self, left=0, right=0): |
2366 | 253 |
self.left = _evalMeasurement(left) |
254 |
self.right = _evalMeasurement(right) |
|
1923 | 255 |
|
2525 | 256 |
def frameAction(self, frame): |
257 |
frame._leftExtraIndent += self.left |
|
258 |
frame._rightExtraIndent += self.right |
|
512 | 259 |
|
2762 | 260 |
class NotAtTopPageBreak(FrameActionFlowable): |
4279
f69571262c74
fix fake KeepTogether setup in handle_keepWithNext; version--> 3.3.13
robin
parents:
4278
diff
changeset
|
261 |
locChanger = 1 #we cause a frame or page change |
4145
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
262 |
def __init__(self,nextTemplate=None): |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
263 |
self.nextTemplate = nextTemplate |
2762 | 264 |
|
265 |
def frameAction(self,frame): |
|
266 |
if not frame._atTop: |
|
4145
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
267 |
frame.add_generated_content(PageBreak(nextTemplate=self.nextTemplate)) |
2762 | 268 |
|
197 | 269 |
class NextPageTemplate(ActionFlowable): |
4279
f69571262c74
fix fake KeepTogether setup in handle_keepWithNext; version--> 3.3.13
robin
parents:
4278
diff
changeset
|
270 |
locChanger = 1 #we cause a frame or page change |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
271 |
"""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
|
272 |
def __init__(self,pt): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
273 |
ActionFlowable.__init__(self,('nextPageTemplate',pt)) |
197 | 274 |
|
275 |
class PageTemplate: |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
276 |
""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
277 |
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
|
278 |
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
|
279 |
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
|
280 |
""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
281 |
def __init__(self,id=None,frames=[],onPage=_doNothing, onPageEnd=_doNothing, |
4212
c903815560d1
add support for crop/art/trim/bleed boxes; version --> 3.2.2
robin
parents:
4211
diff
changeset
|
282 |
pagesize=None, autoNextPageTemplate=None, |
c903815560d1
add support for crop/art/trim/bleed boxes; version --> 3.2.2
robin
parents:
4211
diff
changeset
|
283 |
cropBox=None, |
c903815560d1
add support for crop/art/trim/bleed boxes; version --> 3.2.2
robin
parents:
4211
diff
changeset
|
284 |
artBox=None, |
c903815560d1
add support for crop/art/trim/bleed boxes; version --> 3.2.2
robin
parents:
4211
diff
changeset
|
285 |
trimBox=None, |
c903815560d1
add support for crop/art/trim/bleed boxes; version --> 3.2.2
robin
parents:
4211
diff
changeset
|
286 |
bleedBox=None, |
c903815560d1
add support for crop/art/trim/bleed boxes; version --> 3.2.2
robin
parents:
4211
diff
changeset
|
287 |
): |
3272
10f6899a18a5
reportlab: attempt to eliminate empty list argument issues bug contributed by Tim Roberts and Nate Silva
rgbecker
parents:
3241
diff
changeset
|
288 |
frames = frames or [] |
3731 | 289 |
if not isSeq(frames): frames = [frames] |
3721 | 290 |
assert [x for x in frames if not isinstance(x,Frame)]==[], "frames argument error" |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
291 |
self.id = id |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
292 |
self.frames = frames |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
293 |
self.onPage = onPage |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
294 |
self.onPageEnd = onPageEnd |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
295 |
self.pagesize = pagesize |
3563
3ba0d95480c9
doctemplate.py added support for PageTemplate.autoNextPageTemplate
rgbecker
parents:
3528
diff
changeset
|
296 |
self.autoNextPageTemplate = autoNextPageTemplate |
4212
c903815560d1
add support for crop/art/trim/bleed boxes; version --> 3.2.2
robin
parents:
4211
diff
changeset
|
297 |
self.cropBox = cropBox |
c903815560d1
add support for crop/art/trim/bleed boxes; version --> 3.2.2
robin
parents:
4211
diff
changeset
|
298 |
self.artBox = artBox |
c903815560d1
add support for crop/art/trim/bleed boxes; version --> 3.2.2
robin
parents:
4211
diff
changeset
|
299 |
self.trimBox = trimBox |
c903815560d1
add support for crop/art/trim/bleed boxes; version --> 3.2.2
robin
parents:
4211
diff
changeset
|
300 |
self.bleedBox = bleedBox |
512 | 301 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
302 |
def beforeDrawPage(self,canv,doc): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
303 |
"""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
|
304 |
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
|
305 |
this page are processed.""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
306 |
pass |
197 | 307 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
308 |
def checkPageSize(self,canv,doc): |
2688
f9c4d1488516
doctemplate: apply T Heller's fix emacs syntax colouring patch
rgbecker
parents:
2672
diff
changeset
|
309 |
"""This gets called by the template framework |
1926 | 310 |
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
|
311 |
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
|
312 |
doc size. |
2688
f9c4d1488516
doctemplate: apply T Heller's fix emacs syntax colouring patch
rgbecker
parents:
2672
diff
changeset
|
313 |
""" |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
314 |
#### 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
|
315 |
#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
|
316 |
#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
|
317 |
cp = None |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
318 |
dp = None |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
319 |
sp = None |
3721 | 320 |
if canv._pagesize: cp = list(map(int, canv._pagesize)) |
321 |
if self.pagesize: sp = list(map(int, self.pagesize)) |
|
322 |
if doc.pagesize: dp = list(map(int, doc.pagesize)) |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
323 |
if cp!=sp: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
324 |
if sp: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
325 |
canv.setPageSize(self.pagesize) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
326 |
elif cp!=dp: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
327 |
canv.setPageSize(doc.pagesize) |
4212
c903815560d1
add support for crop/art/trim/bleed boxes; version --> 3.2.2
robin
parents:
4211
diff
changeset
|
328 |
for box in 'crop','art','trim','bleed': |
c903815560d1
add support for crop/art/trim/bleed boxes; version --> 3.2.2
robin
parents:
4211
diff
changeset
|
329 |
size = getattr(self,box+'Box',None) |
c903815560d1
add support for crop/art/trim/bleed boxes; version --> 3.2.2
robin
parents:
4211
diff
changeset
|
330 |
if size: |
c903815560d1
add support for crop/art/trim/bleed boxes; version --> 3.2.2
robin
parents:
4211
diff
changeset
|
331 |
canv.setCropBox(size,name=box) |
936 | 332 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
333 |
def afterDrawPage(self, canv, doc): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
334 |
"""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
|
335 |
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
|
336 |
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
|
337 |
this page.""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
338 |
pass |
1428 | 339 |
|
3009 | 340 |
def _addGeneratedContent(flowables,frame): |
341 |
S = getattr(frame,'_generated_content',None) |
|
4121
3b9e6fa286ad
tableofcontents.py, doctemplate.py: fix indexing page number ordering bug found by Greg Jones bitbucket issue #40
robin
parents:
4067
diff
changeset
|
342 |
if S: |
3323
8fe71f699df9
doctemplate.py: fix bug in order of split[0] generated content contributed by Robert Hölzl <robert.hoelzl@baltech.de>
rgbecker
parents:
3272
diff
changeset
|
343 |
flowables[0:0] = S |
3009 | 344 |
del frame._generated_content |
345 |
||
3241
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
346 |
class onDrawStr(str): |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
347 |
def __new__(cls,value,onDraw,label,kind=None): |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
348 |
self = str.__new__(cls,value) |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
349 |
self.onDraw = onDraw |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
350 |
self.kind = kind |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
351 |
self.label = label |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
352 |
return self |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
353 |
|
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
354 |
class PageAccumulator: |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
355 |
'''gadget to accumulate information in a page |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
356 |
and then allow it to be interrogated at the end |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
357 |
of the page''' |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
358 |
_count = 0 |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
359 |
def __init__(self,name=None): |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
360 |
if name is None: |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
361 |
name = self.__class__.__name__+str(self.__class__._count) |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
362 |
self.__class__._count += 1 |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
363 |
self.name = name |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
364 |
self.data = [] |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
365 |
|
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
366 |
def reset(self): |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
367 |
self.data[:] = [] |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
368 |
|
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
369 |
def add(self,*args): |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
370 |
self.data.append(args) |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
371 |
|
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
372 |
def onDrawText(self,*args): |
3850 | 373 |
return '<onDraw name="%s" label="%s" />' % (self.name,encode_label(args)) |
3241
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
374 |
|
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
375 |
def __call__(self,canv,kind,label): |
3850 | 376 |
self.add(*decode_label(label)) |
3241
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
377 |
|
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
378 |
def attachToPageTemplate(self,pt): |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
379 |
if pt.onPage: |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
380 |
def onPage(canv,doc,oop=pt.onPage): |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
381 |
self.onPage(canv,doc) |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
382 |
oop(canv,doc) |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
383 |
else: |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
384 |
def onPage(canv,doc): |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
385 |
self.onPage(canv,doc) |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
386 |
pt.onPage = onPage |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
387 |
if pt.onPageEnd: |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
388 |
def onPageEnd(canv,doc,oop=pt.onPageEnd): |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
389 |
self.onPageEnd(canv,doc) |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
390 |
oop(canv,doc) |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
391 |
else: |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
392 |
def onPageEnd(canv,doc): |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
393 |
self.onPageEnd(canv,doc) |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
394 |
pt.onPageEnd = onPageEnd |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
395 |
|
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
396 |
def onPage(self,canv,doc): |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
397 |
'''this will be called at the start of the page''' |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
398 |
setattr(canv,self.name,self) #push ourselves onto the canvas |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
399 |
self.reset() |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
400 |
|
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
401 |
def onPageEnd(self,canv,doc): |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
402 |
'''this will be called at the end of a page''' |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
403 |
self.pageEndAction(canv,doc) |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
404 |
try: |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
405 |
delattr(canv,self.name) |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
406 |
except: |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
407 |
pass |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
408 |
self.reset() |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
409 |
|
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
410 |
def pageEndAction(self,canv,doc): |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
411 |
'''this should be overridden to do something useful''' |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
412 |
pass |
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
413 |
|
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
414 |
def onDrawStr(self,value,*args): |
3850 | 415 |
return onDrawStr(value,self,encode_label(args)) |
3241
575302ed6ab9
doctemplate.py : add PageAccumulator class and support in tables.py
rgbecker
parents:
3175
diff
changeset
|
416 |
|
4279
f69571262c74
fix fake KeepTogether setup in handle_keepWithNext; version--> 3.3.13
robin
parents:
4278
diff
changeset
|
417 |
def _ktAllow(f): |
f69571262c74
fix fake KeepTogether setup in handle_keepWithNext; version--> 3.3.13
robin
parents:
4278
diff
changeset
|
418 |
'''return true if allowed in containers like KeepTogether''' |
f69571262c74
fix fake KeepTogether setup in handle_keepWithNext; version--> 3.3.13
robin
parents:
4278
diff
changeset
|
419 |
return not (isinstance(f,(_ContainerSpace,DocIf,DocWhile)) or getattr(f,'locChanger',False)) |
f69571262c74
fix fake KeepTogether setup in handle_keepWithNext; version--> 3.3.13
robin
parents:
4278
diff
changeset
|
420 |
|
512 | 421 |
class BaseDocTemplate: |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
422 |
""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
423 |
First attempt at defining a document template class. |
512 | 424 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
425 |
The basic idea is simple. |
4121
3b9e6fa286ad
tableofcontents.py, doctemplate.py: fix indexing page number ordering bug found by Greg Jones bitbucket issue #40
robin
parents:
4067
diff
changeset
|
426 |
|
3031 | 427 |
1) The document has a list of data associated with it |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
428 |
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
|
429 |
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
|
430 |
like forcing a page end etc. |
512 | 431 |
|
3031 | 432 |
2) The document has one or more page templates. |
512 | 433 |
|
3031 | 434 |
3) Each page template has one or more frames. |
512 | 435 |
|
3031 | 436 |
4) The document class provides base methods for handling the |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
437 |
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
|
438 |
story flowables into the frames. |
214 | 439 |
|
3031 | 440 |
5) The document instances can override the base handler routines. |
1428 | 441 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
442 |
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
|
443 |
but in some advanced usages they may need to be overridden via subclassing. |
1428 | 444 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
445 |
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
|
446 |
since it builds a document using the page template. |
1428 | 447 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
448 |
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
|
449 |
by the filename argument on initialization. |
197 | 450 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
451 |
Possible keyword arguments for the initialization: |
1428 | 452 |
|
3031 | 453 |
- pageTemplates: A list of templates. Must be nonempty. Names |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
454 |
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
|
455 |
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
|
456 |
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
|
457 |
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
|
458 |
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
|
459 |
using the addPageTemplates method before the document is built. |
3031 | 460 |
- pageSize: a 2-tuple or a size constant from reportlab/lib/pagesizes.pu. |
461 |
Used by the SimpleDocTemplate subclass which does NOT accept a list of |
|
462 |
pageTemplates but makes one for you; ignored when using pageTemplates. |
|
2216 | 463 |
|
3031 | 464 |
- showBoundary: if set draw a box around the frame boundaries. |
465 |
- leftMargin: |
|
466 |
- rightMargin: |
|
467 |
- topMargin: |
|
468 |
- bottomMargin: Margin sizes in points (default 1 inch). These margins may be |
|
469 |
overridden by the pageTemplates. They are primarily of interest for the |
|
470 |
SimpleDocumentTemplate subclass. |
|
4121
3b9e6fa286ad
tableofcontents.py, doctemplate.py: fix indexing page number ordering bug found by Greg Jones bitbucket issue #40
robin
parents:
4067
diff
changeset
|
471 |
|
3031 | 472 |
- allowSplitting: If set flowables (eg, paragraphs) may be split across frames or pages |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
473 |
(default: 1) |
3031 | 474 |
- title: Internal title for document (does not automatically display on any page) |
475 |
- author: Internal author for document (does not automatically display on any page) |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
476 |
""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
477 |
_initArgs = { 'pagesize':defaultPageSize, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
478 |
'pageTemplates':[], |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
479 |
'showBoundary':0, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
480 |
'leftMargin':inch, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
481 |
'rightMargin':inch, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
482 |
'topMargin':inch, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
483 |
'bottomMargin':inch, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
484 |
'allowSplitting':1, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
485 |
'title':None, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
486 |
'author':None, |
2666 | 487 |
'subject':None, |
3456 | 488 |
'creator':None, |
4498
fe619935e3ea
allow setting producer; version --> 3.5.19
robin <robin@reportlab.com>
parents:
4492
diff
changeset
|
489 |
'producer':None, |
2666 | 490 |
'keywords':[], |
1839
084e4af662dc
Passing invariant argument through to canvas
andy_robinson
parents:
1838
diff
changeset
|
491 |
'invariant':None, |
2531 | 492 |
'pageCompression':None, |
2492
8142a1737889
doctemplate.py: add rotation argument to BaseDocTemplate
rgbecker
parents:
2491
diff
changeset
|
493 |
'_pageBreakQuick':1, |
2531 | 494 |
'rotation':0, |
3040 | 495 |
'_debug':0, |
3110 | 496 |
'encrypt': None, |
497 |
'cropMarks': None, |
|
3443
64d1fba94908
reportlab: added preliminary support for enforcing color spaces
rgbecker
parents:
3384
diff
changeset
|
498 |
'enforceColorSpace': None, |
4183 | 499 |
'displayDocTitle': None, |
4184 | 500 |
'lang': None, |
4211
464df39467fc
add doctemplate support for intialFontName/Size/Leading, version --> 3.2.1
robin
parents:
4184
diff
changeset
|
501 |
'initialFontName': None, |
464df39467fc
add doctemplate support for intialFontName/Size/Leading, version --> 3.2.1
robin
parents:
4184
diff
changeset
|
502 |
'initialFontSize': None, |
464df39467fc
add doctemplate support for intialFontName/Size/Leading, version --> 3.2.1
robin
parents:
4184
diff
changeset
|
503 |
'initialLeading': None, |
4212
c903815560d1
add support for crop/art/trim/bleed boxes; version --> 3.2.2
robin
parents:
4211
diff
changeset
|
504 |
'cropBox': None, |
c903815560d1
add support for crop/art/trim/bleed boxes; version --> 3.2.2
robin
parents:
4211
diff
changeset
|
505 |
'artBox': None, |
c903815560d1
add support for crop/art/trim/bleed boxes; version --> 3.2.2
robin
parents:
4211
diff
changeset
|
506 |
'trimBox': None, |
c903815560d1
add support for crop/art/trim/bleed boxes; version --> 3.2.2
robin
parents:
4211
diff
changeset
|
507 |
'bleedBox': None, |
4380
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
508 |
'keepTogetherClass': KeepTogether, |
3110 | 509 |
} |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
510 |
_invalidInitArgs = () |
2104 | 511 |
_firstPageTemplateIndex = 0 |
197 | 512 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
513 |
def __init__(self, filename, **kw): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
514 |
"""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
|
515 |
self.filename = filename |
2955 | 516 |
self._nameSpace = dict(doc=self) |
517 |
self._lifetimes = {} |
|
512 | 518 |
|
3723
99aa837b6703
second stage of port to Python 3.3; working hello world
rptlab
parents:
3721
diff
changeset
|
519 |
for k in self._initArgs.keys(): |
3326 | 520 |
if k not in kw: |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
521 |
v = self._initArgs[k] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
522 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
523 |
if k in self._invalidInitArgs: |
3721 | 524 |
raise ValueError("Invalid argument %s" % k) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
525 |
v = kw[k] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
526 |
setattr(self,k,v) |
310 | 527 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
528 |
p = self.pageTemplates |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
529 |
self.pageTemplates = [] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
530 |
self.addPageTemplates(p) |
1428 | 531 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
532 |
# 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
|
533 |
# 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
|
534 |
# 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
|
535 |
# passed to indexing flowables. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
536 |
self._pageRefs = {} |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
537 |
self._indexingFlowables = [] |
512 | 538 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
539 |
#callback facility for progress monitoring |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
540 |
self._onPage = None |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
541 |
self._onProgress = None |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
542 |
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
|
543 |
|
2192 | 544 |
#infinite loop detection if we start doing lots of empty pages |
545 |
self._curPageFlowableCount = 0 |
|
546 |
self._emptyPages = 0 |
|
2193 | 547 |
self._emptyPagesAllowed = 10 |
2192 | 548 |
|
1923 | 549 |
#context sensitive margins - set by story, not from outside |
550 |
self._leftExtraIndent = 0.0 |
|
551 |
self._rightExtraIndent = 0.0 |
|
4228
fd5bbccc7758
add support from simple auto top of frame flowables version-->3.2.9
robin
parents:
4212
diff
changeset
|
552 |
self._topFlowables = [] |
4347
761e190b40af
added SetPageTopFlowables; version --> 3.4.6
robin <robin@reportlab.com>
parents:
4346
diff
changeset
|
553 |
self._pageTopFlowables = [] |
3760
674899ebab37
platypus: FrameBG related stuff ifrom default that got lost somehow
robin
parents:
3731
diff
changeset
|
554 |
self._frameBGs = [] |
2200
be0cfccc662a
Fixed up tabs and whitespace in all source files
andy_robinson
parents:
2196
diff
changeset
|
555 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
556 |
self._calc() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
557 |
self.afterInit() |
1502 | 558 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
559 |
def _calc(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
560 |
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
|
561 |
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
|
562 |
self.width = self._rightMargin - self.leftMargin |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
563 |
self.height = self._topMargin - self.bottomMargin |
1502 | 564 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
565 |
def setPageCallBack(self, func): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
566 |
'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
|
567 |
self._onPage = func |
197 | 568 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
569 |
def setProgressCallBack(self, func): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
570 |
'''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
|
571 |
self._onProgress = func |
1668
448a9205be12
Provision for callback progress monitoring in basic doctemplate class
andy_robinson
parents:
1530
diff
changeset
|
572 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
573 |
def clean_hanging(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
574 |
'handle internal postponed actions' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
575 |
while len(self._hanging): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
576 |
self.handle_flowable(self._hanging) |
1428 | 577 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
578 |
def addPageTemplates(self,pageTemplates): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
579 |
'add one or a sequence of pageTemplates' |
3731 | 580 |
if not isSeq(pageTemplates): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
581 |
pageTemplates = [pageTemplates] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
582 |
#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
|
583 |
#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
|
584 |
for t in pageTemplates: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
585 |
self.pageTemplates.append(t) |
1502 | 586 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
587 |
def handle_documentBegin(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
588 |
'''implement actions at beginning of document''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
589 |
self._hanging = [PageBegin] |
2104 | 590 |
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
|
591 |
self.page = 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
592 |
self.beforeDocument() |
253 | 593 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
594 |
def handle_pageBegin(self): |
2688
f9c4d1488516
doctemplate: apply T Heller's fix emacs syntax colouring patch
rgbecker
parents:
2672
diff
changeset
|
595 |
"""Perform actions required at beginning of page. |
f9c4d1488516
doctemplate: apply T Heller's fix emacs syntax colouring patch
rgbecker
parents:
2672
diff
changeset
|
596 |
shouldn't normally be called directly""" |
2593
3adaab508968
reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents:
2575
diff
changeset
|
597 |
self.page += 1 |
2531 | 598 |
if self._debug: logger.debug("beginning page %d" % self.page) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
599 |
self.pageTemplate.beforeDrawPage(self.canv,self) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
600 |
self.pageTemplate.checkPageSize(self.canv,self) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
601 |
self.pageTemplate.onPage(self.canv,self) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
602 |
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
|
603 |
self.beforePage() |
2192 | 604 |
#keep a count of flowables added to this page. zero indicates bad stuff |
605 |
self._curPageFlowableCount = 0 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
606 |
if hasattr(self,'_nextFrameIndex'): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
607 |
del self._nextFrameIndex |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
608 |
self.frame = self.pageTemplate.frames[0] |
2531 | 609 |
self.frame._debug = self._debug |
4347
761e190b40af
added SetPageTopFlowables; version --> 3.4.6
robin <robin@reportlab.com>
parents:
4346
diff
changeset
|
610 |
self.handle_frameBegin(pageTopFlowables=self._pageTopFlowables) |
197 | 611 |
|
4145
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
612 |
def _setPageTemplate(self): |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
613 |
if hasattr(self,'_nextPageTemplateCycle'): |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
614 |
#they are cycling through pages'; we keep the index |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
615 |
self.pageTemplate = self._nextPageTemplateCycle.next_value |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
616 |
elif hasattr(self,'_nextPageTemplateIndex'): |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
617 |
self.pageTemplate = self.pageTemplates[self._nextPageTemplateIndex] |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
618 |
del self._nextPageTemplateIndex |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
619 |
elif self.pageTemplate.autoNextPageTemplate: |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
620 |
self.handle_nextPageTemplate(self.pageTemplate.autoNextPageTemplate) |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
621 |
self.pageTemplate = self.pageTemplates[self._nextPageTemplateIndex] |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
622 |
|
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
623 |
def _samePT(self,npt): |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
624 |
if isSeq(npt): |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
625 |
return getattr(self,'_nextPageTemplateCycle',[]) |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
626 |
if isinstance(npt,strTypes): |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
627 |
return npt == (self.pageTemplates[self._nextPageTemplateIndex].id if hasattr(self,'_nextPageTemplateIndex') else self.pageTemplate.id) |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
628 |
if isinstance(npt,int) and 0<=npt<len(self.pageTemplates): |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
629 |
if hasattr(self,'_nextPageTemplateIndex'): |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
630 |
return npt==self._nextPageTemplateIndex |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
631 |
return npt==self.pageTemplates.find(self.pageTemplate) |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
632 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
633 |
def handle_pageEnd(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
634 |
''' show the current page |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
635 |
check the next page template |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
636 |
hang a page begin |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
637 |
''' |
2957 | 638 |
self._removeVars(('page','frame')) |
3519
eae7f1448301
doctemplate.py: fix transfer of extra indents in handle_pageBreak
rgbecker
parents:
3484
diff
changeset
|
639 |
self._leftExtraIndent = self.frame._leftExtraIndent |
eae7f1448301
doctemplate.py: fix transfer of extra indents in handle_pageBreak
rgbecker
parents:
3484
diff
changeset
|
640 |
self._rightExtraIndent = self.frame._rightExtraIndent |
3760
674899ebab37
platypus: FrameBG related stuff ifrom default that got lost somehow
robin
parents:
3731
diff
changeset
|
641 |
self._frameBGs = self.frame._frameBGs |
2192 | 642 |
#detect infinite loops... |
643 |
if self._curPageFlowableCount == 0: |
|
2593
3adaab508968
reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents:
2575
diff
changeset
|
644 |
self._emptyPages += 1 |
2192 | 645 |
else: |
646 |
self._emptyPages = 0 |
|
647 |
if self._emptyPages >= self._emptyPagesAllowed: |
|
2196 | 648 |
if 1: |
2466 | 649 |
ident = "More than %d pages generated without content - halting layout. Likely that a flowable is too large for any frame." % self._emptyPagesAllowed |
650 |
#leave to keep apart from the raise |
|
651 |
raise LayoutError(ident) |
|
2196 | 652 |
else: |
653 |
pass #attempt to restore to good state |
|
654 |
else: |
|
655 |
if self._onProgress: |
|
656 |
self._onProgress('PAGE', self.canv.getPageNumber()) |
|
657 |
self.pageTemplate.afterDrawPage(self.canv, self) |
|
658 |
self.pageTemplate.onPageEnd(self.canv, self) |
|
659 |
self.afterPage() |
|
2531 | 660 |
if self._debug: logger.debug("ending page %d" % self.page) |
2492
8142a1737889
doctemplate.py: add rotation argument to BaseDocTemplate
rgbecker
parents:
2491
diff
changeset
|
661 |
self.canv.setPageRotation(getattr(self.pageTemplate,'rotation',self.rotation)) |
2196 | 662 |
self.canv.showPage() |
4145
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
663 |
self._setPageTemplate() |
2196 | 664 |
if self._emptyPages==0: |
665 |
pass #store good state here |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
666 |
self._hanging.append(PageBegin) |
197 | 667 |
|
2408 | 668 |
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
|
669 |
'''some might choose not to end all the frames''' |
2408 | 670 |
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
|
671 |
self.handle_pageEnd() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
672 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
673 |
n = len(self._hanging) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
674 |
while len(self._hanging)==n: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
675 |
self.handle_frameEnd() |
512 | 676 |
|
4347
761e190b40af
added SetPageTopFlowables; version --> 3.4.6
robin <robin@reportlab.com>
parents:
4346
diff
changeset
|
677 |
def handle_frameBegin(self,resume=0,pageTopFlowables=None): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
678 |
'''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
|
679 |
f = self.frame |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
680 |
if f._atTop: |
4492
c0721260ecc1
change precedence in showBoundary usage
robin <robin@reportlab.com>
parents:
4482
diff
changeset
|
681 |
boundary = self.frame.showBoundary or self.showBoundary |
c0721260ecc1
change precedence in showBoundary usage
robin <robin@reportlab.com>
parents:
4482
diff
changeset
|
682 |
if boundary: |
c0721260ecc1
change precedence in showBoundary usage
robin <robin@reportlab.com>
parents:
4482
diff
changeset
|
683 |
self.frame.drawBoundary(self.canv,boundary) |
1923 | 684 |
f._leftExtraIndent = self._leftExtraIndent |
685 |
f._rightExtraIndent = self._rightExtraIndent |
|
3760
674899ebab37
platypus: FrameBG related stuff ifrom default that got lost somehow
robin
parents:
3731
diff
changeset
|
686 |
f._frameBGs = self._frameBGs |
4347
761e190b40af
added SetPageTopFlowables; version --> 3.4.6
robin <robin@reportlab.com>
parents:
4346
diff
changeset
|
687 |
if pageTopFlowables: |
761e190b40af
added SetPageTopFlowables; version --> 3.4.6
robin <robin@reportlab.com>
parents:
4346
diff
changeset
|
688 |
self._hanging.extend(pageTopFlowables) |
4228
fd5bbccc7758
add support from simple auto top of frame flowables version-->3.2.9
robin
parents:
4212
diff
changeset
|
689 |
if self._topFlowables: |
fd5bbccc7758
add support from simple auto top of frame flowables version-->3.2.9
robin
parents:
4212
diff
changeset
|
690 |
self._hanging.extend(self._topFlowables) |
197 | 691 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
692 |
def handle_frameEnd(self,resume=0): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
693 |
''' 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
|
694 |
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
|
695 |
''' |
2957 | 696 |
self._removeVars(('frame',)) |
1923 | 697 |
self._leftExtraIndent = self.frame._leftExtraIndent |
698 |
self._rightExtraIndent = self.frame._rightExtraIndent |
|
3760
674899ebab37
platypus: FrameBG related stuff ifrom default that got lost somehow
robin
parents:
3731
diff
changeset
|
699 |
self._frameBGs = self.frame._frameBGs |
1923 | 700 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
701 |
if hasattr(self,'_nextFrameIndex'): |
2529
dced304f8584
flowables.py: keepInFrame now truncates etc properly, doctemplate.py: fix handle_frameEnd
rgbecker
parents:
2525
diff
changeset
|
702 |
self.frame = self.pageTemplate.frames[self._nextFrameIndex] |
2531 | 703 |
self.frame._debug = self._debug |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
704 |
del self._nextFrameIndex |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
705 |
self.handle_frameBegin(resume) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
706 |
else: |
4380
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
707 |
f = self.frame |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
708 |
if hasattr(f,'lastFrame') or f is self.pageTemplate.frames[-1]: |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
709 |
self.handle_pageEnd() |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
710 |
self.frame = None |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
711 |
else: |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
712 |
self.frame = self.pageTemplate.frames[self.pageTemplate.frames.index(f) + 1] |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
713 |
self.frame._debug = self._debug |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
714 |
self.handle_frameBegin() |
197 | 715 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
716 |
def handle_nextPageTemplate(self,pt): |
2449
47b15f941325
platypus: attempt to make KeepTogether/keepWithNext more robust
rgbecker
parents:
2418
diff
changeset
|
717 |
'''On endPage change to the page template with name or index pt''' |
4018
c69c31436936
doctemplate.py: use annotateException & allow page templates to be any string type
robin
parents:
3975
diff
changeset
|
718 |
if isinstance(pt,strTypes): |
2418 | 719 |
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
|
720 |
for t in self.pageTemplates: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
721 |
if t.id == pt: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
722 |
self._nextPageTemplateIndex = self.pageTemplates.index(t) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
723 |
return |
3721 | 724 |
raise ValueError("can't find template('%s')"%pt) |
3731 | 725 |
elif isinstance(pt,int): |
2418 | 726 |
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
|
727 |
self._nextPageTemplateIndex = pt |
3731 | 728 |
elif isSeq(pt): |
2418 | 729 |
#used for alternating left/right pages |
730 |
#collect the refs to the template objects, complain if any are bad |
|
2661
e179247ffea3
platypus: add * as shortcircuit template cycle notation
rgbecker
parents:
2654
diff
changeset
|
731 |
c = PTCycle() |
e179247ffea3
platypus: add * as shortcircuit template cycle notation
rgbecker
parents:
2654
diff
changeset
|
732 |
for ptn in pt: |
2418 | 733 |
found = 0 |
2661
e179247ffea3
platypus: add * as shortcircuit template cycle notation
rgbecker
parents:
2654
diff
changeset
|
734 |
if ptn=='*': #special case name used to short circuit the iteration |
e179247ffea3
platypus: add * as shortcircuit template cycle notation
rgbecker
parents:
2654
diff
changeset
|
735 |
c._restart = len(c) |
e179247ffea3
platypus: add * as shortcircuit template cycle notation
rgbecker
parents:
2654
diff
changeset
|
736 |
continue |
2418 | 737 |
for t in self.pageTemplates: |
2661
e179247ffea3
platypus: add * as shortcircuit template cycle notation
rgbecker
parents:
2654
diff
changeset
|
738 |
if t.id == ptn: |
e179247ffea3
platypus: add * as shortcircuit template cycle notation
rgbecker
parents:
2654
diff
changeset
|
739 |
c.append(t) |
2418 | 740 |
found = 1 |
741 |
if not found: |
|
3161 | 742 |
raise ValueError("Cannot find page template called %s" % ptn) |
2661
e179247ffea3
platypus: add * as shortcircuit template cycle notation
rgbecker
parents:
2654
diff
changeset
|
743 |
if not c: |
e179247ffea3
platypus: add * as shortcircuit template cycle notation
rgbecker
parents:
2654
diff
changeset
|
744 |
raise ValueError("No valid page templates in cycle") |
e179247ffea3
platypus: add * as shortcircuit template cycle notation
rgbecker
parents:
2654
diff
changeset
|
745 |
elif c._restart>len(c): |
e179247ffea3
platypus: add * as shortcircuit template cycle notation
rgbecker
parents:
2654
diff
changeset
|
746 |
raise ValueError("Invalid cycle restart position") |
e179247ffea3
platypus: add * as shortcircuit template cycle notation
rgbecker
parents:
2654
diff
changeset
|
747 |
|
2418 | 748 |
#ensure we start on the first one |
4145
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
749 |
self._nextPageTemplateCycle = c |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
750 |
else: |
2950 | 751 |
raise TypeError("argument pt should be string or integer or list") |
197 | 752 |
|
4380
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
753 |
def _peekNextPageTemplate(self,pt): |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
754 |
if isinstance(pt,strTypes): |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
755 |
for t in self.pageTemplates: |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
756 |
if t.id == pt: |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
757 |
return t |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
758 |
raise ValueError("can't find template('%s')"%pt) |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
759 |
elif isinstance(pt,int): |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
760 |
self.pageTemplates[pt] |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
761 |
elif isSeq(pt): |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
762 |
#used for alternating left/right pages |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
763 |
#collect the refs to the template objects, complain if any are bad |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
764 |
c = PTCycle() |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
765 |
for ptn in pt: |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
766 |
found = 0 |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
767 |
if ptn=='*': #special case name used to short circuit the iteration |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
768 |
c._restart = len(c) |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
769 |
continue |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
770 |
for t in self.pageTemplates: |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
771 |
if t.id == ptn: |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
772 |
c.append(t) |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
773 |
found = 1 |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
774 |
if not found: |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
775 |
raise ValueError("Cannot find page template called %s" % ptn) |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
776 |
if not c: |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
777 |
raise ValueError("No valid page templates in cycle") |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
778 |
elif c._restart>len(c): |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
779 |
raise ValueError("Invalid cycle restart position") |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
780 |
return c.peek |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
781 |
else: |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
782 |
raise TypeError("argument pt should be string or integer or list") |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
783 |
|
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
784 |
def _peekNextFrame(self): |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
785 |
'''intended to be used by extreme flowables''' |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
786 |
if hasattr(self,'_nextFrameIndex'): |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
787 |
return self.pageTemplate.frames[self._nextFrameIndex] |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
788 |
f = self.frame |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
789 |
if hasattr(f,'lastFrame') or f is self.pageTemplate.frames[-1]: |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
790 |
if hasattr(self,'_nextPageTemplateCycle'): |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
791 |
#they are cycling through pages'; we keep the index |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
792 |
pageTemplate = self._nextPageTemplateCycle.peek |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
793 |
elif hasattr(self,'_nextPageTemplateIndex'): |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
794 |
pageTemplate = self.pageTemplates[self._nextPageTemplateIndex] |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
795 |
elif self.pageTemplate.autoNextPageTemplate: |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
796 |
pageTemplate = self._peekNextPageTemplate(self.pageTemplate.autoNextPageTemplate) |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
797 |
else: |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
798 |
pageTemplate = self.pageTemplate |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
799 |
return pageTemplate.frames[0] |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
800 |
else: |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
801 |
return self.pageTemplate.frames[self.pageTemplate.frames.index(f) + 1] |
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
802 |
|
2529
dced304f8584
flowables.py: keepInFrame now truncates etc properly, doctemplate.py: fix handle_frameEnd
rgbecker
parents:
2525
diff
changeset
|
803 |
def handle_nextFrame(self,fx,resume=0): |
2449
47b15f941325
platypus: attempt to make KeepTogether/keepWithNext more robust
rgbecker
parents:
2418
diff
changeset
|
804 |
'''On endFrame change to the frame with name or index fx''' |
4020 | 805 |
if isinstance(fx,strTypes): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
806 |
for f in self.pageTemplate.frames: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
807 |
if f.id == fx: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
808 |
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
|
809 |
return |
2950 | 810 |
raise ValueError("can't find frame('%s') in %r(%s) which has frames %r"%(fx,self.pageTemplate,self.pageTemplate.id,[(f,f.id) for f in self.pageTemplate.frames])) |
3731 | 811 |
elif isinstance(fx,int): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
812 |
self._nextFrameIndex = fx |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
813 |
else: |
3721 | 814 |
raise TypeError("argument fx should be string or integer") |
512 | 815 |
|
2529
dced304f8584
flowables.py: keepInFrame now truncates etc properly, doctemplate.py: fix handle_frameEnd
rgbecker
parents:
2525
diff
changeset
|
816 |
def handle_currentFrame(self,fx,resume=0): |
2449
47b15f941325
platypus: attempt to make KeepTogether/keepWithNext more robust
rgbecker
parents:
2418
diff
changeset
|
817 |
'''change to the frame with name or index fx''' |
2529
dced304f8584
flowables.py: keepInFrame now truncates etc properly, doctemplate.py: fix handle_frameEnd
rgbecker
parents:
2525
diff
changeset
|
818 |
self.handle_nextFrame(fx,resume) |
dced304f8584
flowables.py: keepInFrame now truncates etc properly, doctemplate.py: fix handle_frameEnd
rgbecker
parents:
2525
diff
changeset
|
819 |
self.handle_frameEnd(resume) |
197 | 820 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
821 |
def handle_breakBefore(self, flowables): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
822 |
'''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
|
823 |
first = flowables[0] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
824 |
# 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
|
825 |
# 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
|
826 |
# 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
|
827 |
if hasattr(first, '_skipMeNextTime'): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
828 |
delattr(first, '_skipMeNextTime') |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
829 |
return |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
830 |
# 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
|
831 |
# 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
|
832 |
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
|
833 |
first._skipMeNextTime = 1 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
834 |
first.insert(0, PageBreak()) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
835 |
return |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
836 |
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
|
837 |
first._skipMeNextTime = 1 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
838 |
flowables.insert(0, PageBreak()) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
839 |
return |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
840 |
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
|
841 |
first._skipMeNextTime = 1 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
842 |
flowables.insert(0, FrameBreak()) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
843 |
return |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
844 |
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
|
845 |
first._skipMeNextTime = 1 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
846 |
flowables.insert(0, FrameBreak()) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
847 |
return |
1428 | 848 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
849 |
def handle_keepWithNext(self, flowables): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
850 |
"implements keepWithNext" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
851 |
i = 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
852 |
n = len(flowables) |
4279
f69571262c74
fix fake KeepTogether setup in handle_keepWithNext; version--> 3.3.13
robin
parents:
4278
diff
changeset
|
853 |
while i<n and flowables[i].getKeepWithNext() and _ktAllow(flowables[i]): i += 1 |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
854 |
if i: |
4279
f69571262c74
fix fake KeepTogether setup in handle_keepWithNext; version--> 3.3.13
robin
parents:
4278
diff
changeset
|
855 |
if i<n and _ktAllow(flowables[i]): i += 1 |
4380
831ee16f2338
improvements to keepTogether & added peek frame/template methods; issue started by Андрија Зарић lisandrija @ bitbucket.org
rptlab
parents:
4370
diff
changeset
|
856 |
K = self.keepTogetherClass(flowables[:i]) |
2995
b510fcf46c0b
doctemplate.py: first try at clean up of keepWithNext for multiBuild
rgbecker
parents:
2964
diff
changeset
|
857 |
mbe = getattr(self,'_multiBuildEdits',None) |
b510fcf46c0b
doctemplate.py: first try at clean up of keepWithNext for multiBuild
rgbecker
parents:
2964
diff
changeset
|
858 |
if mbe: |
b510fcf46c0b
doctemplate.py: first try at clean up of keepWithNext for multiBuild
rgbecker
parents:
2964
diff
changeset
|
859 |
for f in K._content[:-1]: |
b510fcf46c0b
doctemplate.py: first try at clean up of keepWithNext for multiBuild
rgbecker
parents:
2964
diff
changeset
|
860 |
if hasattr(f,'keepWithNext'): |
b510fcf46c0b
doctemplate.py: first try at clean up of keepWithNext for multiBuild
rgbecker
parents:
2964
diff
changeset
|
861 |
mbe((setattr,f,'keepWithNext',f.keepWithNext)) |
b510fcf46c0b
doctemplate.py: first try at clean up of keepWithNext for multiBuild
rgbecker
parents:
2964
diff
changeset
|
862 |
else: |
b510fcf46c0b
doctemplate.py: first try at clean up of keepWithNext for multiBuild
rgbecker
parents:
2964
diff
changeset
|
863 |
mbe((delattr,f,'keepWithNext')) #must get it from a style |
b510fcf46c0b
doctemplate.py: first try at clean up of keepWithNext for multiBuild
rgbecker
parents:
2964
diff
changeset
|
864 |
f.__dict__['keepWithNext'] = 0 |
b510fcf46c0b
doctemplate.py: first try at clean up of keepWithNext for multiBuild
rgbecker
parents:
2964
diff
changeset
|
865 |
else: |
b510fcf46c0b
doctemplate.py: first try at clean up of keepWithNext for multiBuild
rgbecker
parents:
2964
diff
changeset
|
866 |
for f in K._content[:-1]: |
b510fcf46c0b
doctemplate.py: first try at clean up of keepWithNext for multiBuild
rgbecker
parents:
2964
diff
changeset
|
867 |
f.__dict__['keepWithNext'] = 0 |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
868 |
del flowables[:i] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
869 |
flowables.insert(0,K) |
1425 | 870 |
|
2531 | 871 |
def _fIdent(self,f,maxLen=None,frame=None): |
872 |
if frame: f._frame = frame |
|
873 |
try: |
|
874 |
return f.identity(maxLen) |
|
875 |
finally: |
|
876 |
if frame: del f._frame |
|
877 |
||
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
878 |
def handle_flowable(self,flowables): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
879 |
'''try to handle one flowable from the front of list flowables.''' |
1428 | 880 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
881 |
#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
|
882 |
#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
|
883 |
self.filterFlowables(flowables) |
1428 | 884 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
885 |
f = flowables[0] |
4346
081acecbf8f6
fix bitbucket issue #104; version-->3.4.5
robin <robin@reportlab.com>
parents:
4335
diff
changeset
|
886 |
if f: |
081acecbf8f6
fix bitbucket issue #104; version-->3.4.5
robin <robin@reportlab.com>
parents:
4335
diff
changeset
|
887 |
self.handle_breakBefore(flowables) |
081acecbf8f6
fix bitbucket issue #104; version-->3.4.5
robin <robin@reportlab.com>
parents:
4335
diff
changeset
|
888 |
self.handle_keepWithNext(flowables) |
081acecbf8f6
fix bitbucket issue #104; version-->3.4.5
robin <robin@reportlab.com>
parents:
4335
diff
changeset
|
889 |
f = flowables[0] |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
890 |
del flowables[0] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
891 |
if f is None: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
892 |
return |
197 | 893 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
894 |
if isinstance(f,PageBreak): |
4145
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
895 |
npt = f.nextTemplate |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
896 |
if npt and not self._samePT(npt): |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
897 |
npt=NextPageTemplate(npt) |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
898 |
npt.apply(self) |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
899 |
self.afterFlowable(npt) |
2408 | 900 |
if isinstance(f,SlowPageBreak): |
901 |
self.handle_pageBreak(slow=1) |
|
902 |
else: |
|
903 |
self.handle_pageBreak() |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
904 |
self.afterFlowable(f) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
905 |
elif isinstance(f,ActionFlowable): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
906 |
f.apply(self) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
907 |
self.afterFlowable(f) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
908 |
else: |
2762 | 909 |
frame = self.frame |
2950 | 910 |
canv = self.canv |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
911 |
#try to fit it then draw it |
2950 | 912 |
if frame.add(f, canv, trySplit=self.allowSplitting): |
2762 | 913 |
if not isinstance(f,FrameActionFlowable): |
914 |
self._curPageFlowableCount += 1 |
|
915 |
self.afterFlowable(f) |
|
3009 | 916 |
_addGeneratedContent(flowables,frame) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
917 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
918 |
if self.allowSplitting: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
919 |
# see if this is a splittable thing |
2950 | 920 |
S = frame.split(f,canv) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
921 |
n = len(S) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
922 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
923 |
n = 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
924 |
if n: |
3528
5c3249611b60
doctemplate/flowables.py: fix DDIndenter split issue
rgbecker
parents:
3523
diff
changeset
|
925 |
if not isinstance(S[0],(PageBreak,SlowPageBreak,ActionFlowable,DDIndenter)): |
3323
8fe71f699df9
doctemplate.py: fix bug in order of split[0] generated content contributed by Robert Hölzl <robert.hoelzl@baltech.de>
rgbecker
parents:
3272
diff
changeset
|
926 |
if not frame.add(S[0], canv, trySplit=0): |
3484
9c12031155ba
platypus: fix splitting for ListFlowables (maybe)
rgbecker
parents:
3456
diff
changeset
|
927 |
ident = "Splitting error(n==%d) on page %d in\n%s\nS[0]=%s" % (n,self.page,self._fIdent(f,60,frame),self._fIdent(S[0],60,frame)) |
2575 | 928 |
#leave to keep apart from the raise |
929 |
raise LayoutError(ident) |
|
3323
8fe71f699df9
doctemplate.py: fix bug in order of split[0] generated content contributed by Robert Hölzl <robert.hoelzl@baltech.de>
rgbecker
parents:
3272
diff
changeset
|
930 |
self._curPageFlowableCount += 1 |
8fe71f699df9
doctemplate.py: fix bug in order of split[0] generated content contributed by Robert Hölzl <robert.hoelzl@baltech.de>
rgbecker
parents:
3272
diff
changeset
|
931 |
self.afterFlowable(S[0]) |
8fe71f699df9
doctemplate.py: fix bug in order of split[0] generated content contributed by Robert Hölzl <robert.hoelzl@baltech.de>
rgbecker
parents:
3272
diff
changeset
|
932 |
flowables[0:0] = S[1:] # put rest of splitted flowables back on the list |
8fe71f699df9
doctemplate.py: fix bug in order of split[0] generated content contributed by Robert Hölzl <robert.hoelzl@baltech.de>
rgbecker
parents:
3272
diff
changeset
|
933 |
_addGeneratedContent(flowables,frame) |
8fe71f699df9
doctemplate.py: fix bug in order of split[0] generated content contributed by Robert Hölzl <robert.hoelzl@baltech.de>
rgbecker
parents:
3272
diff
changeset
|
934 |
else: |
4482 | 935 |
flowables[0:0] = S # put split flowables back on the list |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
936 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
937 |
if hasattr(f,'_postponed'): |
3131
0f15fabe9d8d
reportlab: improve information in doctemplate overflow error
rgbecker
parents:
3129
diff
changeset
|
938 |
ident = "Flowable %s%s too large on page %d in frame %r%s of template %r" % \ |
0f15fabe9d8d
reportlab: improve information in doctemplate overflow error
rgbecker
parents:
3129
diff
changeset
|
939 |
(self._fIdent(f,60,frame),_fSizeString(f),self.page, self.frame.id, |
0f15fabe9d8d
reportlab: improve information in doctemplate overflow error
rgbecker
parents:
3129
diff
changeset
|
940 |
self.frame._aSpaceString(), self.pageTemplate.id) |
2466 | 941 |
#leave to keep apart from the raise |
942 |
raise LayoutError(ident) |
|
2196 | 943 |
# 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
|
944 |
f._postponed = 1 |
2998
efe6a1d93dd2
doctemplate.py: robustify access to _multiBuildEdits
rgbecker
parents:
2996
diff
changeset
|
945 |
mbe = getattr(self,'_multiBuildEdits',None) |
efe6a1d93dd2
doctemplate.py: robustify access to _multiBuildEdits
rgbecker
parents:
2996
diff
changeset
|
946 |
if mbe: |
efe6a1d93dd2
doctemplate.py: robustify access to _multiBuildEdits
rgbecker
parents:
2996
diff
changeset
|
947 |
mbe((delattr,f,'_postponed')) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
948 |
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
|
949 |
self.handle_frameEnd() |
197 | 950 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
951 |
#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
|
952 |
_handle_documentBegin = handle_documentBegin |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
953 |
_handle_pageBegin = handle_pageBegin |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
954 |
_handle_pageEnd = handle_pageEnd |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
955 |
_handle_frameBegin = handle_frameBegin |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
956 |
_handle_frameEnd = handle_frameEnd |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
957 |
_handle_flowable = handle_flowable |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
958 |
_handle_nextPageTemplate = handle_nextPageTemplate |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
959 |
_handle_currentFrame = handle_currentFrame |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
960 |
_handle_nextFrame = handle_nextFrame |
1505 | 961 |
|
4405
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
962 |
def _makeCanvas(self, filename=None, canvasmaker=canvas.Canvas): |
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
963 |
'''make and return a sample canvas. As suggested by |
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
964 |
Chris Jerdonek cjerdonek @ bitbucket this allows testing of stringWidths |
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
965 |
etc. |
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
966 |
|
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
967 |
*NB* only the canvases created in self._startBuild will actually be used |
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
968 |
in the build process. |
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
969 |
''' |
4458
dfef5530196d
fix missing seq attribute reported by Jim Parinisi; version --> 3.5.6
robin <robin@reportlab.com>
parents:
4405
diff
changeset
|
970 |
#each distinct pass gets a sequencer |
dfef5530196d
fix missing seq attribute reported by Jim Parinisi; version --> 3.5.6
robin <robin@reportlab.com>
parents:
4405
diff
changeset
|
971 |
self.seq = reportlab.lib.sequencer.Sequencer() |
4405
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
972 |
canv = canvasmaker(filename or self.filename, |
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
973 |
pagesize=self.pagesize, |
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
974 |
invariant=self.invariant, |
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
975 |
pageCompression=self.pageCompression, |
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
976 |
enforceColorSpace=self.enforceColorSpace, |
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
977 |
initialFontName = self.initialFontName, |
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
978 |
initialFontSize = self.initialFontSize, |
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
979 |
initialLeading = self.initialLeading, |
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
980 |
cropBox = self.cropBox, |
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
981 |
artBox = self.artBox, |
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
982 |
trimBox = self.trimBox, |
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
983 |
bleedBox = self.bleedBox, |
4529 | 984 |
lang = self.lang, |
4405
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
985 |
) |
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
986 |
|
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
987 |
getattr(canv,'setEncrypt',lambda x: None)(self.encrypt) |
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
988 |
|
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
989 |
canv._cropMarks = self.cropMarks |
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
990 |
canv.setAuthor(self.author) |
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
991 |
canv.setTitle(self.title) |
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
992 |
canv.setSubject(self.subject) |
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
993 |
canv.setCreator(self.creator) |
4498
fe619935e3ea
allow setting producer; version --> 3.5.19
robin <robin@reportlab.com>
parents:
4492
diff
changeset
|
994 |
canv.setProducer(self.producer) |
4405
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
995 |
canv.setKeywords(self.keywords) |
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
996 |
if self.displayDocTitle is not None: |
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
997 |
canv.setViewerPreference('DisplayDocTitle',['false','true'][self.displayDocTitle]) |
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
998 |
|
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
999 |
if self._onPage: |
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
1000 |
canv.setPageCallBack(self._onPage) |
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
1001 |
return canv |
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
1002 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1003 |
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
|
1004 |
self._calc() |
4405
c985bd7093ad
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
robin <robin@reportlab.com>
parents:
4380
diff
changeset
|
1005 |
self.canv = self._makeCanvas(filename=filename,canvasmaker=canvasmaker) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1006 |
self.handle_documentBegin() |
512 | 1007 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1008 |
def _endBuild(self): |
2957 | 1009 |
self._removeVars(('build','page','frame')) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1010 |
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
|
1011 |
del self._hanging[-1] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1012 |
self.clean_hanging() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1013 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1014 |
self.clean_hanging() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1015 |
self.handle_pageBreak() |
1505 | 1016 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1017 |
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
|
1018 |
if self._onPage: self.canv.setPageCallBack(None) |
512 | 1019 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1020 |
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
|
1021 |
"""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
|
1022 |
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
|
1023 |
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
|
1024 |
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
|
1025 |
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
|
1026 |
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
|
1027 |
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
|
1028 |
operations). |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1029 |
""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1030 |
#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
|
1031 |
flowableCount = len(flowables) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1032 |
if self._onProgress: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1033 |
self._onProgress('STARTED',0) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1034 |
self._onProgress('SIZE_EST', len(flowables)) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1035 |
self._startBuild(filename,canvasmaker) |
512 | 1036 |
|
2666 | 1037 |
#pagecatcher can drag in information from embedded PDFs and we want ours |
1038 |
#to take priority, so cache and reapply our own info dictionary after the build. |
|
2950 | 1039 |
canv = self.canv |
1040 |
self._savedInfo = canv._doc.info |
|
2666 | 1041 |
handled = 0 |
2950 | 1042 |
|
1043 |
try: |
|
1044 |
canv._doctemplate = self |
|
1045 |
while len(flowables): |
|
4145
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
1046 |
if self._hanging and self._hanging[-1] is PageBegin and isinstance(flowables[0],PageBreakIfNotEmpty): |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
1047 |
npt = flowables[0].nextTemplate |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
1048 |
if npt and not self._samePT(npt): |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
1049 |
npt=NextPageTemplate(npt) |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
1050 |
npt.apply(self) |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
1051 |
self._setPageTemplate() |
f14cb807aa3d
platypus: support setting template with PageBreak & add PageBreakIfNotEmpty; version --> 3.1.40
robin
parents:
4121
diff
changeset
|
1052 |
del flowables[0] |
2950 | 1053 |
self.clean_hanging() |
1054 |
try: |
|
1055 |
first = flowables[0] |
|
1056 |
self.handle_flowable(flowables) |
|
1057 |
handled += 1 |
|
1058 |
except: |
|
1059 |
#if it has trace info, add it to the traceback message. |
|
1060 |
if hasattr(first, '_traceInfo') and first._traceInfo: |
|
1061 |
exc = sys.exc_info()[1] |
|
1062 |
args = list(exc.args) |
|
1063 |
tr = first._traceInfo |
|
1064 |
args[0] += '\n(srcFile %s, line %d char %d to line %d char %d)' % ( |
|
1065 |
tr.srcFile, |
|
1066 |
tr.startLineNo, |
|
1067 |
tr.startLinePos, |
|
1068 |
tr.endLineNo, |
|
1069 |
tr.endLinePos |
|
1070 |
) |
|
1071 |
exc.args = tuple(args) |
|
1072 |
raise |
|
1073 |
if self._onProgress: |
|
1074 |
self._onProgress('PROGRESS',flowableCount - len(flowables)) |
|
1075 |
finally: |
|
1076 |
del canv._doctemplate |
|
1077 |
||
1505 | 1078 |
|
2666 | 1079 |
#reapply pagecatcher info |
2950 | 1080 |
canv._doc.info = self._savedInfo |
2666 | 1081 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1082 |
self._endBuild() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1083 |
if self._onProgress: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1084 |
self._onProgress('FINISHED',0) |
512 | 1085 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1086 |
def _allSatisfied(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1087 |
"""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
|
1088 |
allHappy = 1 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1089 |
for f in self._indexingFlowables: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1090 |
if not f.isSatisfied(): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1091 |
allHappy = 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1092 |
break |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1093 |
return allHappy |
197 | 1094 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1095 |
def notify(self, kind, stuff): |
2688
f9c4d1488516
doctemplate: apply T Heller's fix emacs syntax colouring patch
rgbecker
parents:
2672
diff
changeset
|
1096 |
"""Forward to any listeners""" |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1097 |
for l in self._indexingFlowables: |
4121
3b9e6fa286ad
tableofcontents.py, doctemplate.py: fix indexing page number ordering bug found by Greg Jones bitbucket issue #40
robin
parents:
4067
diff
changeset
|
1098 |
_canv = getattr(l,'_canv',self) |
3b9e6fa286ad
tableofcontents.py, doctemplate.py: fix indexing page number ordering bug found by Greg Jones bitbucket issue #40
robin
parents:
4067
diff
changeset
|
1099 |
try: |
3b9e6fa286ad
tableofcontents.py, doctemplate.py: fix indexing page number ordering bug found by Greg Jones bitbucket issue #40
robin
parents:
4067
diff
changeset
|
1100 |
if _canv==self: |
3b9e6fa286ad
tableofcontents.py, doctemplate.py: fix indexing page number ordering bug found by Greg Jones bitbucket issue #40
robin
parents:
4067
diff
changeset
|
1101 |
l._canv = self.canv |
3b9e6fa286ad
tableofcontents.py, doctemplate.py: fix indexing page number ordering bug found by Greg Jones bitbucket issue #40
robin
parents:
4067
diff
changeset
|
1102 |
l.notify(kind, stuff) |
3b9e6fa286ad
tableofcontents.py, doctemplate.py: fix indexing page number ordering bug found by Greg Jones bitbucket issue #40
robin
parents:
4067
diff
changeset
|
1103 |
finally: |
3b9e6fa286ad
tableofcontents.py, doctemplate.py: fix indexing page number ordering bug found by Greg Jones bitbucket issue #40
robin
parents:
4067
diff
changeset
|
1104 |
if _canv==self: |
3b9e6fa286ad
tableofcontents.py, doctemplate.py: fix indexing page number ordering bug found by Greg Jones bitbucket issue #40
robin
parents:
4067
diff
changeset
|
1105 |
del l._canv |
1505 | 1106 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1107 |
def pageRef(self, label): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1108 |
"""hook to register a page number""" |
3721 | 1109 |
if verbose: print("pageRef called with label '%s' on page %d" % ( |
1110 |
label, self.page)) |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1111 |
self._pageRefs[label] = self.page |
1428 | 1112 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1113 |
def multiBuild(self, story, |
3175
bf81f5b13ba8
doctemplate.py: fix bogus exception and allow for build keyword args in multibuild
rgbecker
parents:
3161
diff
changeset
|
1114 |
maxPasses = 10, |
bf81f5b13ba8
doctemplate.py: fix bogus exception and allow for build keyword args in multibuild
rgbecker
parents:
3161
diff
changeset
|
1115 |
**buildKwds |
bf81f5b13ba8
doctemplate.py: fix bogus exception and allow for build keyword args in multibuild
rgbecker
parents:
3161
diff
changeset
|
1116 |
): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1117 |
"""Makes multiple passes until all indexing flowables |
3374 | 1118 |
are happy. |
4121
3b9e6fa286ad
tableofcontents.py, doctemplate.py: fix indexing page number ordering bug found by Greg Jones bitbucket issue #40
robin
parents:
4067
diff
changeset
|
1119 |
|
3374 | 1120 |
Returns number of passes""" |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1121 |
self._indexingFlowables = [] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1122 |
#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
|
1123 |
for thing in story: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1124 |
if thing.isIndexing(): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1125 |
self._indexingFlowables.append(thing) |
1683 | 1126 |
|
1829
ce5ceec32eab
Fix up multiBuild to be cleverer about initial saves
rgbecker
parents:
1824
diff
changeset
|
1127 |
#better fix for filename is a 'file' problem |
ce5ceec32eab
Fix up multiBuild to be cleverer about initial saves
rgbecker
parents:
1824
diff
changeset
|
1128 |
self._doSave = 0 |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1129 |
passes = 0 |
2995
b510fcf46c0b
doctemplate.py: first try at clean up of keepWithNext for multiBuild
rgbecker
parents:
2964
diff
changeset
|
1130 |
mbe = [] |
b510fcf46c0b
doctemplate.py: first try at clean up of keepWithNext for multiBuild
rgbecker
parents:
2964
diff
changeset
|
1131 |
self._multiBuildEdits = mbe.append |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1132 |
while 1: |
2593
3adaab508968
reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents:
2575
diff
changeset
|
1133 |
passes += 1 |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1134 |
if self._onProgress: |
2460
dc28c1738ea9
doctemplate.py: fix buglet reported by Steve Halasz
rgbecker
parents:
2450
diff
changeset
|
1135 |
self._onProgress('PASS', passes) |
3884 | 1136 |
if verbose: sys.stdout.write('building pass '+str(passes) + '...') |
197 | 1137 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1138 |
for fl in self._indexingFlowables: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1139 |
fl.beforeBuild() |
218
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
1140 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1141 |
# 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
|
1142 |
tempStory = story[:] |
3175
bf81f5b13ba8
doctemplate.py: fix bogus exception and allow for build keyword args in multibuild
rgbecker
parents:
3161
diff
changeset
|
1143 |
self.build(tempStory, **buildKwds) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1144 |
#self.notify('debug',None) |
512 | 1145 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1672
diff
changeset
|
1146 |
for fl in self._indexingFlowables: |