[reportlab-users] get methods for properties

Randall Smith reportlab-users@reportlab.com
Thu, 10 Jun 2004 13:07:15 -0500


I'm new to reportlab.  I've been playing with it and looking at the 
source.  I like the design, especially the templates.  Thank you for 
opening it to the public; I hope you get useful feedback.

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 __init__(self, height):
         Flowable.__init__(self)
         self.height = height
 

     def __repr__(self):
         return "HR(t=%s)" % (self.height,)
 

     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)

Randall