reportlab/platypus/doctemplate.py
changeset 2449 47b15f941325
parent 2418 9f4ad36c767f
child 2450 f2ae0122a66a
equal deleted inserted replaced
2448:facfc9a8957a 2449:47b15f941325
    68         pass
    68         pass
    69 
    69 
    70     def afterBuild(self):
    70     def afterBuild(self):
    71         """Called after build ends but before isSatisfied"""
    71         """Called after build ends but before isSatisfied"""
    72         pass
    72         pass
    73 
       
    74 
    73 
    75 class ActionFlowable(Flowable):
    74 class ActionFlowable(Flowable):
    76     '''This Flowable is never drawn, it can be used for data driven controls
    75     '''This Flowable is never drawn, it can be used for data driven controls
    77        For example to change a page template (from one column to two, for example)
    76        For example to change a page template (from one column to two, for example)
    78        use NextPageTemplate which creates an ActionFlowable.
    77        use NextPageTemplate which creates an ActionFlowable.
   113         return self
   112         return self
   114 
   113 
   115     def identity(self, maxLen=None):
   114     def identity(self, maxLen=None):
   116         return "ActionFlowable: %s" % str(self.action)
   115         return "ActionFlowable: %s" % str(self.action)
   117 
   116 
       
   117 class LCActionFlowable(ActionFlowable):
       
   118     locChanger = 1                  #we cause a frame or page change
       
   119 
   118 class NextFrameFlowable(ActionFlowable):
   120 class NextFrameFlowable(ActionFlowable):
   119     def __init__(self,ix,resume=0):
   121     def __init__(self,ix,resume=0):
   120         ActionFlowable.__init__(self,('nextFrame',ix,resume))
   122         ActionFlowable.__init__(self,('nextFrame',ix,resume))
   121 
   123 
   122 class CurrentFrameFlowable(ActionFlowable):
   124 class CurrentFrameFlowable(LCActionFlowable):
   123     def __init__(self,ix,resume=0):
   125     def __init__(self,ix,resume=0):
   124         ActionFlowable.__init__(self,('currentFrame',ix,resume))
   126         ActionFlowable.__init__(self,('currentFrame',ix,resume))
   125 
   127 
   126 class _FrameBreak(ActionFlowable):
   128 class _FrameBreak(LCActionFlowable):
   127     '''
   129     '''
   128     A special ActionFlowable that allows setting doc._nextFrameIndex
   130     A special ActionFlowable that allows setting doc._nextFrameIndex
   129 
   131 
   130     eg story.append(FrameBreak('mySpecialFrame'))
   132     eg story.append(FrameBreak('mySpecialFrame'))
   131     '''
   133     '''
   137     def apply(self,doc):
   139     def apply(self,doc):
   138         if getattr(self,'_ix',None): doc._nextFrameIndex = self._ix
   140         if getattr(self,'_ix',None): doc._nextFrameIndex = self._ix
   139         ActionFlowable.apply(self,doc)
   141         ActionFlowable.apply(self,doc)
   140 
   142 
   141 FrameBreak = _FrameBreak('frameEnd')
   143 FrameBreak = _FrameBreak('frameEnd')
   142 PageBegin = ActionFlowable('pageBegin')
   144 PageBegin = LCActionFlowable('pageBegin')
   143 
   145 
   144 def _evalMeasurement(n):
   146 def _evalMeasurement(n):
   145     if type(n) is type(''):
   147     if type(n) is type(''):
   146         from paraparser import _num
   148         from paraparser import _num
   147         n = _num(n)
   149         n = _num(n)
   459             f = self.frame
   461             f = self.frame
   460             self.frame = self.pageTemplate.frames[self.pageTemplate.frames.index(f) + 1]
   462             self.frame = self.pageTemplate.frames[self.pageTemplate.frames.index(f) + 1]
   461             self.handle_frameBegin()
   463             self.handle_frameBegin()
   462 
   464 
   463     def handle_nextPageTemplate(self,pt):
   465     def handle_nextPageTemplate(self,pt):
   464         '''On endPage chenge to the page template with name or index pt'''
   466         '''On endPage change to the page template with name or index pt'''
   465         if type(pt) is StringType:
   467         if type(pt) is StringType:
   466             if hasattr(self, '_nextPageTemplateCycle'): del self._nextPageTemplateCycle
   468             if hasattr(self, '_nextPageTemplateCycle'): del self._nextPageTemplateCycle
   467             for t in self.pageTemplates:
   469             for t in self.pageTemplates:
   468                 if t.id == pt:
   470                 if t.id == pt:
   469                     self._nextPageTemplateIndex = self.pageTemplates.index(t)
   471                     self._nextPageTemplateIndex = self.pageTemplates.index(t)
   492             self._nextPageTemplateIndex = 0  #indexes into the cycle
   494             self._nextPageTemplateIndex = 0  #indexes into the cycle
   493         else:
   495         else:
   494             raise TypeError, "argument pt should be string or integer or list"
   496             raise TypeError, "argument pt should be string or integer or list"
   495 
   497 
   496     def handle_nextFrame(self,fx):
   498     def handle_nextFrame(self,fx):
   497         '''On endFrame chenge to the frame with name or index fx'''
   499         '''On endFrame change to the frame with name or index fx'''
   498         if type(fx) is StringType:
   500         if type(fx) is StringType:
   499             for f in self.pageTemplate.frames:
   501             for f in self.pageTemplate.frames:
   500                 if f.id == fx:
   502                 if f.id == fx:
   501                     self._nextFrameIndex = self.pageTemplate.frames.index(f)
   503                     self._nextFrameIndex = self.pageTemplate.frames.index(f)
   502                     return
   504                     return
   505             self._nextFrameIndex = fx
   507             self._nextFrameIndex = fx
   506         else:
   508         else:
   507             raise TypeError, "argument fx should be string or integer"
   509             raise TypeError, "argument fx should be string or integer"
   508 
   510 
   509     def handle_currentFrame(self,fx):
   511     def handle_currentFrame(self,fx):
   510         '''chenge to the frame with name or index fx'''
   512         '''change to the frame with name or index fx'''
   511         if type(fx) is StringType:
   513         if type(fx) is StringType:
   512             for f in self.pageTemplate.frames:
   514             for f in self.pageTemplate.frames:
   513                 if f.id == fx:
   515                 if f.id == fx:
   514                     self._nextFrameIndex = self.pageTemplate.frames.index(f)
   516                     self._nextFrameIndex = self.pageTemplate.frames.index(f)
   515                     return
   517                     return
   545         if hasattr(first,'style') and hasattr(first.style, 'frameBreakBefore') and first.style.frameBreakBefore == 1:
   547         if hasattr(first,'style') and hasattr(first.style, 'frameBreakBefore') and first.style.frameBreakBefore == 1:
   546             first._skipMeNextTime = 1
   548             first._skipMeNextTime = 1
   547             flowables.insert(0, FrameBreak())
   549             flowables.insert(0, FrameBreak())
   548             return
   550             return
   549 
   551 
   550 
       
   551     def handle_keepWithNext(self, flowables):
   552     def handle_keepWithNext(self, flowables):
   552         "implements keepWithNext"
   553         "implements keepWithNext"
   553         i = 0
   554         i = 0
   554         n = len(flowables)
   555         n = len(flowables)
   555         while i<n and flowables[i].getKeepWithNext(): i = i + 1
   556         while i<n and flowables[i].getKeepWithNext(): i += 1
   556         if i:
   557         if i:
   557             i = i + 1
   558             if not getattr(flowables[i],'locChanger',None): i += 1
   558             K = KeepTogether(flowables[:i])
   559             K = KeepTogether(flowables[:i])
   559             for f in K._flowables:
   560             for f in K._flowables:
   560                 f.keepWithNext = 0
   561                 f.keepWithNext = 0
   561             del flowables[:i]
   562             del flowables[:i]
   562             flowables.insert(0,K)
   563             flowables.insert(0,K)