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

Robin Becker reportlab-users@reportlab.com
Fri, 2 Aug 2002 17:48:11 +0100


-----Original message-----
Subject:    [reportlab-team] widgets/markers.py
Newsgroups: !reportlab-team
To:         reportlab-team@www.reportlab.co.uk
From:       Robin Becker <robin@reportlab.com>
Reply-To:   reportlab-team@www.reportlab.co.uk
Date:       Fri, 2 Aug 2002 17:20:27 +0100
Message-ID: <Qv9VMXALFrS9EwNO@jessikat.demon.co.uk>

In article <BB5EFBC9-A62A-11D6-BC03-00039345C610@darwin.in-berlin.de>, Dinu 
Gherman <gherman@darwin.in-berlin.de> writes
>Hi,
>
>just out of curiosity: how is someone supposed to subclass Marker?
>And why does markers.py create an empty (test?) file?
>
>I'm not convinced this is really object-oriented code I'm seeing.
>Certainly it's not about polymorphism (as the only docstring says)
>in the original sense, namely of objects of different classes which
>share the same interface...
>
>But then, yes, maybe my definition of OO is totally different than
>yours! ;-)
>
>Dinu
Well how about the following which subclasses Marker in a few lines.
All the old behaviour is there and you have a new marker. The polymorphic
refers to different shapes from the same class. I realize this may not look
like OO to you Dinu, but it seems to work.

from reportlab.graphics.widgets.markers import *
class DinuMarker(Marker):
        _attrMap=  AttrMap(BASE=Marker,
                        kind = AttrMapValue(OneOf(Marker._attrMap['kind'].valida
te._enum+('DINU',)),
                                desc='marker type name'),
                        )
        def _DINU(self):
                d = self.size/2.0
                return self._doPolygon((-d,3,3,d,d,-3,-3,-d))

if __name__=='__main__':
        from reportlab.lib import colors
        D=Drawing()
        M=DinuMarker()
        M.kind='DINU'           # the new thing
        M.x=30
        M.y=30
        D.add(M)
        M.strokeColor = colors.green
        M=DinuMarker()
        M.kind='Diamond'        # an old thing
        M.x=40
        M.y=30
        M.strokeColor = colors.red
        D.add(M)
        D.save(fnRoot='DinuMarker',formats=['pdf'], outDir='/tmp')
-- 
Robin Becker
_______________________________________________
reportlab-team mailing list
reportlab-team@www.reportlab.co.uk
http://www.reportlab.co.uk/mailman/listinfo/reportlab-team

-----End of original message from Robin Becker-----

-- 
Robin Becker