[reportlab-users] get methods for properties
Tim Roberts
reportlab-users@reportlab.com
Fri, 11 Jun 2004 10:22:30 -0700
On Thu, 10 Jun 2004 13:07:15 -0500, Randall Smith <randall@tnr.cc> wrote:
>My comment is about getting properties. Maybe I missed it, but I don't
>see a clean way to grab some useful properties. For example, line
>width. I wrote a flowable to draw a horizontal line. I want to set the
>line width and return it back to what it was before the flowable was
>created. Because _lineWidth starts with a _, I'm guessing this is a
>semi-private variable and subject to change (not part of the API). So
>shouldn't canvas have an API attribute or call like canvas.lineWidth or
>canvas.getLineWidth()?
>
>Here is code below:
>
>class HR(Flowable):
>...
> def draw(self):
> orig_linewidth = self.canv._lineWidth # my problem is here
> self.canv.setLineWidth(height)
> self.canv.line(0, 0, 100, 0)
> self.canv.setLineWidth(orig_linewidth)
>
>
The correct (and easy) way to do this is:
def draw(self):
self.canv.saveState()
self.canv.setLineWidth(height)
self.canv.setLotsOfOtherProperties()
self.canv.line(0, 0, 100, 0)
self.canv.restoreState()
--
- Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.