reportlab/demos/pythonpoint/customshapes.py
author andy_robinson
Thu, 06 Apr 2000 09:48:42 +0000
changeset 76 dff7aff2fe03
parent 75 daedbd33f33e
child 494 54257447cfe9
permissions -rw-r--r--
Removed some stray comments
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
     1
###############################################################################
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
     2
#
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
     3
#	ReportLab Public License Version 1.0
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
     4
#
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
     5
#   Except for the change of names the spirit and intention of this
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
     6
#   license is the same as that of Python
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
     7
#
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
     8
#	(C) Copyright ReportLab Inc. 1998-2000.
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
     9
#
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    10
#
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    11
# All Rights Reserved
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    12
#
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    13
# Permission to use, copy, modify, and distribute this software and its
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    14
# documentation for any purpose and without fee is hereby granted, provided
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    15
# that the above copyright notice appear in all copies and that both that
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    16
# copyright notice and this permission notice appear in supporting
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    17
# documentation, and that the name of ReportLab not be used
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    18
# in advertising or publicity pertaining to distribution of the software
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    19
# without specific, written prior permission. 
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    20
# 
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    21
#
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    22
# Disclaimer
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    23
#
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    24
# ReportLab Inc. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    25
# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    26
# IN NO EVENT SHALL ReportLab BE LIABLE FOR ANY SPECIAL, INDIRECT
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    27
# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    28
# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    29
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    30
# PERFORMANCE OF THIS SOFTWARE. 
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    31
#
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    32
###############################################################################
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    33
#	$Log: customshapes.py,v $
76
dff7aff2fe03 Removed some stray comments
andy_robinson
parents: 75
diff changeset
    34
#	Revision 1.2  2000/04/06 09:48:42  andy_robinson
dff7aff2fe03 Removed some stray comments
andy_robinson
parents: 75
diff changeset
    35
#	Removed some stray comments
dff7aff2fe03 Removed some stray comments
andy_robinson
parents: 75
diff changeset
    36
#
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    37
#	Revision 1.1  2000/04/06 09:47:20  andy_robinson
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    38
#	Added several new shape tags.
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    39
#	Broke out parser into separate module, to
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    40
#	allow for alternative parsers in future.
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    41
#	Broke out 'user guide' into pythonpoint.xml
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    42
#	
76
dff7aff2fe03 Removed some stray comments
andy_robinson
parents: 75
diff changeset
    43
__version__=''' $Id: customshapes.py,v 1.2 2000/04/06 09:48:42 andy_robinson Exp $ '''
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    44
# xml parser stuff for PythonPoint
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    45
# PythonPoint Markup Language!
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    46
__doc__="""
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    47
This demonstrates a custom shape for use with the <customshape> tag.
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    48
The shape must fulfil a very simple interface, which may change in
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    49
future.
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    50
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    51
The XML tag currently has this form:
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    52
        <customshape
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    53
            module="customshapes.py"
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    54
            class = "MyShape"
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    55
            initargs="(100,200,3)"
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    56
        />
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    57
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    58
PythonPoint will look in the given module for the given class,
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    59
evaluate the arguments string and pass it to the constructor.
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    60
Then, it will call
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    61
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    62
    object.drawOn(canvas)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    63
    
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    64
Thus your object must be fully defined by the constructor.
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    65
For this one, we pass three argumenyts: x, y and scale.
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    66
This does a five-tile jigsaw over which words can be overlaid; based
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    67
on work done for a customer's presentation.
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    68
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    69
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    70
"""
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    71
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    72
import reportlab.pdfgen.canvas
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    73
from reportlab.lib import colors
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    74
## custom shape for use with PythonPoint.
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    75
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    76
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    77
class Jigsaw:
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    78
    """This draws a jigsaw patterm.  By default it is centred on 0,0
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    79
    and has dimensions of 200 x 140; use the x/y/scale attributes
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    80
    to move it around."""
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    81
    #Using my usual bulldozer coding style - I am sure a mathematician could
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    82
    #derive an elegant way to draw this, but I just took a ruler, guessed at
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    83
    #the control points, and reflected a few lists at the interactive prompt.
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    84
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    85
    def __init__(self, x, y, scale=1):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    86
        self.width = 200
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    87
        self.height = 140
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    88
        self.x = x
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    89
        self.y = y
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    90
        self.scale = scale
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    91
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    92
    def drawOn(self, canvas):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    93
        canvas.saveState()
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    94
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    95
        canvas.setFont('Helvetica-Bold',24)        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    96
        canvas.drawString(100,700,'A Custom Shape')
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    97
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    98
        canvas.translate(self.x, self.y)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    99
        canvas.scale(self.scale, self.scale)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   100
        self.drawBounds(canvas)        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   101
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   102
        self.drawCentre(canvas)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   103
        self.drawTopLeft(canvas)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   104
        self.drawBottomLeft(canvas)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   105
        self.drawBottomRight(canvas)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   106
        self.drawTopRight(canvas)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   107
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   108
        canvas.restoreState()
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   109
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   110
    def curveThrough(self, path, pointlist):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   111
        """Helper to curve through set of control points."""
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   112
        assert len(pointlist) % 3 == 1, "No. of points must be 3n+1 for integer n"
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   113
        (x,y) = pointlist[0]
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   114
        path.moveTo(x, y)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   115
        idx = 1
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   116
        while idx < len(pointlist)-2:
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   117
            p1, p2, p3 = pointlist[idx:idx+3]
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   118
            path.curveTo(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1])
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   119
            idx = idx + 3
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   120
            
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   121
    def drawShape(self, canvas, controls, color):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   122
        """Utlity to draw a closed shape through a list of control points;
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   123
        extends the previous proc"""
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   124
        canvas.setFillColor(color)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   125
        p = canvas.beginPath()
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   126
        self.curveThrough(p, controls)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   127
        p.close()
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   128
        canvas.drawPath(p, stroke=1, fill=1)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   129
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   130
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   131
    def drawBounds(self, canvas):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   132
        """Guidelines to help me draw - not needed in production"""
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   133
        canvas.setStrokeColor(colors.red)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   134
        canvas.rect(-100,-70,200,140)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   135
        canvas.line(-100,0,100,0)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   136
        canvas.line(0,70,0,-70)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   137
        canvas.setStrokeColor(colors.black)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   138
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   139
    
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   140
    def drawCentre(self, canvas):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   141
        controls = [ (0,50),   #top
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   142
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   143
                #top right edge - duplicated for that corner piece                     
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   144
                (5,50),(10,45),(10,40),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   145
                (10,35),(15,30),(20,30),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   146
                (25,30),(30,25),(30,20),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   147
                (30,15),(35,10),(40,10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   148
                (45,10),(50,5),(50,0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   149
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   150
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   151
                #bottom right edge
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   152
                (50, -5), (45,-10), (40,-10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   153
                (35,-10), (30,-15), (30, -20),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   154
                (30,-25), (25,-30), (20,-30),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   155
                (15,-30), (10,-35), (10,-40),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   156
                (10,-45),(5,-50),(0,-50),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   157
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   158
                #bottom left                     
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   159
                (-5,-50),(-10,-45),(-10,-40),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   160
                (-10,-35),(-15,-30),(-20,-30),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   161
                (-25,-30),(-30,-25),(-30,-20),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   162
                (-30,-15),(-35,-10),(-40,-10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   163
                (-45,-10),(-50,-5),(-50,0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   164
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   165
                #top left
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   166
                (-50,5),(-45,10),(-40,10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   167
                (-35,10),(-30,15),(-30,20),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   168
                (-30,25),(-25,30),(-20,30),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   169
                (-15,30),(-10,35),(-10,40),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   170
                (-10,45),(-5,50),(0,50)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   171
                     
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   172
                ]            
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   173
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   174
        self.drawShape(canvas, controls, colors.yellow)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   175
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   176
    def drawTopLeft(self, canvas):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   177
        controls = [(-100,70),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   178
            (-100,69),(-100,1),(-100,0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   179
            (-99,0),(-91,0),(-90,0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   180
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   181
            #jigsaw interlock - 4 sections
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   182
            (-90,5),(-92,5),(-92,10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   183
            (-92,15), (-85,15), (-80,15),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   184
            (-75,15),(-68,15),(-68,10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   185
            (-68,5),(-70,5),(-70,0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   186
            (-69,0),(-51,0),(-50,0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   187
            
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   188
            #five distinct curves
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   189
            (-50,5),(-45,10),(-40,10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   190
            (-35,10),(-30,15),(-30,20),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   191
            (-30,25),(-25,30),(-20,30),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   192
            (-15,30),(-10,35),(-10,40),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   193
            (-10,45),(-5,50),(0,50),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   194
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   195
            (0,51),(0,69),(0,70),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   196
            (-1,70),(-99,70),(-100,70)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   197
            ]
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   198
        self.drawShape(canvas, controls, colors.teal)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   199
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   200
    def drawBottomLeft(self, canvas):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   201
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   202
        controls = [(-100,-70),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   203
            (-99,-70),(-1,-70),(0,-70),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   204
            (0,-69),(0,-51),(0,-50),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   205
            
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   206
            #wavyline
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   207
            (-5,-50),(-10,-45),(-10,-40),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   208
            (-10,-35),(-15,-30),(-20,-30),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   209
            (-25,-30),(-30,-25),(-30,-20),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   210
            (-30,-15),(-35,-10),(-40,-10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   211
            (-45,-10),(-50,-5),(-50,0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   212
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   213
            #jigsaw interlock - 4 sections
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   214
                    
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   215
            (-51, 0), (-69, 0), (-70, 0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   216
            (-70, 5), (-68, 5), (-68, 10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   217
            (-68, 15), (-75, 15), (-80, 15),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   218
            (-85, 15), (-92, 15), (-92, 10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   219
            (-92, 5), (-90, 5), (-90, 0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   220
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   221
            (-91,0),(-99,0),(-100,0)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   222
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   223
            ]
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   224
        self.drawShape(canvas, controls, colors.green)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   225
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   226
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   227
    def drawBottomRight(self, canvas):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   228
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   229
        controls = [ (100,-70),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   230
            (100,-69),(100,-1),(100,0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   231
            (99,0),(91,0),(90,0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   232
            
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   233
            #jigsaw interlock - 4 sections
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   234
            (90, -5), (92, -5), (92, -10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   235
            (92, -15), (85, -15), (80, -15),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   236
            (75, -15), (68, -15), (68, -10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   237
            (68, -5), (70, -5), (70, 0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   238
            (69, 0), (51, 0), (50, 0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   239
                    
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   240
            #wavyline
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   241
            (50, -5), (45,-10), (40,-10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   242
            (35,-10), (30,-15), (30, -20),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   243
            (30,-25), (25,-30), (20,-30),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   244
            (15,-30), (10,-35), (10,-40),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   245
            (10,-45),(5,-50),(0,-50),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   246
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   247
            (0,-51), (0,-69), (0,-70),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   248
            (1,-70),(99,-70),(100,-70)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   249
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   250
            ]
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   251
        self.drawShape(canvas, controls, colors.navy)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   252
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   253
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   254
    def drawBottomLeft(self, canvas):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   255
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   256
        controls = [(-100,-70),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   257
            (-99,-70),(-1,-70),(0,-70),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   258
            (0,-69),(0,-51),(0,-50),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   259
            
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   260
            #wavyline
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   261
            (-5,-50),(-10,-45),(-10,-40),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   262
            (-10,-35),(-15,-30),(-20,-30),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   263
            (-25,-30),(-30,-25),(-30,-20),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   264
            (-30,-15),(-35,-10),(-40,-10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   265
            (-45,-10),(-50,-5),(-50,0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   266
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   267
            #jigsaw interlock - 4 sections
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   268
                    
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   269
            (-51, 0), (-69, 0), (-70, 0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   270
            (-70, 5), (-68, 5), (-68, 10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   271
            (-68, 15), (-75, 15), (-80, 15),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   272
            (-85, 15), (-92, 15), (-92, 10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   273
            (-92, 5), (-90, 5), (-90, 0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   274
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   275
            (-91,0),(-99,0),(-100,0)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   276
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   277
            ]
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   278
        self.drawShape(canvas, controls, colors.green)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   279
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   280
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   281
    def drawTopRight(self, canvas):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   282
        controls = [(100, 70),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   283
            (99, 70), (1, 70), (0, 70),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   284
            (0, 69), (0, 51), (0, 50),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   285
            (5, 50), (10, 45), (10, 40),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   286
            (10, 35), (15, 30), (20, 30),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   287
            (25, 30), (30, 25), (30, 20),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   288
            (30, 15), (35, 10), (40, 10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   289
            (45, 10), (50, 5), (50, 0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   290
            (51, 0), (69, 0), (70, 0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   291
            (70, -5), (68, -5), (68, -10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   292
            (68, -15), (75, -15), (80, -15),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   293
            (85, -15), (92, -15), (92, -10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   294
            (92, -5), (90, -5), (90, 0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   295
            (91, 0), (99, 0), (100, 0)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   296
                    ]
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   297
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   298
        self.drawShape(canvas, controls, colors.magenta)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   299
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   300
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   301
def run():
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   302
    c = reportlab.pdfgen.canvas.Canvas('customshape.pdf')
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   303
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   304
    J = Jigsaw(300, 540, 2)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   305
    J.drawOn(c)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   306
    c.save()
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   307
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   308
if __name__ == '__main__':
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   309
    run()
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   310