[reportlab-users] Can a pagetemplate modify its frames?
    Robin Becker 
    robin at reportlab.com
       
    Thu Aug 28 11:36:59 EDT 2008
    
    
  
Roberto Alsina wrote:
> On Thursday 28 August 2008 11:54:58 Roberto Alsina wrote:
>> I am trying to implement a "smart page" PageTemplate which does things like
>> adjust margins and show/hide headers and footers depending on the content.
>>
>> Can I modify self.frames from a PageTemplate?
>>
>> I tried this to implement a "gutter margin" with no visible effect:
>>
>>     def beforePage(self,canv,doc):
> 
> Make that beforeDrawPage (BTW, the manual is wrong here ;-)
> 
>>         print self.frames[0].__dict__
>>
>>         # Adjust gutter margins
>>         if doc.page%2: #Odd page
>>             gm=self.gm
>>         else: # Even page
>>             gm=-self.gm
>>
>>         print gm
>>
>>         for f in self.frames:
>>             f._x+=gm
>>             f._x1+=gm
>>             f._x2+=gm
>>
>> The values change but the frame doesn't move :-)
> 
you're messing with bad stuff here. These classes were created before python had 
properties etc etc so I think you'll need either to overwrite the frame with a 
new instance or to adjust the external properties x1, y1 etc etc and force the 
geometry to recalculate. If you do
f.a=z where a is one of ('x1', 'y1', 'width', 'height', 'leftPadding', 
'bottomPadding', 'rightPadding', 'topPadding') then the underlying _a variable 
is actually set and the frame recalculates its geometry.
According to Andy the right way to do this sort of odd/even page stuff is to use 
  a pagetemplate cycle basically need to use
NextPageTemplate(['left','right'])
PageBreak()
in the story and then we iterate left & right templates.
-- 
Robin Becker
    
    
More information about the reportlab-users
mailing list