Fixed page transitions; extended Pythonpoint
authorandy_robinson
Sun, 05 Nov 2000 17:46:15 +0000
changeset 500 58d712fef651
parent 499 2b9a27c589ba
child 501 327ee9cd6469
Fixed page transitions; extended Pythonpoint
reportlab/demos/pythonpoint/pythonpoint.py
reportlab/demos/pythonpoint/pythonpoint.xml
reportlab/demos/pythonpoint/stdparser.py
reportlab/pdfbase/pdfdoc.py
reportlab/pdfgen/canvas.py
reportlab/platypus/doctemplate.py
--- a/reportlab/demos/pythonpoint/pythonpoint.py	Sun Nov 05 17:43:34 2000 +0000
+++ b/reportlab/demos/pythonpoint/pythonpoint.py	Sun Nov 05 17:46:15 2000 +0000
@@ -1,8 +1,8 @@
 #copyright ReportLab Inc. 2000
 #see license.txt for license details
 #history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/demos/pythonpoint/pythonpoint.py?cvsroot=reportlab
-#$Header: /tmp/reportlab/reportlab/demos/pythonpoint/Attic/pythonpoint.py,v 1.26 2000/10/25 08:57:44 rgbecker Exp $
-__version__=''' $Id: pythonpoint.py,v 1.26 2000/10/25 08:57:44 rgbecker Exp $ '''
+#$Header: /tmp/reportlab/reportlab/demos/pythonpoint/Attic/pythonpoint.py,v 1.27 2000/11/05 17:46:15 andy_robinson Exp $
+__version__=''' $Id: pythonpoint.py,v 1.27 2000/11/05 17:46:15 andy_robinson Exp $ '''
 # xml parser stuff for PythonPoint
 # PythonPoint Markup Language!
 __doc__="""
@@ -30,6 +30,8 @@
         PPSlide
         PPFrame
 
+        PPAuthor, PPTitle and PPSubject are optional
+        
     Things to flow within frames...
         PPPara - flowing text
         PPPreformatted - text with line breaks and tabs, for code..
@@ -64,6 +66,9 @@
     def __init__(self):
         self.filename = None
         self.description = None
+        self.title = None
+        self.author = None
+        self.subject = None
         self.speakerNotes = 0   # different printing mode
         self.slides = []
         self.effectName = None
@@ -78,11 +83,14 @@
         canv = canvas.Canvas(self.filename,
                                 pagesize = (self.pageWidth, self.pageHeight)
                                )
+        if self.title:
+            canv.setTitle(self.title)
+        if self.author:
+            canv.setAuthor(self.author)
+        if self.subject:
+            canv.setSubject(self.subject)
         canv.setPageCompression(0)
-            
         for slide in self.slides:
-
-            
             if self.speakerNotes:
                 #frame and shift the slide
                 canv.scale(0.67, 0.67)
@@ -99,6 +107,7 @@
             canv.showOutline()
         canv.save()        
 
+
 class PPSection:
     """A section can hold graphics which will be drawn on all
     pages within it, before frames and other content are done.
@@ -149,7 +158,6 @@
         if self.section:
             self.section.drawOn(canv)
                 
-        canv.drawRightString(800, 36, 'id: %s, title: %s' % (self.id, self.title))
         for graphic in self.graphics:
             graphic.drawOn(canv)
             
@@ -433,6 +441,7 @@
         self.font = 'Times-Roman'
         self.size = 12
         self.color = (0,0,0)
+        self.hasInfo = 0  # these can have data substituted into them
 
     def normalizeText(self):
         """It contains literal XML text typed over several lines.
@@ -448,9 +457,25 @@
         self.text = newtext
         
     def drawOn(self, canv):
+        # for a string in a section, this will be drawn several times;
+        # so any substitution into the text should be in a temporary
+        # variable
+        if self.hasInfo:
+            # provide a dictionary of stuff which might go into
+            # the string, so they can number pages, do headers
+            # etc.
+            info = {}
+            info['title'] = canv._doc.info.title
+            info['author'] = canv._doc.info.author
+            info['subject'] = canv._doc.info.subject
+            info['page'] = canv.getPageNumber()
+            drawText = self.text % info
+        else:
+            drawText = self.text
+
         if self.color is None:
             return
-        lines = string.split(string.strip(self.text), '\\n')
+        lines = string.split(string.strip(drawText), '\\n')
         canv.saveState()
         canv.setFont(self.font, self.size)
         r,g,b = self.color
--- a/reportlab/demos/pythonpoint/pythonpoint.xml	Sun Nov 05 17:43:34 2000 +0000
+++ b/reportlab/demos/pythonpoint/pythonpoint.xml	Sun Nov 05 17:46:15 2000 +0000
@@ -6,11 +6,17 @@
 <!DOCTYPE presentation SYSTEM "pythonpoint.dtd"> 
 -->
 <presentation filename='pythonpoint.pdf'>
+  <title>PythonPoint Demonstration</title>
+  <author>Andy Robinson</author>
+  <subject>Reportlab Sample Applications</subject>
   <section name = 'Main'>
   	<!-- any graphics in the section go on all its pages as a backdrop -->
     <rectangle x="20" y="20" width="96" height="555" fill="(0,0,0.8)"/>
     <fixedimage  x="20" y="510" width="96" height="64" filename="leftlogo.gif"/>
-
+    <infostring align="right" x="800" y= "36" size="14" >
+            %(title)s, page %(page)s
+    </infostring>
+        
 	<!--Now for the slides-->
      <slide id="Slide001" title="Introduction" effectname='Wipe'>
         <frame x="120" y="72" width="700" height="468" 
--- a/reportlab/demos/pythonpoint/stdparser.py	Sun Nov 05 17:43:34 2000 +0000
+++ b/reportlab/demos/pythonpoint/stdparser.py	Sun Nov 05 17:46:15 2000 +0000
@@ -1,12 +1,12 @@
 #copyright ReportLab Inc. 2000
 #see license.txt for license details
 #history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/demos/pythonpoint/stdparser.py?cvsroot=reportlab
-#$Header: /tmp/reportlab/reportlab/demos/pythonpoint/Attic/stdparser.py,v 1.12 2000/10/25 08:57:44 rgbecker Exp $
+#$Header: /tmp/reportlab/reportlab/demos/pythonpoint/Attic/stdparser.py,v 1.13 2000/11/05 17:46:15 andy_robinson Exp $
 __version__=''' $Id $ '''
 __doc__="""
 Parser for PythonPoint using the xmllib.py in the standard Python
 distribution.  Slow, but always present.  We intend to add new parsers
-as Python 1.6 and the xml package spread in popularity.
+as Python 2.0 and the xml package spread in popularity ad stabilise.
 
 The parser has a getPresentation method; it is called from
 pythonpoint.py.
@@ -146,6 +146,10 @@
         self._curPrefmt = None
         self._curString = None
         self._curTable = None
+        self._curTitle = None
+        self._curAuthor = None
+        self._curSubject = None
+        
         xmllib.XMLParser.__init__(self)
 
     def _arg(self,tag,args,name):
@@ -184,13 +188,28 @@
             self._curString.text = self._curString.text + data
         elif self._curTable:
             self._curTable.rawBlocks.append(data)
+        elif self._curTitle <> None:  # need to allow empty strings,
+            # hence explicitly testing for None
+            self._curTitle = self._curTitle + data
+        elif self._curAuthor <> None:
+            self._curAuthor = self._curAuthor + data
+        elif self._curSubject <> None:
+            self._curSubject = self._curSubject + data
             
     def handle_cdata(self, data):
         #just append to current paragraph text, so we can quote XML
         if self._curPara:
             self._curPara.rawtext = self._curPara.rawtext + data
-        if self._curPrefmt:
+        elif self._curPrefmt:
             self._curPrefmt.rawtext = self._curPrefmt.rawtext + data
+        elif  self._curString:
+            self._curString.text = self._curString.text + data
+        elif self._curTable:
+            self._curTable.rawBlocks.append(data)
+        elif self._curAuthor <> None:
+            self._curAuthor = self._curAuthor + data
+        elif self._curSubject <> None:
+            self._curSubject = self._curSubject + data
         
             
     def start_presentation(self, args):
@@ -203,6 +222,27 @@
         #print 'ended presentation'
         print 'Fully parsed presentation',self._curPres.filename
 
+    def start_title(self, args):
+        self._curTitle = ''
+
+    def end_title(self):
+        self._curPres.title = self._curTitle
+        self._curTitle = None
+
+    def start_author(self, args):
+        self._curAuthor = ''
+
+    def end_author(self):
+        self._curPres.author = self._curAuthor
+        self._curAuthor = None
+        
+    def start_subject(self, args):
+        self._curSubject = ''
+
+    def end_subject(self):
+        self._curPres.subject = self._curSubject
+        self._curSubject = None
+
     def start_stylesheet(self, args):
         #makes it the current style sheet.
         path = self._arg('stylesheet',args,'path')
@@ -463,6 +503,14 @@
             self._curSection.graphics.append(self._curString)
         self._curString = None
 
+    def start_infostring(self, args):
+        # like a string, but lets them embed page no, author etc.
+        self.start_string(args)
+        self._curString.hasInfo = 1
+
+    def end_infostring(self):
+        self.end_string()
+    
     def start_customshape(self, args):
         #loads one
         path = self._arg('customshape',args,'path')
--- a/reportlab/pdfbase/pdfdoc.py	Sun Nov 05 17:43:34 2000 +0000
+++ b/reportlab/pdfbase/pdfdoc.py	Sun Nov 05 17:46:15 2000 +0000
@@ -1,8 +1,9 @@
+
 #copyright ReportLab Inc. 2000
 #see license.txt for license details
 #history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/pdfbase/pdfdoc.py?cvsroot=reportlab
-#$Header: /tmp/reportlab/reportlab/pdfbase/pdfdoc.py,v 1.30 2000/10/25 08:57:45 rgbecker Exp $
-__version__=''' $Id: pdfdoc.py,v 1.30 2000/10/25 08:57:45 rgbecker Exp $ '''
+#$Header: /tmp/reportlab/reportlab/pdfbase/pdfdoc.py,v 1.31 2000/11/05 17:46:15 andy_robinson Exp $
+__version__=''' $Id: pdfdoc.py,v 1.31 2000/11/05 17:46:15 andy_robinson Exp $ '''
 __doc__=""" 
 PDFgen is a library to generate PDF files containing text and graphics.  It is the 
 foundation for a complete reporting solution in Python.  
@@ -748,6 +749,7 @@
     __NoDefault__ = string.split(""" Parent
         MediaBox Resources Contents CropBox Rotate Thumb Annots B Dur Hid Trans AA
         PieceInfo LastModified SeparationInfo ArtBox TrimBox BleedBox ID PZ
+        Trans
     """)
     __Refs__ = string.split("""
         Contents Parent ID
@@ -758,6 +760,7 @@
     hasImages = 0
     compression = 0
     XObjects = None
+    Trans = None
     # transitionstring?
     # xobjects?
     # annotations
@@ -774,6 +777,9 @@
         if type(code) is ListType:
             code = string.join(code, LINEEND)+LINEEND
         self.stream = code
+
+    def setPageTransition(self, tranDict):
+        self.Trans = PDFDictionary(tranDict)
         
     def check_format(self, document):
         # set up parameters unless usual behaviour is suppressed
@@ -1108,7 +1114,7 @@
         D["Title"] = PDFString(self.title)
         D["Author"] = PDFString(self.author)
         D["CreationDate"] = PDFDate()
-        D["Producer"] = PDFString("ReporLab http://www.reportlab.com")
+        D["Producer"] = PDFString("ReportLab http://www.reportlab.com")
         D["Subject"] = PDFString(self.subject)
         PD = PDFDictionary(D)
         return PD.format(document)
--- a/reportlab/pdfgen/canvas.py	Sun Nov 05 17:43:34 2000 +0000
+++ b/reportlab/pdfgen/canvas.py	Sun Nov 05 17:46:15 2000 +0000
@@ -1,8 +1,8 @@
 #copyright ReportLab Inc. 2000
 #see license.txt for license details
 #history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/pdfgen/canvas.py?cvsroot=reportlab
-#$Header: /tmp/reportlab/reportlab/pdfgen/canvas.py,v 1.55 2000/10/25 08:57:45 rgbecker Exp $
-__version__=''' $Id: canvas.py,v 1.55 2000/10/25 08:57:45 rgbecker Exp $ '''
+#$Header: /tmp/reportlab/reportlab/pdfgen/canvas.py,v 1.56 2000/11/05 17:46:15 andy_robinson Exp $
+__version__=''' $Id: canvas.py,v 1.56 2000/11/05 17:46:15 andy_robinson Exp $ '''
 __doc__=""" 
 PDFgen is a library to generate PDF files containing text and graphics.  It is the 
 foundation for a complete reporting solution in Python.  It is also the
@@ -145,7 +145,7 @@
 		
         self._pagesize = pagesize
         #self._currentPageHasImages = 0
-        self._pageTransitionString = ''
+        self._pageTransition = None
         self._destinations = {} # dictionary of destinations for cross indexing.
 
         self.setPageCompression(pageCompression)
@@ -320,7 +320,7 @@
         page.pagewidth = self._pagesize[0]
         page.pageheight = self._pagesize[1]
         page.hasImages = self._currentPageHasImages
-        page.pageTransitionString = self._pageTransitionString
+        page.setPageTransition(self._pageTransition)
         page.setCompression(self._pageCompression)
         #print stream
         page.setStream([self._preamble] + self._code)
@@ -1126,23 +1126,28 @@
             }
         Have fun!
 """
+        # This builds a Python dictionary with the right arguments
+        # for the Trans dictionary in the PDFPage object,
+        # and stores it in the variable _pageTransition.
+        # showPage later passes this to the setPageTransition method
+        # of the PDFPage object, which turns it to a PDFDictionary.
+        self._pageTransition = {}
         if not effectname:
-            self._pageTransitionString = ''
             return
             
         #first check each optional argument has an allowed value
         if direction in [0,90,180,270]:
-            direction_arg = '/Di /%d' % direction
+            direction_arg = ('Di', '/%d' % direction)
         else:
             raise 'PDFError', ' directions allowed are 0,90,180,270'
         
         if dimension in ['H', 'V']:
-            dimension_arg = '/Dm /%s' % dimension
+            dimension_arg = ('Dm', '/' + dimension)
         else:
             raise'PDFError','dimension values allowed are H and V'
         
         if motion in ['I','O']:
-            motion_arg = '/M /%s' % motion
+            motion_arg = ('M', '/' + motion)
         else:
             raise'PDFError','motion values allowed are I and O'
 
@@ -1161,12 +1166,15 @@
             args = PageTransitionEffects[effectname]
         except KeyError:
             raise 'PDFError', 'Unknown Effect Name "%s"' % effectname
-            self._pageTransitionString = ''
-            return
         
-
-        self._pageTransitionString = (('/Trans <</D %d /S /%s ' % (duration, effectname)) + 
-            string.join(args, ' ') + ' >>')
+        # now build the dictionary
+        transDict = {}
+        transDict['Type'] = '/Trans'
+        transDict['D'] = '/%d' % duration
+        transDict['S'] = '/' + effectname
+        for (key, value) in args:
+            transDict[key] = value
+        self._pageTransition = transDict
 
 if __name__ == '__main__':
-    print 'For test scripts, run testpdfgen.py'
+    print 'For test scripts, look in reportlab/test'
--- a/reportlab/platypus/doctemplate.py	Sun Nov 05 17:43:34 2000 +0000
+++ b/reportlab/platypus/doctemplate.py	Sun Nov 05 17:46:15 2000 +0000
@@ -1,8 +1,8 @@
 #copyright ReportLab Inc. 2000
 #see license.txt for license details
 #history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/platypus/doctemplate.py?cvsroot=reportlab
-#$Header: /tmp/reportlab/reportlab/platypus/doctemplate.py,v 1.29 2000/10/25 08:57:45 rgbecker Exp $
-__version__=''' $Id: doctemplate.py,v 1.29 2000/10/25 08:57:45 rgbecker Exp $ '''
+#$Header: /tmp/reportlab/reportlab/platypus/doctemplate.py,v 1.30 2000/11/05 17:46:15 andy_robinson Exp $
+__version__=''' $Id: doctemplate.py,v 1.30 2000/11/05 17:46:15 andy_robinson Exp $ '''
 __doc__="""
 This module contains the core structure of platypus.
 
@@ -29,6 +29,7 @@
 from reportlab.platypus.flowables import *
 from reportlab.platypus.paragraph import Paragraph
 from reportlab.platypus.frames import Frame
+from reportlab.lib.pagesizes import DEFAULT_PAGE_SIZE
 import reportlab.lib.sequencer
 from types import *
 import sys
@@ -91,13 +92,15 @@
 	of a page when this is selected. onPageEnd gets called at the end.
 	derived classes can also implement beforeDrawPage and afterDrawPage if they want
 	"""
-	def __init__(self,id=None,frames=[],onPage=_doNothing, onPageEnd=_doNothing):
+	def __init__(self,id=None,frames=[],onPage=_doNothing, onPageEnd=_doNothing,
+				 pagesize=DEFAULT_PAGE_SIZE):
 		if type(frames) not in (ListType,TupleType): frames = [frames]
 		assert filter(lambda x: not isinstance(x,Frame), frames)==[], "frames argument error"
 		self.id = id
 		self.frames = frames
 		self.onPage = onPage
 		self.onPageEnd = onPageEnd
+		self.pagesize = pagesize
 
 	def beforeDrawPage(self,canv,doc):
 		"""Override this if you want additional functionality or prefer