[reportlab-users] Widgets as Flowables...

Dinu Gherman reportlab-users@reportlab.com
Fri, 27 Sep 2002 14:20:00 +0200

Andy Robinson:

>     myCanvas = Canvas('encapsulation.pdf')
>     myWidget = Rect(0,0,200,100,fillColor=red)
> 1.  myDrawing = Drawing(300,200)
> 2.  myDrawing.add(myWidget)
>     myDrawing.drawOn(myCanvas, 100,500)
>     myCanvas.save()
> Please explain to me why lines (1) and (2) are so much
> trouble, or what the encapsulation stops you from
> doing....

It's not about lines (1) and (2)! ;-) It's about using features
of the PDF canvas in a widget. As there is no canvas available
there, you need to make use of it in the wrapping drawing. This
leads to splitting this functionality over the widget and draw-
ing. E.g. you collect data of active, clickable rectangles in-
side the widget, and reuse them in the drawings's draw method.

I know you'll argue it's supposed to be like that! But in prac-
tice you'll run into trouble when building composite widgets,
for which you then need corresponding composite drawings, and
that means opening a can of worms, namely maintaining dual class

Previously I tried to describe how I hoped to work around this,
but probably there is no point in doing this without extensive
code studies, which I don't think you'll have the time for.

I see there is Group.asDrawing(width, height), so maybe what I'm
looking for is something like Widget.asDrawing(), not sure... it
might be already there!

My understanding of drawings is that I should not use them instead
of widgets, isn't it? Building blocks for domain-specific graphics
libraries are widgets, not drawings, right? And drawings should be
used only within documents.

What then, probably, is misleading is the fact that the code for
all renderers mentions only drawings as the things they are able
to render, where in fact they also can render shapes and widgets.
Alas, they cannot render symbols or flags or markers, although
all of these are subclasses of Widget (they have a size attribute
but no width or height)...

These issues crop-up only when applying the concepts on higher
levels and trying to benefit from the promise of reusability.


Dinu C. Gherman
"The whole point of brainwashing, is that those being brainwashed
don't know it." (Graham Haley)