[reportlab-users] Tried reportlab on python 3.4... failed

Andy Robinson andy at reportlab.com
Sat Oct 25 22:16:38 EDT 2014


Hi Glenn,

As far as we know the code behaves identically in Pythons 2.7, 3.3 and
3.4; certainly the user guide generates and all the tests run.

It looks like we managed to document a very, very old pattern in the
user guide and to give a completely misleading explanation of how to
set up the styles, and somehow it has survived about 13-14 years.  My
apologies for this.   We're warming up for a release in November and
need to make a pass through the whole user guide.

If we were redoing things now we would use a metaclass-like pattern
similar to Django's models or forms, but that didn't exist in Python
1.4 or whatever we were on at the time; reportlab/lib/styles has our
own handrolled version of this, designed for speed rather than
elegance.  I'm not sure why we showed an example like this.

The intended use is for you to do this:

    mystyle = ParagraphStyle(key1=value1, key2=value2, etc...)

...and just keep a style instance around.  I don't think you would
want to create your own subclass for anything I can think of.   We
support inheritance by allowing a parent attribute e.g.

   styBase = ParagraphStyle(fontName="myfont", fontSize=10)
   styBold = ParagraphStyle(parent=styBase, fontName="myBoldFont")

..

That way, all paragraph styles will be initialised with every
attribute currently supported.

- Andy

On 25 October 2014 08:01, Glenn Linderman <v+python at g.nevcal.com> wrote:
> Since reportlab was one of a very few reasons I have python 2.7 installed, I
> have watched with anticipation the development of reportlab for python 3.
> Today I decided to try it, because I tried to operate on a file with a
> non-ASCII character in it, and python 2.7 doesn't like those, so rather than
> rename the file, I installed reportlab in Python 3.4.1 via pip. The install
> seemed to go fine.
>
> I tweaked the launching of my PDF generator to launch it via Python 3.4.1
> instead of python 2.7. Since it has been a while since I looked at that
> code, I figured I would get a bunch of Python 2->3 sort of errors, but...
> not yet...
>
> Instead, on the call to mkdoc(), I got a traceback, from mkdoc() down here
> it is:
>
>  in mkdoc:
>     doc.build( elements, onFirstPage=mkpage )
>   File "c:\python34\lib\site-packages\reportlab\platypus\doctemplate.py",
> line 1127, in build
>      BaseDocTemplate.build(self,flowables, canvasmaker=canvasmaker)
>   File "c:\python34\lib\site-packages\reportlab\platypus\doctemplate.py",
> line 8 90, in build
>     self.handle_flowable(flowables)
>   File "c:\python34\lib\site-packages\reportlab\platypus\doctemplate.py",
> line 773, in handle_flowable
>     if frame.add(f, canv, trySplit=self.allowSplitting):
>   File "c:\python34\lib\site-packages\reportlab\platypus\frames.py", line
> 161, in _add
>     w, h = flowable.wrap(aW, h)
>   File "c:\python34\lib\site-packages\reportlab\platypus\paragraph.py", line
> 1035, in wrap
>     blPara = self.breakLines([first_line_width, later_widths])
>   File "c:\python34\lib\site-packages\reportlab\platypus\paragraph.py", line
> 1203, in breakLines
>     splitLongWords = style.splitLongWords
> AttributeError: 'MyParaSt' object has no attribute 'splitLongWords'
>
>
> The definition for MyParaSt is as follows... works fine in reportlab 2.5 on
> python 2.7....
>
> class MyParaSt(PropertySet):
>     defaults = {
>         'fontName': 'Times-New-Roman',
>         'fontSize': defsize,
>         'leading': deflead,
>         'leftIndent': 0,
>         'rightIndent': 0,
>         'firstLineIndent': 0,
>         'alignment': TA_LEFT,
>         'spaceBefore': 0,
>         'spaceAfter': 0,
>         'bulletFontName': 'Times-New-Roman',
>         'bulletFontSize': 10,
>         'bulletIndent': 0,
>         'textColor': black,
>         'backColor': None,
>         'wordWrap': None,
>         'borderWidth': 0,
>         'borderPadding': 0,
>         'borderColor': None,
>         'borderRadius': None,
>         'allowWidows': 1,
>         'allowOrphans': 0,
>         'textTransform': None,
>             #uppercase lowercase (captitalize not yet) or None or absent
>         }
>
> I'm not exactly sure why I have a MyParaSt, since it has been a long time
> since I wrote this, but I would guess it might have been to set the default
> font(s)?  Maybe there would have been a better way, like only changing the
> items I wanted to change, rather than creating my whole new own defaults
> hash? I probably cut-n-pasted this idea from somewhere, though, and maybe it
> wasn't the best idea?
>
> Where should I start reading? I did do a search and it seems splitLongWords
> is relatively new...
>
> _______________________________________________
> reportlab-users mailing list
> reportlab-users at lists2.reportlab.com
> https://pairlist2.pair.net/mailman/listinfo/reportlab-users
>



-- 
Andy Robinson
Managing Director
ReportLab Europe Ltd.
Thornton House, Thornton Road, Wimbledon, London SW19 4NG, UK
Tel +44-20-8405-6420


More information about the reportlab-users mailing list