Changes related to removal of SimpleFlowDocument
authorrgbecker
Tue, 16 May 2000 16:15:16 +0000
changeset 221 3d71b66b14c6
parent 220 3b27693ac273
child 222 f04b9db53afc
Changes related to removal of SimpleFlowDocument
reportlab/platypus/doctemplate.py
reportlab/platypus/layout.py
reportlab/platypus/paragraph.py
reportlab/platypus/tables.py
--- a/reportlab/platypus/doctemplate.py	Tue May 16 15:58:27 2000 +0000
+++ b/reportlab/platypus/doctemplate.py	Tue May 16 16:15:16 2000 +0000
@@ -31,9 +31,12 @@
 #
 ###############################################################################
 #	$Log: doctemplate.py,v $
+#	Revision 1.8  2000/05/16 16:15:16  rgbecker
+#	Changes related to removal of SimpleFlowDocument
+#
 #	Revision 1.7  2000/05/16 14:28:55  rgbecker
 #	Fixes/Changes to get testplatypus to work with new framework
-#
+#	
 #	Revision 1.6  2000/05/15 15:07:32  rgbecker
 #	Added drawPage
 #	
@@ -52,7 +55,7 @@
 #	Revision 1.1  2000/05/12 12:53:33  rgbecker
 #	Initial try at a document template class
 #	
-__version__=''' $Id: doctemplate.py,v 1.7 2000/05/16 14:28:55 rgbecker Exp $ '''
+__version__=''' $Id: doctemplate.py,v 1.8 2000/05/16 16:15:16 rgbecker Exp $ '''
 __doc__="""
 More complicated Document model
 """
@@ -327,3 +330,84 @@
 			self.handle_flowable(flowables)
 
 		self._endBuild()
+
+class SimpleDocTemplate(BaseDocTemplate):
+	def handle_pageBegin(self):
+		self._handle_pageBegin()
+		self._handle_nextPageTemplate('Later')
+
+	def build(self,flowables,onFirstPage=_doNothing, onLaterPages=_doNothing):
+		frameT = BasicFrame(self.leftMargin, self.bottomMargin, self.width, self.height, id='normal')
+		self.addPageTemplates([PageTemplate(id='First',frames=frameT, onPage=onFirstPage),
+						PageTemplate(id='Later',frames=frameT, onPage=onLaterPages)])
+		BaseDocTemplate.build(self,flowables)
+
+if __name__ == '__main__':
+	##########################################################
+	##
+	##	 testing
+	##
+	##########################################################
+	def randomText():
+		#this may or may not be appropriate in your company
+		from random import randint, choice
+
+		RANDOMWORDS = ['strategic','direction','proactive',
+		'reengineering','forecast','resources',
+		'forward-thinking','profit','growth','doubletalk',
+		'venture capital','IPO']
+
+		sentences = 5
+		output = ""
+		for sentenceno in range(randint(1,5)):
+			output = output + 'Blah'
+			for wordno in range(randint(10,25)):
+				if randint(0,4)==0:
+					word = choice(RANDOMWORDS)
+				else:
+					word = 'blah'
+				output = output + ' ' +word
+			output = output+'.'
+		return output
+
+	def myFirstPage(canvas, doc):
+		canvas.saveState()
+		canvas.setStrokeColor(red)
+		canvas.setLineWidth(5)
+		canvas.line(66,72,66,PAGE_HEIGHT-72)
+		canvas.setFont('Times-Bold',24)
+		canvas.drawString(108, PAGE_HEIGHT-108, "PLATYPUS")
+		canvas.setFont('Times-Roman',12)
+		canvas.drawString(4 * inch, 0.75 * inch, "First Page")
+		canvas.restoreState()
+
+	def myLaterPages(canvas, doc):
+		canvas.saveState()
+		canvas.setStrokeColor(red)
+		canvas.setLineWidth(5)
+		canvas.line(66,72,66,PAGE_HEIGHT-72)
+		canvas.setFont('Times-Roman',12)
+		canvas.drawString(4 * inch, 0.75 * inch, "Page %d" % doc.page)
+		canvas.restoreState()
+
+	def run():
+		objects_to_draw = []
+		from reportlab.lib.styles import ParagraphStyle
+		from paragraph import Paragraph
+
+		#need a style
+		normal = ParagraphStyle('normal')
+		normal.firstLineIndent = 18
+		normal.spaceBefore = 6
+		import random
+		for i in range(15):
+			height = 0.5 + (2*random.random())
+			box = XBox(6 * inch, height * inch, 'Box Number %d' % i)
+			objects_to_draw.append(box)
+			para = Paragraph(randomText(), normal)
+			objects_to_draw.append(para)
+
+		SimpleDocTemplate('doctemplate.pdf',DEFAULT_PAGE_SIZE).build(objects_to_draw,
+			onFirstPage=myFirstPage,onLaterPages=myLaterPages)
+
+	run()
--- a/reportlab/platypus/layout.py	Tue May 16 15:58:27 2000 +0000
+++ b/reportlab/platypus/layout.py	Tue May 16 16:15:16 2000 +0000
@@ -31,9 +31,12 @@
 #
 ###############################################################################
 #	$Log: layout.py,v $
+#	Revision 1.26  2000/05/16 16:15:16  rgbecker
+#	Changes related to removal of SimpleFlowDocument
+#
 #	Revision 1.25  2000/05/15 13:36:11  rgbecker
 #	Splitting changes
-#
+#	
 #	Revision 1.24  2000/05/12 12:52:00  rgbecker
 #	Fixes to BasicFrame split method
 #	
@@ -104,7 +107,7 @@
 #	Revision 1.2  2000/02/15 15:47:09  rgbecker
 #	Added license, __version__ and Logi comment
 #	
-__version__=''' $Id: layout.py,v 1.25 2000/05/15 13:36:11 rgbecker Exp $ '''
+__version__=''' $Id: layout.py,v 1.26 2000/05/16 16:15:16 rgbecker Exp $ '''
 __doc__="""
 Page Layout And TYPography Using Scripts
 a page layout API on top of PDFgen
@@ -542,76 +545,3 @@
 			#print 'drew page %d, %d objects remaining' % (self.page, len(flowables))
 
 		canv.save()
-	##########################################################
-	##
-	##	 testing
-	##
-	##########################################################
-
-def randomText():
-	#this may or may not be appropriate in your company
-	from random import randint, choice
-
-	RANDOMWORDS = ['strategic','direction','proactive',
-	'reengineering','forecast','resources',
-	'forward-thinking','profit','growth','doubletalk',
-	'venture capital','IPO']
-
-	sentences = 5
-	output = ""
-	for sentenceno in range(randint(1,5)):
-		output = output + 'Blah'
-		for wordno in range(randint(10,25)):
-			if randint(0,4)==0:
-				word = choice(RANDOMWORDS)
-			else:
-				word = 'blah'
-			output = output + ' ' +word
-		output = output+'.'
-	return output
-
-def myFirstPage(canvas, doc):
-	canvas.saveState()
-	canvas.setStrokeColor(red)
-	canvas.setLineWidth(5)
-	canvas.line(66,72,66,PAGE_HEIGHT-72)
-	canvas.setFont('Times-Bold',24)
-	canvas.drawString(108, PAGE_HEIGHT-108, "PLATYPUS")
-	canvas.setFont('Times-Roman',12)
-	canvas.drawString(4 * inch, 0.75 * inch, "First Page")
-	canvas.restoreState()
-
-def myLaterPages(canvas, doc):
-	#canvas.drawImage("snkanim.gif", 36, 36)
-	canvas.saveState()
-	canvas.setStrokeColor(red)
-	canvas.setLineWidth(5)
-	canvas.line(66,72,66,PAGE_HEIGHT-72)
-	canvas.setFont('Times-Roman',12)
-	canvas.drawString(4 * inch, 0.75 * inch, "Page %d" % doc.page)
-	canvas.restoreState()
-
-def run():
-	objects_to_draw = []
-	from reportlab.lib.styles import ParagraphStyle
-	from reportlab.platypus.paragraph import Paragraph
-
-	#need a style
-	normal = ParagraphStyle('normal')
-	normal.firstLineIndent = 18
-	normal.spaceBefore = 6
-	import random
-	for i in range(15):
-		height = 0.5 + (2*random.random())
-		box = XBox(6 * inch, height * inch, 'Box Number %d' % i)
-		objects_to_draw.append(box)
-		para = Paragraph(randomText(), normal)
-		objects_to_draw.append(para)
-
-	doc = SimpleFlowDocument('platypus.pdf',DEFAULT_PAGE_SIZE)
-	doc.onFirstPage = myFirstPage
-	doc.onNewPage = myLaterPages
-	doc.build(objects_to_draw)
-
-if __name__ == '__main__':
-	run()
--- a/reportlab/platypus/paragraph.py	Tue May 16 15:58:27 2000 +0000
+++ b/reportlab/platypus/paragraph.py	Tue May 16 16:15:16 2000 +0000
@@ -31,9 +31,12 @@
 #
 ###############################################################################
 #	$Log: paragraph.py,v $
+#	Revision 1.9  2000/05/16 16:15:16  rgbecker
+#	Changes related to removal of SimpleFlowDocument
+#
 #	Revision 1.8  2000/05/16 15:58:27  rgbecker
 #	Fixed font setting bug
-#
+#	
 #	Revision 1.7  2000/05/16 14:28:55  rgbecker
 #	Fixes/Changes to get testplatypus to work with new framework
 #	
@@ -55,12 +58,12 @@
 #	Revision 1.1  2000/04/14 13:21:52  rgbecker
 #	Removed from layout.py
 #	
-__version__=''' $Id: paragraph.py,v 1.8 2000/05/16 15:58:27 rgbecker Exp $ '''
+__version__=''' $Id: paragraph.py,v 1.9 2000/05/16 16:15:16 rgbecker Exp $ '''
 import string
 import types
 from reportlab.pdfbase.pdfmetrics import stringWidth
 from reportlab.platypus.paraparser import ParaParser, ParaFrag
-from reportlab.platypus.layout import Flowable
+from layout import Flowable
 from reportlab.lib.colors import Color
 from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY
 from copy import deepcopy
--- a/reportlab/platypus/tables.py	Tue May 16 15:58:27 2000 +0000
+++ b/reportlab/platypus/tables.py	Tue May 16 16:15:16 2000 +0000
@@ -31,10 +31,13 @@
 #
 ###############################################################################
 #	$Log: tables.py,v $
+#	Revision 1.9  2000/05/16 16:15:16  rgbecker
+#	Changes related to removal of SimpleFlowDocument
+#
 #	Revision 1.8  2000/04/26 11:07:15  andy_robinson
 #	Tables changed to use reportlab.lib.colors instead of
 #	the six hard-coded color strings there previously.
-#
+#	
 #	Revision 1.7  2000/04/14 12:17:05  rgbecker
 #	Splitting layout.py
 #	
@@ -53,13 +56,13 @@
 #	Revision 1.2  2000/02/15 15:47:09  rgbecker
 #	Added license, __version__ and Logi comment
 #	
-__version__=''' $Id: tables.py,v 1.8 2000/04/26 11:07:15 andy_robinson Exp $ '''
+__version__=''' $Id: tables.py,v 1.9 2000/05/16 16:15:16 rgbecker Exp $ '''
 __doc__="""
 Tables are created by passing the constructor a tuple of column widths, a tuple of row heights and the data in
 row order. Drawing of the table can be controlled by using a TableStyle instance. This allows control of the
 color and weight of the lines (if any), and the font, alignment and padding of the text.
 """
-from reportlab.platypus import layout
+from reportlab.platypus.doctemplate import *
 from reportlab.platypus.paragraph import Paragraph
 from reportlab.lib.styles import PropertySet, getSampleStyleSheet
 from reportlab.lib import colors
@@ -92,7 +95,7 @@
     def getCommands(self):
         return self._cmds
         
-class Table(layout.Flowable):
+class Table(Flowable):
     def __init__(self, colWidths, rowHeights, data):
         if not colWidths:
             raise ValueError, "Table must have at least 1 column"
@@ -328,13 +331,12 @@
         ('Key Ring', 0,0,0,0,0,0,1,0,0,0,2,13),
         ('Hats', 893, 912, '1,212', 643, 789, 159, 888, '1,298', 832, 453, '1,344','2,843')
         )
-    doc = layout.SimpleFlowDocument('testtables.pdf', layout.DEFAULT_PAGE_SIZE, 1)
     styleSheet = getSampleStyleSheet()
     lst = []
     lst.append(Paragraph("Tables", styleSheet['Heading1']))
     lst.append(Paragraph(__doc__, styleSheet['BodyText']))
     lst.append(Paragraph("The Tables (shown in different styles below) were created using the following code:", styleSheet['BodyText']))
-    lst.append(layout.Preformatted("""
+    lst.append(Preformatted("""
     colwidths = (50, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32)
     rowheights = (24, 16, 16, 16, 16)
     data = (
@@ -352,7 +354,7 @@
     You can then give the Table a TableStyle object to control its format. The first TableStyle used was
     created as follows:
     """, styleSheet['BodyText']))
-    lst.append(layout.Preformatted("""
+    lst.append(Preformatted("""
 GRID_STYLE = TableStyle(
     [('GRID', (0,0), (-1,-1), 0.25, colors.black),
      ('ALIGN', (1,1), (-1,-1), 'RIGHT')]
@@ -396,7 +398,7 @@
     """, styleSheet['BodyText']))
     t = Table(colwidths, rowheights,  data)
     t.setStyle(GRID_STYLE)
-    lst.append(layout.PageBreak())
+    lst.append(PageBreak())
     lst.append(Paragraph("This is GRID_STYLE\n", styleSheet['BodyText']))
     lst.append(t)
     
@@ -407,7 +409,7 @@
     lst.append(Paragraph("""
     It was created as follows:
     """, styleSheet['BodyText']))
-    lst.append(layout.Preformatted("""
+    lst.append(Preformatted("""
 BOX_STYLE = TableStyle(
     [('BOX', (0,0), (-1,-1), 0.50, colors.black),
      ('ALIGN', (1,1), (-1,-1), 'RIGHT')]
@@ -421,7 +423,7 @@
     lst.append(Paragraph("""
     It was created as follows:
     """, styleSheet['BodyText']))
-    lst.append(layout.Preformatted("""
+    lst.append(Preformatted("""
 LABELED_GRID_STYLE = TableStyle(
     [('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
      ('BOX', (0,0), (-1,-1), 2, colors.black),
@@ -430,7 +432,7 @@
      ('ALIGN', (1,1), (-1,-1), 'RIGHT')]
     )
     """, styleSheet['Code']))
-    lst.append(layout.PageBreak())
+    lst.append(PageBreak())
     
     t = Table(colwidths, rowheights,  data)
     t.setStyle(COLORED_GRID_STYLE)
@@ -439,7 +441,7 @@
     lst.append(Paragraph("""
     It was created as follows:
     """, styleSheet['BodyText']))
-    lst.append(layout.Preformatted("""
+    lst.append(Preformatted("""
 COLORED_GRID_STYLE = TableStyle(
     [('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
      ('BOX', (0,0), (-1,-1), 2, colors.red),
@@ -456,7 +458,7 @@
     lst.append(Paragraph("""
     It was created as follows:
     """, styleSheet['BodyText']))
-    lst.append(layout.Preformatted("""
+    lst.append(Preformatted("""
 LIST_STYLE = TableStyle(
     [('LINEABOVE', (0,0), (-1,0), 2, colors.green),
      ('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black),
@@ -480,7 +482,7 @@
     lst.append(Paragraph("""
     It was created as follows:
     """, styleSheet['BodyText']))
-    lst.append(layout.Preformatted("""
+    lst.append(Preformatted("""
    ts = TableStyle(
     [('LINEABOVE', (0,0), (-1,0), 2, colors.green),
      ('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black),
@@ -490,7 +492,7 @@
      ('BACKGROUND', (0,0), (-1,0), colors.Color(0,0.7,0.7))]
     )
     """, styleSheet['Code']))
-    doc.build(lst)
+    SimpleDocTemplate('testtables.pdf', DEFAULT_PAGE_SIZE, showBoundary=1).build(lst)
 
 if __name__ == '__main__':
     test()