reportlab/demos/odyssey/fodyssey.py
author rgbecker
Thu, 01 Jun 2000 09:41:12 +0000
changeset 251 6f6cd14069f6
parent 226 a9acb67cdef7
child 253 cfcf8d555a2c
permissions -rw-r--r--
test filename case fix
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
     1
###############################################################################
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
     2
#
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
     3
#	ReportLab Public License Version 1.0
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
     4
#
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
     5
#	Except for the change of names the spirit and intention of this
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
     6
#	license is the same as that of Python
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
     7
#
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
     8
#	(C) Copyright ReportLab Inc. 1998-2000.
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
     9
#
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    10
#
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    11
# All Rights Reserved
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    12
#
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    13
# Permission to use, copy, modify, and distribute this software and its
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    14
# documentation for any purpose and without fee is hereby granted, provided
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    15
# that the above copyright notice appear in all copies and that both that
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    16
# copyright notice and this permission notice appear in supporting
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    17
# documentation, and that the name of ReportLab not be used
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    18
# in advertising or publicity pertaining to distribution of the software
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    19
# without specific, written prior permission. 
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    20
# 
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    21
#
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    22
# Disclaimer
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    23
#
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    24
# ReportLab Inc. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    25
# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    26
# IN NO EVENT SHALL ReportLab BE LIABLE FOR ANY SPECIAL, INDIRECT
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    27
# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    28
# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    29
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    30
# PERFORMANCE OF THIS SOFTWARE. 
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    31
#
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    32
###############################################################################
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    33
#	$Log: fodyssey.py,v $
251
6f6cd14069f6 test filename case fix
rgbecker
parents: 226
diff changeset
    34
#	Revision 1.11  2000/06/01 09:41:12  rgbecker
6f6cd14069f6 test filename case fix
rgbecker
parents: 226
diff changeset
    35
#	test filename case fix
6f6cd14069f6 test filename case fix
rgbecker
parents: 226
diff changeset
    36
#
226
a9acb67cdef7 Removal of SimpleFrame
rgbecker
parents: 225
diff changeset
    37
#	Revision 1.10  2000/05/17 16:29:39  rgbecker
a9acb67cdef7 Removal of SimpleFrame
rgbecker
parents: 225
diff changeset
    38
#	Removal of SimpleFrame
251
6f6cd14069f6 test filename case fix
rgbecker
parents: 226
diff changeset
    39
#	
225
1f58b00cf30e Changes related to removal of SimpleFlowDocument
rgbecker
parents: 207
diff changeset
    40
#	Revision 1.9  2000/05/17 15:37:33  rgbecker
1f58b00cf30e Changes related to removal of SimpleFlowDocument
rgbecker
parents: 207
diff changeset
    41
#	Changes related to removal of SimpleFlowDocument
226
a9acb67cdef7 Removal of SimpleFrame
rgbecker
parents: 225
diff changeset
    42
#	
207
52e4ab91cc16 Fix spacing bugs
rgbecker
parents: 203
diff changeset
    43
#	Revision 1.8  2000/05/13 09:23:45  rgbecker
52e4ab91cc16 Fix spacing bugs
rgbecker
parents: 203
diff changeset
    44
#	Fix spacing bugs
225
1f58b00cf30e Changes related to removal of SimpleFlowDocument
rgbecker
parents: 207
diff changeset
    45
#	
203
0e2031146bf5 Title leading changes
rgbecker
parents: 198
diff changeset
    46
#	Revision 1.7  2000/05/12 16:19:07  rgbecker
0e2031146bf5 Title leading changes
rgbecker
parents: 198
diff changeset
    47
#	Title leading changes
207
52e4ab91cc16 Fix spacing bugs
rgbecker
parents: 203
diff changeset
    48
#	
198
5604fb99b2e7 Added 'if __name__=='__main__'' handlers to demos
andy_robinson
parents: 195
diff changeset
    49
#	Revision 1.6  2000/05/12 14:19:03  andy_robinson
5604fb99b2e7 Added 'if __name__=='__main__'' handlers to demos
andy_robinson
parents: 195
diff changeset
    50
#	Added 'if __name__=='__main__'' handlers to demos
203
0e2031146bf5 Title leading changes
rgbecker
parents: 198
diff changeset
    51
#	
195
9ec081129a84 Minor fixes and changes for comparison with dodyssey.py
rgbecker
parents: 129
diff changeset
    52
#	Revision 1.5  2000/05/12 12:49:38  rgbecker
9ec081129a84 Minor fixes and changes for comparison with dodyssey.py
rgbecker
parents: 129
diff changeset
    53
#	Minor fixes and changes for comparison with dodyssey.py
198
5604fb99b2e7 Added 'if __name__=='__main__'' handlers to demos
andy_robinson
parents: 195
diff changeset
    54
#	
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
    55
#	Revision 1.4  2000/04/14 12:17:05  rgbecker
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
    56
#	Splitting layout.py
195
9ec081129a84 Minor fixes and changes for comparison with dodyssey.py
rgbecker
parents: 129
diff changeset
    57
#	
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 117
diff changeset
    58
#	Revision 1.3  2000/04/13 14:48:41  rgbecker
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 117
diff changeset
    59
#	<para> tag added in layout.py paraparser.py
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
    60
#	
117
fd3682228853 XML Tagged Paragraph parser changes
rgbecker
parents: 73
diff changeset
    61
#	Revision 1.2  2000/04/12 16:24:34  rgbecker
fd3682228853 XML Tagged Paragraph parser changes
rgbecker
parents: 73
diff changeset
    62
#	XML Tagged Paragraph parser changes
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 117
diff changeset
    63
#	
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    64
#	Revision 1.1  2000/04/06 08:58:09  rgbecker
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    65
#	Paragraph formatting version of odyssey.py
117
fd3682228853 XML Tagged Paragraph parser changes
rgbecker
parents: 73
diff changeset
    66
#	
251
6f6cd14069f6 test filename case fix
rgbecker
parents: 226
diff changeset
    67
__version__=''' $Id: fodyssey.py,v 1.11 2000/06/01 09:41:12 rgbecker Exp $ '''
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    68
__doc__=''
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    69
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    70
#REPORTLAB_TEST_SCRIPT
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    71
import sys, copy, string, os
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
    72
from reportlab.platypus.paragraph import Paragraph
225
1f58b00cf30e Changes related to removal of SimpleFlowDocument
rgbecker
parents: 207
diff changeset
    73
from reportlab.platypus.doctemplate import *
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    74
from reportlab.lib.units import inch
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
    75
from reportlab.lib.styles import getSampleStyleSheet
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
    76
from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    77
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
    78
styles = getSampleStyleSheet()
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    79
195
9ec081129a84 Minor fixes and changes for comparison with dodyssey.py
rgbecker
parents: 129
diff changeset
    80
Title = "The Odyssey"
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    81
Author = "Homer"
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    82
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    83
def myFirstPage(canvas, doc):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    84
	canvas.saveState()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    85
	canvas.restoreState()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    86
	
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    87
def myLaterPages(canvas, doc):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    88
	canvas.saveState()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    89
	canvas.setFont('Times-Roman',9)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    90
	canvas.drawString(inch, 0.75 * inch, "Page %d" % doc.page)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    91
	canvas.restoreState()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    92
	
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    93
def go():
226
a9acb67cdef7 Removal of SimpleFrame
rgbecker
parents: 225
diff changeset
    94
	doc = SimpleDocTemplate('fodyssey.pdf',DEFAULT_PAGE_SIZE,showBoundary='showboundary' in sys.argv)
225
1f58b00cf30e Changes related to removal of SimpleFlowDocument
rgbecker
parents: 207
diff changeset
    95
	doc.allowSplitting = not 'nosplitting' in sys.argv
1f58b00cf30e Changes related to removal of SimpleFlowDocument
rgbecker
parents: 207
diff changeset
    96
	doc.build(Elements,myFirstPage,myLaterPages)
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    97
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    98
Elements = []
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    99
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   100
ChapterStyle = copy.copy(styles["Heading1"])
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
   101
ChapterStyle.alignment = TA_CENTER
195
9ec081129a84 Minor fixes and changes for comparison with dodyssey.py
rgbecker
parents: 129
diff changeset
   102
ChapterStyle.fontsize = 16
9ec081129a84 Minor fixes and changes for comparison with dodyssey.py
rgbecker
parents: 129
diff changeset
   103
InitialStyle = copy.deepcopy(ChapterStyle)
9ec081129a84 Minor fixes and changes for comparison with dodyssey.py
rgbecker
parents: 129
diff changeset
   104
InitialStyle.fontsize = 16
203
0e2031146bf5 Title leading changes
rgbecker
parents: 198
diff changeset
   105
InitialStyle.leading = 20
195
9ec081129a84 Minor fixes and changes for comparison with dodyssey.py
rgbecker
parents: 129
diff changeset
   106
PreStyle = styles["Code"] 
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   107
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   108
def newPage():
225
1f58b00cf30e Changes related to removal of SimpleFlowDocument
rgbecker
parents: 207
diff changeset
   109
	Elements.append(PageBreak())
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   110
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   111
def chapter(txt, style=ChapterStyle):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   112
	newPage()
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
   113
	Elements.append(Paragraph(txt, style))
225
1f58b00cf30e Changes related to removal of SimpleFlowDocument
rgbecker
parents: 207
diff changeset
   114
	Elements.append(Spacer(0.2*inch, 0.3*inch))
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   115
195
9ec081129a84 Minor fixes and changes for comparison with dodyssey.py
rgbecker
parents: 129
diff changeset
   116
def fTitle(txt,style=InitialStyle):
9ec081129a84 Minor fixes and changes for comparison with dodyssey.py
rgbecker
parents: 129
diff changeset
   117
	Elements.append(Paragraph(txt, style))
9ec081129a84 Minor fixes and changes for comparison with dodyssey.py
rgbecker
parents: 129
diff changeset
   118
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 117
diff changeset
   119
ParaStyle = copy.deepcopy(styles["Normal"])
207
52e4ab91cc16 Fix spacing bugs
rgbecker
parents: 203
diff changeset
   120
ParaStyle.spaceBefore = 0.1*inch
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 117
diff changeset
   121
if 'right' in sys.argv:
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
   122
	ParaStyle.alignment = TA_RIGHT
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 117
diff changeset
   123
elif 'left' in sys.argv:
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
   124
	ParaStyle.alignment = TA_LEFT
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 117
diff changeset
   125
elif 'justify' in sys.argv:
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
   126
	ParaStyle.alignment = TA_JUSTIFY
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 117
diff changeset
   127
elif 'center' in sys.argv or 'centre' in sys.argv:
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
   128
	ParaStyle.alignment = TA_CENTER
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 117
diff changeset
   129
else:
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
   130
	ParaStyle.alignment = TA_JUSTIFY
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   131
195
9ec081129a84 Minor fixes and changes for comparison with dodyssey.py
rgbecker
parents: 129
diff changeset
   132
def spacer(inches):
225
1f58b00cf30e Changes related to removal of SimpleFlowDocument
rgbecker
parents: 207
diff changeset
   133
	Elements.append(Spacer(0.1*inch, inches*inch))
195
9ec081129a84 Minor fixes and changes for comparison with dodyssey.py
rgbecker
parents: 129
diff changeset
   134
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   135
def p(txt, style=ParaStyle):
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
   136
	Elements.append(Paragraph(txt, style))
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   137
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   138
def pre(txt, style=PreStyle):
195
9ec081129a84 Minor fixes and changes for comparison with dodyssey.py
rgbecker
parents: 129
diff changeset
   139
	spacer(0.1)
225
1f58b00cf30e Changes related to removal of SimpleFlowDocument
rgbecker
parents: 207
diff changeset
   140
	p = Preformatted(txt, style)
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   141
	Elements.append(p)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   142
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   143
def parseOdyssey(fn):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   144
	from time import time
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   145
	E = []
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   146
	t0=time()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   147
	L = open(fn,'r').readlines()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   148
	t1 = time()
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 117
diff changeset
   149
	print "open(%s,'r').readlines() took %.4f seconds" %(fn,t1-t0)
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   150
	for i in xrange(len(L)):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   151
		if L[i][-1]=='\012':
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   152
			L[i] = L[i][:-1]
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   153
	t2 = time()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   154
	print "Removing all linefeeds took %.4f seconds" %(t2-t1)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   155
	L.append('')
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   156
	L.append('-----')
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   157
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   158
	def findNext(L, i):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   159
		while 1:
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   160
			if string.strip(L[i])=='':
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   161
				del L[i]
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   162
				kind = 1
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   163
				if i<len(L):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   164
					while string.strip(L[i])=='':
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   165
						del L[i]
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   166
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   167
					if i<len(L):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   168
						kind = L[i][-1]=='-' and L[i][0]=='-'
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   169
						if kind:
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   170
							del L[i]
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   171
							if i<len(L):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   172
								while string.strip(L[i])=='':
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   173
									del L[i]
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   174
				break
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   175
			else:
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   176
				i = i + 1
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   177
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   178
		return i, kind
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   179
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   180
	f = s = 0
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   181
	while 1:
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   182
		f, k = findNext(L,0)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   183
		if k: break
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   184
195
9ec081129a84 Minor fixes and changes for comparison with dodyssey.py
rgbecker
parents: 129
diff changeset
   185
	E.append([spacer,2])
9ec081129a84 Minor fixes and changes for comparison with dodyssey.py
rgbecker
parents: 129
diff changeset
   186
	E.append([fTitle,'<font color=red>%s</font>' % Title, InitialStyle])
9ec081129a84 Minor fixes and changes for comparison with dodyssey.py
rgbecker
parents: 129
diff changeset
   187
	E.append([fTitle,'<font size=-4>by</font> <font color=green>%s</font>' % Author, InitialStyle])
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   188
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   189
	while 1:
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   190
		if f>=len(L): break
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   191
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   192
		if string.upper(L[f][0:5])=='BOOK ':
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   193
			E.append([chapter,L[f]])
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   194
			f=f+1
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   195
			while string.strip(L[f])=='': del L[f]
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   196
			style = ParaStyle
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   197
			func = p
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   198
		else:
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   199
			style = PreStyle
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   200
			func = pre
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   201
	
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   202
		while 1:
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   203
			s=f
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   204
			f, k=findNext(L,s)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   205
			sep= (func is pre) and '\012' or ' '
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   206
			E.append([func,string.join(L[s:f],sep),style])
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   207
			if k: break
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   208
	t3 = time()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   209
	print "Parsing into memory took %.4f seconds" %(t3-t2)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   210
	del L
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   211
	t4 = time()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   212
	print "Deleting list of lines took %.4f seconds" %(t4-t3)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   213
	for i in xrange(len(E)):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   214
		apply(E[i][0],E[i][1:])
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   215
	t5 = time()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   216
	print "Moving into platypus took %.4f seconds" %(t5-t4)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   217
	del E
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   218
	t6 = time()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   219
	print "Deleting list of actions took %.4f seconds" %(t6-t5)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   220
	go()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   221
	t7 = time()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   222
	print "saving to PDF took %.4f seconds" %(t7-t6)
117
fd3682228853 XML Tagged Paragraph parser changes
rgbecker
parents: 73
diff changeset
   223
	print "Total run took %.4f seconds"%(t7-t0)
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   224
251
6f6cd14069f6 test filename case fix
rgbecker
parents: 226
diff changeset
   225
for fn in ('odyssey.full.txt','odyssey.txt'):
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   226
	if os.path.isfile(fn):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   227
		break
198
5604fb99b2e7 Added 'if __name__=='__main__'' handlers to demos
andy_robinson
parents: 195
diff changeset
   228
if __name__=='__main__':
5604fb99b2e7 Added 'if __name__=='__main__'' handlers to demos
andy_robinson
parents: 195
diff changeset
   229
	parseOdyssey(fn)