[reportlab-users] Can a pagetemplate modify its frames?

Roberto Alsina ralsina at netmanagers.com.ar
Thu Aug 28 11:42:18 EDT 2008


On Thursday 28 August 2008 12:36:59 Robin Becker wrote:

> 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


That's more than good enough if it works.


> 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.


Yes, but I have problems here exposing that kind of thing to the user.
The user already is going to have to switch for example, from "cover" to
"contents" to "normal" templates.

If he's going to have to switch from cover to contents-left, to normal-right,
to normal-left, and so on, it's going to become annoying (not to mention that
all page breaks would have to be manual).

So, that doesn't really fit my idea of how the app will work. OTOH, recreating
the frams? I have no problem with that ;-)

--
("\''/").__..-''"`-. . Roberto Alsina
`9_ 9 ) `-. ( ).`-._.`) KDE Developer (MFCH)
(_Y_.)' ._ ) `._`. " -.-' http://lateral.netmanagers.com.ar
_..`-'_..-_/ /-'_.' The 6,855th most popular site of Slovenia
(l)-'' ((i).' ((!.' according to alexa.com (27/5/2007)

Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it. --Brian W. Kernighan


More information about the reportlab-users mailing list