[reportlab-users] Re: [reportlab-team] widgets/markers.py

Robin Becker reportlab-users@reportlab.com
Tue, 6 Aug 2002 00:45:48 +0100


In article <58F809E8-A862-11D6-941D-00039345C610@darwin.in-berlin.de>, Dinu Gherman
<gherman@darwin.in-berlin.de> writes
>Robin Becker:
>
.....
>Actually, the more I think about it the more rotten all this seems
>to appear to me from an OO point of view. After all, a marker is
>nothing else, but a widget (in the charting domain), adding not
>much more, but a tiny shell of functionality to place, (and dis-
>place), size and possibly rotate the wrapped widget.
>
Dinu markers are a special restricted widget with particular attributes
that clients can set. As an example a red lineplot needs to know it
can set particular things on the result.

At present we're using code like this to convert the 'marker' instance to
something that can be added to the plot. 

def uSymbol2Symbol(uSymbol,x,y,color):
        if type(uSymbol) == FunctionType:
                symbol = uSymbol(x, y, 5, color)
        elif type(uSymbol) == ClassType and issubclass(uSymbol,Widget):
                size = 10.
                symbol = uSymbol()
                symbol.x = x - (size/2)
                symbol.y = y - (size/2)
                try:
                        symbol.size = size
                        symbol.color = color
                except:
                        pass
        elif isinstance(uSymbol,Marker) or isinstance(uSymbol,Flag):
                symbol = uSymbol.clone()
                if isinstance(uSymbol,Marker): symbol.fillColor = symbol.fillColor or color
                symbol.x, symbol.y = x, y
        else:
                symbol = None
        return symbol

so when we use that you can already use an arbitrary widget or function
or one of the marker things.
>That means, what we speak about when saying "markers" is a mere
>wrapper on widgets! Therefore, it would all make much more sense,
>neither to fiddle with more and more *methods* of one Marker class
>(as you did for regular Polygons), nor to make, maybe many, sub-
>classes (as I was suggesting), but to create the equivalent widgets,
>so they become reusable in other contexts, too, i.e. outside the
>charting domain...
>
>Then markers can just become the true wrappers they really are!
>If you haven't heard it already, I'm ringing the Decorator bell,
>for those familiar with the pattern lingo...
>
>Dinu
....
there's nothing to stop you using arbitrary derived classes of 
Marker that use x, y, fillColor as above.
-- 
Robin Becker