reportlab/platypus/doctemplate.py
changeset 1668 448a9205be12
parent 1530 1dedd3370a99
child 1669 31cb4c337e0d
equal deleted inserted replaced
1667:dfe2f821f4e2 1668:448a9205be12
     1 #copyright ReportLab Inc. 2000
     1 #copyright ReportLab Inc. 2000
     2 #see license.txt for license details
     2 #see license.txt for license details
     3 #history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/platypus/doctemplate.py?cvsroot=reportlab
     3 #history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/platypus/doctemplate.py?cvsroot=reportlab
     4 #$Header: /tmp/reportlab/reportlab/platypus/doctemplate.py,v 1.52 2002/03/12 15:18:03 rgbecker Exp $
     4 #$Header: /tmp/reportlab/reportlab/platypus/doctemplate.py,v 1.53 2002/07/07 22:29:02 andy_robinson Exp $
     5 
     5 
     6 __version__=''' $Id: doctemplate.py,v 1.52 2002/03/12 15:18:03 rgbecker Exp $ '''
     6 __version__=''' $Id: doctemplate.py,v 1.53 2002/07/07 22:29:02 andy_robinson Exp $ '''
     7 
     7 
     8 __doc__="""
     8 __doc__="""
     9 This module contains the core structure of platypus.
     9 This module contains the core structure of platypus.
    10 
    10 
    11 Platypus constructs documents.	Document styles are determined by DocumentTemplates.
    11 Platypus constructs documents.	Document styles are determined by DocumentTemplates.
   282 		# passed to indexing flowables.
   282 		# passed to indexing flowables.
   283 		self._pageRefs = {}
   283 		self._pageRefs = {}
   284 		self._indexingFlowables = []
   284 		self._indexingFlowables = []
   285 
   285 
   286 
   286 
   287 		#callback facility
   287 		#callback facility for progress monitoring
   288 		self._onPage = None
   288 		self._onPage = None
       
   289 		self._onProgress = None
       
   290 		self._flowableCount = 0  # so we know how far to go
       
   291 
       
   292 		
   289 		self._calc()
   293 		self._calc()
   290 		self.afterInit()
   294 		self.afterInit()
   291 
   295 
   292 	def _calc(self):
   296 	def _calc(self):
   293 		self._rightMargin = self.pagesize[0] - self.rightMargin
   297 		self._rightMargin = self.pagesize[0] - self.rightMargin
   294 		self._topMargin = self.pagesize[1] - self.topMargin
   298 		self._topMargin = self.pagesize[1] - self.topMargin
   295 		self.width = self._rightMargin - self.leftMargin
   299 		self.width = self._rightMargin - self.leftMargin
   296 		self.height = self._topMargin - self.bottomMargin
   300 		self.height = self._topMargin - self.bottomMargin
   297 
   301 
   298 	def setPageCallBack(self, func):
   302 	def setPageCallBack(self, func):
   299 		'Progress monitor - func(pageNo) called on each new page'
   303 		'Simple progress monitor - func(pageNo) called on each new page'
   300 		self._onPage = func
   304 		self._onPage = func
       
   305 
       
   306 	def setProgressCallBack(self, func):
       
   307 		'''Cleverer progress monitor - func(typ, value) called regularly'''
       
   308 		self._onProgress = func
   301 
   309 
   302 	def clean_hanging(self):
   310 	def clean_hanging(self):
   303 		'handle internal postponed actions'
   311 		'handle internal postponed actions'
   304 		while len(self._hanging):
   312 		while len(self._hanging):
   305 			self.handle_flowable(self._hanging)
   313 			self.handle_flowable(self._hanging)
   556 		   an alternate canvas which places 6 slides on a page (by
   564 		   an alternate canvas which places 6 slides on a page (by
   557 		   doing translations, scalings and redefining the page break
   565 		   doing translations, scalings and redefining the page break
   558 		   operations).
   566 		   operations).
   559 		"""
   567 		"""
   560 		#assert filter(lambda x: not isinstance(x,Flowable), flowables)==[], "flowables argument error"
   568 		#assert filter(lambda x: not isinstance(x,Flowable), flowables)==[], "flowables argument error"
       
   569 		flowableCount = len(flowables)
       
   570 		if self._onProgress:
       
   571 			self._onProgress('STARTED',0)
       
   572 			self._onProgress('SIZE_EST', len(flowables))
   561 		self._startBuild(filename,canvasmaker)
   573 		self._startBuild(filename,canvasmaker)
   562 
   574 
   563 		while len(flowables):
   575 		while len(flowables):
   564 			self.clean_hanging()
   576 			self.clean_hanging()
   565 			self.handle_flowable(flowables)
   577 			self.handle_flowable(flowables)
       
   578 			if self._onProgress:
       
   579 				self._onProgress('PROGRESS',flowableCount - len(flowables))
   566 
   580 
   567 		self._endBuild()
   581 		self._endBuild()
       
   582 		if self._onProgress:
       
   583 			self._onProgress('FINISHED',0)
   568 
   584 
   569 	def _allSatisfied(self):
   585 	def _allSatisfied(self):
   570 		"""Called by multi-build - are all cross-references resolved?"""
   586 		"""Called by multi-build - are all cross-references resolved?"""
   571 		allHappy = 1
   587 		allHappy = 1
   572 		for f in self._indexingFlowables:
   588 		for f in self._indexingFlowables:
   601 		#print self._indexingFlowables
   617 		#print self._indexingFlowables
   602 		
   618 		
   603 		passes = 0
   619 		passes = 0
   604 		while 1:
   620 		while 1:
   605 			passes = passes + 1
   621 			passes = passes + 1
       
   622 			if self._onProgress:
       
   623 				self.onProgress('PASS', passes)
   606 			if verbose: print 'building pass '+str(passes) + '...',
   624 			if verbose: print 'building pass '+str(passes) + '...',
   607 
   625 
   608 			for fl in self._indexingFlowables:
   626 			for fl in self._indexingFlowables:
   609 				fl.beforeBuild()
   627 				fl.beforeBuild()
   610 
   628