reportlab/demos/odyssey/dodyssey.py
changeset 253 cfcf8d555a2c
parent 251 6f6cd14069f6
child 494 54257447cfe9
equal deleted inserted replaced
252:04d4a765d934 253:cfcf8d555a2c
    29 # OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
    29 # OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
    30 # PERFORMANCE OF THIS SOFTWARE. 
    30 # PERFORMANCE OF THIS SOFTWARE. 
    31 #
    31 #
    32 ###############################################################################
    32 ###############################################################################
    33 #	$Log: dodyssey.py,v $
    33 #	$Log: dodyssey.py,v $
       
    34 #	Revision 1.7  2000/06/01 15:23:06  rgbecker
       
    35 #	Platypus re-organisation
       
    36 #
    34 #	Revision 1.6  2000/06/01 09:41:11  rgbecker
    37 #	Revision 1.6  2000/06/01 09:41:11  rgbecker
    35 #	test filename case fix
    38 #	test filename case fix
    36 #
    39 #	
    37 #	Revision 1.5  2000/05/17 22:15:58  rgbecker
    40 #	Revision 1.5  2000/05/17 22:15:58  rgbecker
    38 #	Renamed BasicFrame to Frame
    41 #	Renamed BasicFrame to Frame
    39 #	
    42 #	
    40 #	Revision 1.4  2000/05/13 09:23:45  rgbecker
    43 #	Revision 1.4  2000/05/13 09:23:45  rgbecker
    41 #	Fix spacing bugs
    44 #	Fix spacing bugs
    59 #	XML Tagged Paragraph parser changes
    62 #	XML Tagged Paragraph parser changes
    60 #	
    63 #	
    61 #	Revision 1.1  2000/04/06 08:58:09  rgbecker
    64 #	Revision 1.1  2000/04/06 08:58:09  rgbecker
    62 #	Paragraph formatting version of odyssey.py
    65 #	Paragraph formatting version of odyssey.py
    63 #	
    66 #	
    64 __version__=''' $Id: dodyssey.py,v 1.6 2000/06/01 09:41:11 rgbecker Exp $ '''
    67 __version__=''' $Id: dodyssey.py,v 1.7 2000/06/01 15:23:06 rgbecker Exp $ '''
    65 __doc__=''
    68 __doc__=''
    66 
    69 
    67 #REPORTLAB_TEST_SCRIPT
    70 #REPORTLAB_TEST_SCRIPT
    68 import sys, copy, string, os
    71 import sys, copy, string, os
    69 from reportlab.platypus import doctemplate
    72 from reportlab.platypus import *
    70 from reportlab.platypus.paragraph import Paragraph
       
    71 from reportlab.lib.units import inch
    73 from reportlab.lib.units import inch
    72 from reportlab.lib.styles import getSampleStyleSheet
    74 from reportlab.lib.styles import getSampleStyleSheet
    73 from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY
    75 from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY
    74 
    76 
    75 styles = getSampleStyleSheet()
    77 styles = getSampleStyleSheet()
    86 	canvas.setFont('Times-Roman',9)
    88 	canvas.setFont('Times-Roman',9)
    87 	canvas.drawString(inch, 0.75 * inch, "Page %d" % doc.page)
    89 	canvas.drawString(inch, 0.75 * inch, "Page %d" % doc.page)
    88 	canvas.restoreState()
    90 	canvas.restoreState()
    89 	
    91 	
    90 def go():
    92 def go():
    91 	doc = doctemplate.BaseDocTemplate('dodyssey.pdf',showBoundary=0)
    93 	doc = BaseDocTemplate('dodyssey.pdf',showBoundary=0)
    92 
    94 
    93 	#normal frame as for SimpleFlowDocument
    95 	#normal frame as for SimpleFlowDocument
    94 	frameT = doctemplate.Frame(doc.leftMargin, doc.bottomMargin, doc.width, doc.height, id='normal')
    96 	frameT = Frame(doc.leftMargin, doc.bottomMargin, doc.width, doc.height, id='normal')
    95 
    97 
    96 	#Two Columns
    98 	#Two Columns
    97 	frame1 = doctemplate.Frame(doc.leftMargin, doc.bottomMargin, doc.width/2-6, doc.height, id='col1')
    99 	frame1 = Frame(doc.leftMargin, doc.bottomMargin, doc.width/2-6, doc.height, id='col1')
    98 	frame2 = doctemplate.Frame(doc.leftMargin+doc.width/2+6, doc.bottomMargin, doc.width/2-6,
   100 	frame2 = Frame(doc.leftMargin+doc.width/2+6, doc.bottomMargin, doc.width/2-6,
    99 						doc.height, id='col2')
   101 						doc.height, id='col2')
   100 	doc.addPageTemplates([doctemplate.PageTemplate(id='First',frames=frameT, onPage=myTitlePage),
   102 	doc.addPageTemplates([PageTemplate(id='First',frames=frameT, onPage=myTitlePage),
   101 						doctemplate.PageTemplate(id='OneCol',frames=frameT, onPage=myLaterPages),
   103 						PageTemplate(id='OneCol',frames=frameT, onPage=myLaterPages),
   102 						doctemplate.PageTemplate(id='TwoCol',frames=[frame1,frame2], onPage=myLaterPages),
   104 						PageTemplate(id='TwoCol',frames=[frame1,frame2], onPage=myLaterPages),
   103 						])
   105 						])
   104 	doc.build(Elements)
   106 	doc.build(Elements)
   105 
   107 
   106 Elements = []
   108 Elements = []
   107 
   109 
   112 InitialStyle.fontsize = 16
   114 InitialStyle.fontsize = 16
   113 InitialStyle.leading = 20
   115 InitialStyle.leading = 20
   114 PreStyle = styles["Code"] 
   116 PreStyle = styles["Code"] 
   115 
   117 
   116 def newPage():
   118 def newPage():
   117 	Elements.append(doctemplate.PageBreak())
   119 	Elements.append(PageBreak())
   118 
   120 
   119 def chapter(txt, style=ChapterStyle):
   121 def chapter(txt, style=ChapterStyle):
   120 	Elements.append(doctemplate.NextPageTemplate('OneCol'))
   122 	Elements.append(NextPageTemplate('OneCol'))
   121 	newPage()
   123 	newPage()
   122 	Elements.append(Paragraph(txt, style))
   124 	Elements.append(Paragraph(txt, style))
   123 	Elements.append(doctemplate.Spacer(0.2*inch, 0.3*inch))
   125 	Elements.append(Spacer(0.2*inch, 0.3*inch))
   124 	if useTwoCol:
   126 	if useTwoCol:
   125 		Elements.append(doctemplate.NextPageTemplate('TwoCol'))
   127 		Elements.append(NextPageTemplate('TwoCol'))
   126 
   128 
   127 def fTitle(txt,style=InitialStyle):
   129 def fTitle(txt,style=InitialStyle):
   128 	Elements.append(Paragraph(txt, style))
   130 	Elements.append(Paragraph(txt, style))
   129 	
   131 	
   130 ParaStyle = copy.deepcopy(styles["Normal"])
   132 ParaStyle = copy.deepcopy(styles["Normal"])
   141 	ParaStyle.alignment = TA_JUSTIFY
   143 	ParaStyle.alignment = TA_JUSTIFY
   142 
   144 
   143 useTwoCol = 'notwocol' not in sys.argv 
   145 useTwoCol = 'notwocol' not in sys.argv 
   144 
   146 
   145 def spacer(inches):
   147 def spacer(inches):
   146 	Elements.append(doctemplate.Spacer(0.1*inch, inches*inch))
   148 	Elements.append(Spacer(0.1*inch, inches*inch))
   147 
   149 
   148 def p(txt, style=ParaStyle):
   150 def p(txt, style=ParaStyle):
   149 	Elements.append(Paragraph(txt, style))
   151 	Elements.append(Paragraph(txt, style))
   150 
   152 
   151 firstPre = 1
   153 firstPre = 1
   152 def pre(txt, style=PreStyle):
   154 def pre(txt, style=PreStyle):
   153 	global firstPre
   155 	global firstPre
   154 	if firstPre:
   156 	if firstPre:
   155 		Elements.append(doctemplate.NextPageTemplate('OneCol'))
   157 		Elements.append(NextPageTemplate('OneCol'))
   156 		newPage()
   158 		newPage()
   157 		firstPre = 0
   159 		firstPre = 0
   158 
   160 
   159 	spacer(0.1)
   161 	spacer(0.1)
   160 	p = doctemplate.Preformatted(txt, style)
   162 	p = Preformatted(txt, style)
   161 	Elements.append(p)
   163 	Elements.append(p)
   162 
   164 
   163 def parseOdyssey(fn):
   165 def parseOdyssey(fn):
   164 	from time import time
   166 	from time import time
   165 	E = []
   167 	E = []