Removal of SimpleFrame
authorrgbecker
Wed, 17 May 2000 16:30:09 +0000
changeset 226 a9acb67cdef7
parent 225 1f58b00cf30e
child 227 fa5b4d81f471
Removal of SimpleFrame
reportlab/demos/odyssey/fodyssey.py
reportlab/demos/pythonpoint/pythonpoint.py
reportlab/platypus/doctemplate.py
reportlab/platypus/layout.py
utils/yaml/platdemos.py
utils/yaml/platprop.yml
utils/yaml/sample.txt
utils/yaml/simple_doc.py
utils/yaml/yaml.py
utils/yaml/yaml2pdf.py
--- a/reportlab/demos/odyssey/fodyssey.py	Wed May 17 15:39:10 2000 +0000
+++ b/reportlab/demos/odyssey/fodyssey.py	Wed May 17 16:30:09 2000 +0000
@@ -31,9 +31,12 @@
 #
 ###############################################################################
 #	$Log: fodyssey.py,v $
+#	Revision 1.10  2000/05/17 16:29:39  rgbecker
+#	Removal of SimpleFrame
+#
 #	Revision 1.9  2000/05/17 15:37:33  rgbecker
 #	Changes related to removal of SimpleFlowDocument
-#
+#	
 #	Revision 1.8  2000/05/13 09:23:45  rgbecker
 #	Fix spacing bugs
 #	
@@ -58,7 +61,7 @@
 #	Revision 1.1  2000/04/06 08:58:09  rgbecker
 #	Paragraph formatting version of odyssey.py
 #	
-__version__=''' $Id: fodyssey.py,v 1.9 2000/05/17 15:37:33 rgbecker Exp $ '''
+__version__=''' $Id: fodyssey.py,v 1.10 2000/05/17 16:29:39 rgbecker Exp $ '''
 __doc__=''
 
 #REPORTLAB_TEST_SCRIPT
@@ -85,7 +88,7 @@
 	canvas.restoreState()
 	
 def go():
-	doc = SimpleDocTemplate('fodyssey.pdf',DEFAULT_PAGE_SIZE,showBoundary=0)
+	doc = SimpleDocTemplate('fodyssey.pdf',DEFAULT_PAGE_SIZE,showBoundary='showboundary' in sys.argv)
 	doc.allowSplitting = not 'nosplitting' in sys.argv
 	doc.build(Elements,myFirstPage,myLaterPages)
 
--- a/reportlab/demos/pythonpoint/pythonpoint.py	Wed May 17 15:39:10 2000 +0000
+++ b/reportlab/demos/pythonpoint/pythonpoint.py	Wed May 17 16:30:09 2000 +0000
@@ -31,9 +31,12 @@
 #
 ###############################################################################
 #	$Log: pythonpoint.py,v $
+#	Revision 1.17  2000/05/17 16:29:40  rgbecker
+#	Removal of SimpleFrame
+#
 #	Revision 1.16  2000/05/16 23:48:00  andy_robinson
 #	Allowed intra-paragraph text; fixed various bugs
-#
+#	
 #	Revision 1.15  2000/04/28 17:04:28  andy_robinson
 #	Changed to display multiple outline levels
 #	
@@ -84,7 +87,7 @@
 #	Revision 1.1.1.1  2000/02/15 15:08:55  rgbecker
 #	Initial setup of demos directory and contents.
 #	
-__version__=''' $Id: pythonpoint.py,v 1.16 2000/05/16 23:48:00 andy_robinson Exp $ '''
+__version__=''' $Id: pythonpoint.py,v 1.17 2000/05/17 16:29:40 rgbecker Exp $ '''
 # xml parser stuff for PythonPoint
 # PythonPoint Markup Language!
 __doc__="""
@@ -237,23 +240,20 @@
 
     def drawOn(self, canv):
         #make a layout frame
-        frame = layout.SimpleFrame(canv,
-                                   self.x,
+        frame = layout.BasicFrame( self.x,
                                    self.y,
                                    self.width,
-                                   self.height)
-                    
-        frame.showBoundary = self.showBoundary
-        
+                                   self.height,
+                                   showBoundary=1)
+ 
         #build a story for the frame
         story = []
         for thingy in self.content:
             #ask it for any flowables
             story.append(thingy.getFlowable())
         #draw it
-        frame.addFromList(story)
-
-        
+        frame.addFromList(story,canv)
+ 
 class PPPara:
     """This is a placeholder for a paragraph."""
     def __init__(self):
--- a/reportlab/platypus/doctemplate.py	Wed May 17 15:39:10 2000 +0000
+++ b/reportlab/platypus/doctemplate.py	Wed May 17 16:30:09 2000 +0000
@@ -31,9 +31,12 @@
 #
 ###############################################################################
 #	$Log: doctemplate.py,v $
+#	Revision 1.10  2000/05/17 16:29:40  rgbecker
+#	Removal of SimpleFrame
+#
 #	Revision 1.9  2000/05/17 15:37:33  rgbecker
 #	Changes related to removal of SimpleFlowDocument
-#
+#	
 #	Revision 1.8  2000/05/16 16:15:16  rgbecker
 #	Changes related to removal of SimpleFlowDocument
 #	
@@ -58,7 +61,7 @@
 #	Revision 1.1  2000/05/12 12:53:33  rgbecker
 #	Initial try at a document template class
 #	
-__version__=''' $Id: doctemplate.py,v 1.9 2000/05/17 15:37:33 rgbecker Exp $ '''
+__version__=''' $Id: doctemplate.py,v 1.10 2000/05/17 16:29:40 rgbecker Exp $ '''
 __doc__="""
 More complicated Document model
 """
@@ -207,12 +210,7 @@
 	def handle_frameBegin(self,*args):
 		self.frame._reset()
 		if self.showBoundary or self.frame.showBoundary:
-			self.canv.rect(
-						self.frame.x1,
-						self.frame.y1,
-						self.frame.x2 - self.frame.x1,
-						self.frame.y2 - self.frame.y1
-						)
+			self.frame.drawBoundary(self.canv)
 
 	def handle_frameEnd(self):
 		'''	Handles the semantics of the end of a frame. This includes the selection of
--- a/reportlab/platypus/layout.py	Wed May 17 15:39:10 2000 +0000
+++ b/reportlab/platypus/layout.py	Wed May 17 16:30:09 2000 +0000
@@ -31,9 +31,12 @@
 #
 ###############################################################################
 #	$Log: layout.py,v $
+#	Revision 1.27  2000/05/17 16:29:40  rgbecker
+#	Removal of SimpleFrame
+#
 #	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
 #	
@@ -107,7 +110,7 @@
 #	Revision 1.2  2000/02/15 15:47:09  rgbecker
 #	Added license, __version__ and Logi comment
 #	
-__version__=''' $Id: layout.py,v 1.26 2000/05/16 16:15:16 rgbecker Exp $ '''
+__version__=''' $Id: layout.py,v 1.27 2000/05/17 16:29:40 rgbecker Exp $ '''
 __doc__="""
 Page Layout And TYPography Using Scripts
 a page layout API on top of PDFgen
@@ -401,47 +404,25 @@
 		s = self.atTop and 0 or flowable.getSpaceBefore()
 		return flowable.split(self.width, y-p-s)
 
-
-#############################################################
-#	A Frame, and a Document Model
-#############################################################
-FrameFullError = "FrameFullError"
-LayoutError = "LayoutError"
+	def drawBoundary(self,canv):
+		canv.rect(
+				self.x1,
+				self.y1,
+				self.x2 - self.x1,
+				self.y2 - self.y1
+				)
 
-class SimpleFrame(BasicFrame):
-	"""A region into which flowable objects are to be packed.
-	Flows downwards.  A more general solution is needed which
-	will allow flows in any direction, including 'across and then
-	down' for small objects, but this is useful for
-	many languages now, as long as each object is 'full-width'
-	(i.e. a paragraph and not a word)."""
-	def __init__(self, canvas, x1, y1, width,height):
-		BasicFrame.__init__(self, x1, y1, width,height, leftPadding=6, bottomPadding=6,
-			rightPadding=6, topPadding=6, id=None, showBoundary=0)
-		self.canvas = canvas
-		self.objects = []	#it keeps a list of objects
-
-	def add(self, flowable):
-		r = self._add(flowable, self.canvas)
-		if r: self.objects.append(flowable)
-		return r
-
-	def addFromList(self, drawlist):
+	def addFromList(self, drawlist, canv):
 		"""Consumes objects from the front of the list until the
 		frame is full.	If it cannot fit one object, raises
 		an exception."""
 
 		if self.showBoundary:
-			self.canvas.rect(
-						self.x1,
-						self.y1,
-						self.x2 - self.x1,
-						self.y2 - self.y1
-						)
+			self.drawBoundary(canv)
 
 		while len(drawlist) > 0:
 			head = drawlist[0]
-			if self.add(head):
+			if self.add(head,canv,trySplit=0):
 				del drawlist[0]
 			else:
 				#leave it in the list for later
@@ -481,67 +462,3 @@
 def _doNothing(canvas, doc):
 	"Dummy callback for onPage"
 	pass
-
-##########################################################
-#
-#
-#
-##########################################################
-class SimpleFlowDocument:
-	"""A sample document that uses a single frame on each page.
-	The intention is for programmers to create their own document
-	models as needed.  This one accepts a list of flowables. You
-	can provide callbacks to decorate the first page and
-	subsequent pages; these should do headers, footers, sidebars
-	as needed."""
-	def __init__(self, filename, pagesize, showBoundary=0):
-		self.filename = filename
-		self.pagesize = pagesize
-		self.showBoundary=showBoundary
-		#sensibel defaults; override if you wish
-		self.leftMargin =  inch
-		self.bottomMargin = inch
-		self.rightMargin = self.pagesize[0] - inch
-		self.topMargin = self.pagesize[1] - inch
-
-		# 1-based counting is friendlier for readers
-		self.page = 1
-		#set these to drawing procedures of your own
-		self.onFirstPage = _doNothing
-		self.onNewPage = _doNothing
-
-
-	def build(self, flowables):
-		canv = canvas.Canvas(self.filename)
-		#canv.setPageTransition('Dissolve')
-
-		# do page 1
-		self.onFirstPage(canv, self)
-		frame1 = SimpleFrame(
-					canv,
-					self.leftMargin,
-					self.bottomMargin,
-					self.rightMargin - self.leftMargin,
-					self.topMargin - inch - self.bottomMargin
-							)
-		frame1.showBoundary = self.showBoundary
-		frame1.addFromList(flowables)
-		#print 'drew page %d, %d objects remaining' % (self.page, len(flowables))
-		# do subsequent pages
-		while len(flowables) > 0:
-			canv.showPage()
-			self.page = self.page + 1
-			self.onNewPage(canv, self)
-			frame = SimpleFrame(
-					canv,
-					self.leftMargin,
-					self.bottomMargin,
-					self.rightMargin - self.leftMargin,
-					self.topMargin - self.bottomMargin
-							)
-			frame.showBoundary = self.showBoundary
-			frame.addFromList(flowables)
-
-			#print 'drew page %d, %d objects remaining' % (self.page, len(flowables))
-
-		canv.save()
--- a/utils/yaml/platdemos.py	Wed May 17 15:39:10 2000 +0000
+++ b/utils/yaml/platdemos.py	Wed May 17 16:30:09 2000 +0000
@@ -3,7 +3,7 @@
 from reportlab.lib import colors
 from reportlab.pdfgen.canvas import Canvas
 from reportlab.lib.styles import ParagraphStyle
-from reportlab.platypus.layout import SimpleFrame, Flowable
+from reportlab.platypus.layout import BasicFrame, Flowable
 from reportlab.platypus.paragraph import Paragraph
 from reportlab.lib.units import inch
 from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER
@@ -98,14 +98,13 @@
 
 
 def demo1(canvas):
-    frame = SimpleFrame(
-                    canvas,
+    frame = BasicFrame(
                     2*inch,     # x
                     4*inch,     # y at bottom
                     4*inch,     # width
-                    5*inch     # height
+                    5*inch,     # height
+                    showBoundary = 1  # helps us see what's going on
                     )
-    frame.showBoundary = 1  # helps us see what's going on
 
     bodyStyle = ParagraphStyle('Body',
                        fontName='Times-Roman',
@@ -120,16 +119,15 @@
 
     #this does the packing and drawing.  The frame will consume
     #items from the front of the list as it prints them
-    frame.addFromList(mydata)
+    frame.addFromList(mydata,canvas)
 
 
 def test1():
     c  = Canvas('platdemos.pdf')
-    f = SimpleFrame(c, inch, inch, 6*inch, 9*inch)
-    f.showBoundary = 1
+    f = BasicFrame(inch, inch, 6*inch, 9*inch, showBoundary=1)
     v = PlatPropFigure1()
-    f.addFromList([v])
+    f.addFromList([v],c)
     c.save()
     
 if __name__ == '__main__':
-    test1()
\ No newline at end of file
+    test1()
--- a/utils/yaml/platprop.yml	Wed May 17 15:39:10 2000 +0000
+++ b/utils/yaml/platprop.yml	Wed May 17 16:30:09 2000 +0000
@@ -4,6 +4,9 @@
 CVS Revision History
 .beginPre Code
 $Log: platprop.yml,v $
+Revision 1.6  2000/05/17 16:30:09  rgbecker
+Removal of SimpleFrame
+
 Revision 1.5  2000/05/16 15:40:25  andy_robinson
 It now actually says something - checking in before going home
 
@@ -311,7 +314,7 @@
 ]]></font>
 
 
-Paragraphs permit two escaping mechanisms which you can use when you really want  to print things which might be mistaken for XML.  The first is to use standard HTML entity references.  Thus <b><!CDATA[[&lt;]]></b> produces the character %lt;.  This is the easiest to use for mathematical formulae and code (although no XML processing is done on Preformatted objects, which are the preferred form for printing code).  The second is the standard XML CDATA escaping mechanism.  Anything found between the escape sequences <b>%lt;!CDATA[[</b> and <b>]]&gt;</b> will not be checked for tags; this is thus a very useful mechanism when writing an entire paragraph of XML tags.
+Paragraphs permit two escaping mechanisms which you can use when you really want  to print things which might be mistaken for XML.  The first is to use standard HTML entity references.  Thus <b><![CDATA[&lt;]]></b> produces the character <b>&lt;</b>.  This is the easiest to use for mathematical formulae and code (although no XML processing is done on Preformatted objects, which are the preferred form for printing code).  The second is the standard XML CDATA escaping mechanism.  Anything found between the escape sequences <b>%lt;!CDATA[[</b> and <b>]]&gt;</b> will not be checked for tags; this is thus a very useful mechanism when writing an entire paragraph of XML tags.
 
 The tags which may be used within a paragraph are listed below.  The meanings should be obvious:
 
--- a/utils/yaml/sample.txt	Wed May 17 15:39:10 2000 +0000
+++ b/utils/yaml/sample.txt	Wed May 17 16:30:09 2000 +0000
@@ -3,7 +3,7 @@
 .Heading2 What is ReportLab?
 
 ReportLab is a new generation reporting tool for the 
-Internet era.  <b>The core is a software library</b> which 
+Internet era.  <b>The <font color=red>core</font> is a software library</b> which 
 directly generates PDF documents, without the need 
 for Acrobat Distiller, PostScript or any print drivers.  
 Every report consists of a script which can
@@ -29,4 +29,4 @@
 Centered centered centered. Centered centered centered.
 Centered centered centered. Centered centered centered.
 Centered centered centered. Centered centered centered.
-Centered centered centered. Centered centered centered. 
\ No newline at end of file
+Centered centered centered. Centered centered centered. 
--- a/utils/yaml/simple_doc.py	Wed May 17 15:39:10 2000 +0000
+++ b/utils/yaml/simple_doc.py	Wed May 17 16:30:09 2000 +0000
@@ -139,8 +139,9 @@
 
 .H stuff for HTML ONLY you've been warned RGB :)
 """
-from reportlab.platypus import layout
-inch = layout.inch
+from reportlab.platypus.doctemplate import *
+from reportlab.platypus.paragraph import Paragraph
+from reportlab.lib.styles import getSampleStyleSheet
 import string
 
 do_images = 1
@@ -152,12 +153,12 @@
 	def __init__(self):
 		self.elts = []
 		self.paragraph = []
-		styles = layout.getSampleStyleSheet()
+		styles = getSampleStyleSheet()
 		self.paraStyle = styles["Normal"]
 		self.headerStyle = styles["Heading3"]
 		self.preStyle = styles["Code"]
 		self.modeStyles = {"normal": self.paraStyle, "preformatted": self.preStyle}
-		self.modeFormat = {"normal": layout.Paragraph, "preformatted": layout.Preformatted}
+		self.modeFormat = {"normal": Paragraph, "preformatted": Preformatted}
 		self.mode = "normal"
 
 	def add_text(self, text):
@@ -188,11 +189,11 @@
 		self.paragraph = []
 
 	def emit_paragraph(self, body):
-		#s1 = layout.Spacer(0.2*inch, 0.2*inch)
+		#s1 = Spacer(0.2*inch, 0.2*inch)
 		style = self.modeStyles[self.mode]
 		formatter = self.modeFormat[self.mode]
 		t = formatter(body, style)
-		s2 = layout.Spacer(10, 10)
+		s2 = Spacer(10, 10)
 		e = self.elts
 		e.append(t)
 		e.append(s2)
@@ -202,13 +203,13 @@
 
 	def addHeader(self, header):
 		self.addItem(header)
-		s2 = layout.Spacer(0.2*inch, 0.2*inch)
+		s2 = Spacer(0.2*inch, 0.2*inch)
 		e = self.elts
 		e.append(s2)
 		
 	def addItem(self, item):
-		s1 = layout.Spacer(0.2*inch, 0.2*inch)
-		t = layout.Paragraph(item, self.headerStyle)
+		s1 = Spacer(0.2*inch, 0.2*inch)
+		t = Paragraph(item, self.headerStyle)
 		e = self.elts
 		e.append(s1)
 		e.append(t)
@@ -223,13 +224,13 @@
 		canvas.rect(20,20,90,802,stroke=0, fill=1)
 		#if do_images:
 		#	canvas.drawInlineImage("images/replog.gif",20,750,90,60)
-		#	canvas.drawInlineImage("images/reppow.jpg", 2*inch, layout.PAGE_HEIGHT-3*inch)
+		#	canvas.drawInlineImage("images/reppow.jpg", 2*inch, PAGE_HEIGHT-3*inch)
 		canvas.setStrokeColorRGB(1,0,0)
 		canvas.setLineWidth(5)
 		canvas.setFont("Helvetica-Bold",16)
-		canvas.drawCentredString(4*inch, layout.PAGE_HEIGHT-4*inch, self.Title)
+		canvas.drawCentredString(4*inch, PAGE_HEIGHT-4*inch, self.Title)
 		canvas.setFont('Times-Roman',9)
-		canvas.drawString(2*inch, layout.PAGE_HEIGHT-0.50 * inch, "First Page / %s" % self.Title)
+		canvas.drawString(2*inch, PAGE_HEIGHT-0.50 * inch, "First Page / %s" % self.Title)
 		canvas.restoreState()
 	
 	def myLaterPages(self, canvas, doc):
@@ -240,7 +241,7 @@
 		#	canvas.drawInlineImage("images/replog.gif",20,750,90,60)
 		canvas.setFont('Times-Roman',9)
 		pageinfo=self.Title
-		canvas.drawString(2*inch, layout.PAGE_HEIGHT-0.5 * inch, "Page %d %s" % (doc.page, pageinfo))
+		canvas.drawString(2*inch, PAGE_HEIGHT-0.5 * inch, "Page %d %s" % (doc.page, pageinfo))
 		canvas.restoreState()
 
 	def process(self, lines, tofilename):
@@ -272,12 +273,12 @@
 			self.finish(tofilename)
 
 	def finish(self, tofilename):
-		doc = layout.SimpleFlowDocument(tofilename, layout.DEFAULT_PAGE_SIZE)
+		doc = SimpleDocTemplate(tofilename, DEFAULT_PAGE_SIZE)
 		doc.onFirstPage = self.myFirstPage
-		doc.onNewPage = self.myLaterPages
+		doc.onLaterPages = self.myLaterPages
 		doc.leftMargin = 144
 		elts = self.elts
-		elts.insert(0, layout.Spacer(4*inch, 4*inch)) # make space for title
+		elts.insert(0, Spacer(4*inch, 4*inch)) # make space for title
 		doc.build(self.elts)
 
 	def processfile(self, fn, tofilename):
@@ -332,11 +333,10 @@
 if __name__=='__main__':
 	if len(sys.argv) <> 2:
 		print 'Usage: simple_doc.py myfile.txt  will create HTML and PDF versions'
+		filename = 'sample.txt'
 	else:
 		filename = sys.argv[1]
-		if os.path.isfile(filename):
-			DoDualFormatPages([filename])
-		else:
-			print '%s not found' % filename
-			
-	
\ No newline at end of file
+	if os.path.isfile(filename):
+		DoDualFormatPages([filename])
+	else:
+		print '%s not found' % filename
--- a/utils/yaml/yaml.py	Wed May 17 15:39:10 2000 +0000
+++ b/utils/yaml/yaml.py	Wed May 17 16:30:09 2000 +0000
@@ -138,7 +138,7 @@
         
         
 
-if __name__=='__main__':
+if __name__=='__main__': #NORUNTESTS
     if len(sys.argv) <> 2:
         print 'usage: aml.py source.txt'
     else:
--- a/utils/yaml/yaml2pdf.py	Wed May 17 15:39:10 2000 +0000
+++ b/utils/yaml/yaml2pdf.py	Wed May 17 16:30:09 2000 +0000
@@ -216,7 +216,7 @@
                                   textColor=colors.navy,
                                   alignment=TA_CENTER),
                    alias='u')
-        
+ 
     stylesheet.add(ParagraphStyle(name='centred',
                                   parent=stylesheet['Normal'],
                                   alignment=TA_CENTER
@@ -224,9 +224,7 @@
     
     return stylesheet
 
-
-
-if __name__ == '__main__':
+if __name__ == '__main__': #NORUNTESTS
     if len(sys.argv) == 2:
         infilename = sys.argv[1]
         outfilename = os.path.splitext(infilename)[0] + '.pdf'
@@ -236,7 +234,3 @@
             print 'File not found %s' % infilename
     else:
         print __doc__
-            
-
-
-    
\ No newline at end of file