reportlab/demos/pythonpoint/customshapes.py
author andy_robinson
Thu, 06 Apr 2000 09:47:20 +0000
changeset 75 daedbd33f33e
child 76 dff7aff2fe03
permissions -rw-r--r--
Added several new shape tags. Broke out parser into separate module, to allow for alternative parsers in future. Broke out 'user guide' into pythonpoint.xml
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 $
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    34
#	Revision 1.1  2000/04/06 09:47:20  andy_robinson
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    35
#	Added several new shape tags.
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    36
#	Broke out parser into separate module, to
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    37
#	allow for alternative parsers in future.
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    38
#	Broke out 'user guide' into pythonpoint.xml
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    39
#
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    40
#	Revision 1.6  2000/03/21 19:36:37  rgbecker
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    41
#	8bit character fixes
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    42
#	
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    43
#	Revision 1.5  2000/02/23 15:09:23  rgbecker
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    44
#	Memory leak fixes
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    45
#	
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    46
#	Revision 1.4  2000/02/17 02:06:28  rgbecker
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    47
#	Docstring & other fixes
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    48
#	
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    49
#	Revision 1.3  2000/02/16 09:42:50  rgbecker
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    50
#	Conversion to reportlab package
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    51
#	
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    52
#	Revision 1.2  2000/02/15 17:55:59  rgbecker
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    53
#	License text fixes
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    54
#	
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    55
#	Revision 1.1.1.1  2000/02/15 15:08:55  rgbecker
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    56
#	Initial setup of demos directory and contents.
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    57
#	
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    58
__version__=''' $Id: customshapes.py,v 1.1 2000/04/06 09:47:20 andy_robinson Exp $ '''
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    59
# xml parser stuff for PythonPoint
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    60
# PythonPoint Markup Language!
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    61
__doc__="""
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    62
This demonstrates a custom shape for use with the <customshape> tag.
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    63
The shape must fulfil a very simple interface, which may change in
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    64
future.
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    65
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    66
The XML tag currently has this form:
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    67
        <customshape
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    68
            module="customshapes.py"
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    69
            class = "MyShape"
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    70
            initargs="(100,200,3)"
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    71
        />
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    72
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    73
PythonPoint will look in the given module for the given class,
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    74
evaluate the arguments string and pass it to the constructor.
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    75
Then, it will call
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    76
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    77
    object.drawOn(canvas)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    78
    
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    79
Thus your object must be fully defined by the constructor.
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    80
For this one, we pass three argumenyts: x, y and scale.
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    81
This does a five-tile jigsaw over which words can be overlaid; based
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    82
on work done for a customer's presentation.
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    83
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    84
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    85
"""
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    86
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    87
import reportlab.pdfgen.canvas
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    88
from reportlab.lib import colors
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    89
## custom shape for use with PythonPoint.
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    90
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    91
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    92
class Jigsaw:
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    93
    """This draws a jigsaw patterm.  By default it is centred on 0,0
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    94
    and has dimensions of 200 x 140; use the x/y/scale attributes
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    95
    to move it around."""
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    96
    #Using my usual bulldozer coding style - I am sure a mathematician could
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    97
    #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
    98
    #the control points, and reflected a few lists at the interactive prompt.
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    99
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   100
    def __init__(self, x, y, scale=1):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   101
        self.width = 200
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   102
        self.height = 140
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   103
        self.x = x
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   104
        self.y = y
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   105
        self.scale = scale
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   106
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   107
    def drawOn(self, canvas):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   108
        canvas.saveState()
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   109
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   110
        canvas.setFont('Helvetica-Bold',24)        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   111
        canvas.drawString(100,700,'A Custom Shape')
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   112
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   113
        canvas.translate(self.x, self.y)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   114
        canvas.scale(self.scale, self.scale)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   115
        self.drawBounds(canvas)        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   116
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   117
        self.drawCentre(canvas)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   118
        self.drawTopLeft(canvas)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   119
        self.drawBottomLeft(canvas)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   120
        self.drawBottomRight(canvas)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   121
        self.drawTopRight(canvas)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   122
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   123
        canvas.restoreState()
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   124
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   125
    def curveThrough(self, path, pointlist):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   126
        """Helper to curve through set of control points."""
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   127
        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
   128
        (x,y) = pointlist[0]
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   129
        path.moveTo(x, y)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   130
        idx = 1
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   131
        while idx < len(pointlist)-2:
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   132
            p1, p2, p3 = pointlist[idx:idx+3]
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   133
            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
   134
            idx = idx + 3
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   135
            
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   136
    def drawShape(self, canvas, controls, color):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   137
        """Utlity to draw a closed shape through a list of control points;
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   138
        extends the previous proc"""
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   139
        canvas.setFillColor(color)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   140
        p = canvas.beginPath()
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   141
        self.curveThrough(p, controls)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   142
        p.close()
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   143
        canvas.drawPath(p, stroke=1, fill=1)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   144
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   145
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   146
    def drawBounds(self, canvas):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   147
        """Guidelines to help me draw - not needed in production"""
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   148
        canvas.setStrokeColor(colors.red)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   149
        canvas.rect(-100,-70,200,140)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   150
        canvas.line(-100,0,100,0)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   151
        canvas.line(0,70,0,-70)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   152
        canvas.setStrokeColor(colors.black)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   153
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   154
    
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   155
    def drawCentre(self, canvas):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   156
        controls = [ (0,50),   #top
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   157
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   158
                #top right edge - duplicated for that corner piece                     
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
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   166
                #bottom right edge
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   167
                (50, -5), (45,-10), (40,-10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   168
                (35,-10), (30,-15), (30, -20),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   169
                (30,-25), (25,-30), (20,-30),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   170
                (15,-30), (10,-35), (10,-40),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   171
                (10,-45),(5,-50),(0,-50),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   172
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   173
                #bottom left                     
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   174
                (-5,-50),(-10,-45),(-10,-40),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   175
                (-10,-35),(-15,-30),(-20,-30),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   176
                (-25,-30),(-30,-25),(-30,-20),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   177
                (-30,-15),(-35,-10),(-40,-10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   178
                (-45,-10),(-50,-5),(-50,0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   179
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   180
                #top left
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   181
                (-50,5),(-45,10),(-40,10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   182
                (-35,10),(-30,15),(-30,20),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   183
                (-30,25),(-25,30),(-20,30),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   184
                (-15,30),(-10,35),(-10,40),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   185
                (-10,45),(-5,50),(0,50)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   186
                     
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   187
                ]            
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   188
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   189
        self.drawShape(canvas, controls, colors.yellow)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   190
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   191
    def drawTopLeft(self, canvas):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   192
        controls = [(-100,70),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   193
            (-100,69),(-100,1),(-100,0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   194
            (-99,0),(-91,0),(-90,0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   195
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   196
            #jigsaw interlock - 4 sections
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   197
            (-90,5),(-92,5),(-92,10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   198
            (-92,15), (-85,15), (-80,15),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   199
            (-75,15),(-68,15),(-68,10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   200
            (-68,5),(-70,5),(-70,0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   201
            (-69,0),(-51,0),(-50,0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   202
            
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   203
            #five distinct curves
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   204
            (-50,5),(-45,10),(-40,10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   205
            (-35,10),(-30,15),(-30,20),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   206
            (-30,25),(-25,30),(-20,30),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   207
            (-15,30),(-10,35),(-10,40),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   208
            (-10,45),(-5,50),(0,50),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   209
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   210
            (0,51),(0,69),(0,70),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   211
            (-1,70),(-99,70),(-100,70)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   212
            ]
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   213
        self.drawShape(canvas, controls, colors.teal)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   214
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   215
    def drawBottomLeft(self, canvas):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   216
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   217
        controls = [(-100,-70),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   218
            (-99,-70),(-1,-70),(0,-70),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   219
            (0,-69),(0,-51),(0,-50),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   220
            
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   221
            #wavyline
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   222
            (-5,-50),(-10,-45),(-10,-40),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   223
            (-10,-35),(-15,-30),(-20,-30),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   224
            (-25,-30),(-30,-25),(-30,-20),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   225
            (-30,-15),(-35,-10),(-40,-10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   226
            (-45,-10),(-50,-5),(-50,0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   227
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   228
            #jigsaw interlock - 4 sections
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   229
                    
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   230
            (-51, 0), (-69, 0), (-70, 0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   231
            (-70, 5), (-68, 5), (-68, 10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   232
            (-68, 15), (-75, 15), (-80, 15),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   233
            (-85, 15), (-92, 15), (-92, 10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   234
            (-92, 5), (-90, 5), (-90, 0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   235
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   236
            (-91,0),(-99,0),(-100,0)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   237
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   238
            ]
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   239
        self.drawShape(canvas, controls, colors.green)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   240
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   241
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   242
    def drawBottomRight(self, canvas):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   243
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   244
        controls = [ (100,-70),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   245
            (100,-69),(100,-1),(100,0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   246
            (99,0),(91,0),(90,0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   247
            
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   248
            #jigsaw interlock - 4 sections
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   249
            (90, -5), (92, -5), (92, -10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   250
            (92, -15), (85, -15), (80, -15),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   251
            (75, -15), (68, -15), (68, -10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   252
            (68, -5), (70, -5), (70, 0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   253
            (69, 0), (51, 0), (50, 0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   254
                    
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   255
            #wavyline
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   256
            (50, -5), (45,-10), (40,-10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   257
            (35,-10), (30,-15), (30, -20),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   258
            (30,-25), (25,-30), (20,-30),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   259
            (15,-30), (10,-35), (10,-40),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   260
            (10,-45),(5,-50),(0,-50),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   261
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   262
            (0,-51), (0,-69), (0,-70),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   263
            (1,-70),(99,-70),(100,-70)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   264
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   265
            ]
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   266
        self.drawShape(canvas, controls, colors.navy)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   267
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   268
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   269
    def drawBottomLeft(self, canvas):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   270
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   271
        controls = [(-100,-70),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   272
            (-99,-70),(-1,-70),(0,-70),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   273
            (0,-69),(0,-51),(0,-50),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   274
            
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   275
            #wavyline
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   276
            (-5,-50),(-10,-45),(-10,-40),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   277
            (-10,-35),(-15,-30),(-20,-30),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   278
            (-25,-30),(-30,-25),(-30,-20),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   279
            (-30,-15),(-35,-10),(-40,-10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   280
            (-45,-10),(-50,-5),(-50,0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   281
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   282
            #jigsaw interlock - 4 sections
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   283
                    
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   284
            (-51, 0), (-69, 0), (-70, 0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   285
            (-70, 5), (-68, 5), (-68, 10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   286
            (-68, 15), (-75, 15), (-80, 15),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   287
            (-85, 15), (-92, 15), (-92, 10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   288
            (-92, 5), (-90, 5), (-90, 0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   289
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   290
            (-91,0),(-99,0),(-100,0)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   291
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   292
            ]
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   293
        self.drawShape(canvas, controls, colors.green)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   294
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   295
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   296
    def drawTopRight(self, canvas):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   297
        controls = [(100, 70),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   298
            (99, 70), (1, 70), (0, 70),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   299
            (0, 69), (0, 51), (0, 50),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   300
            (5, 50), (10, 45), (10, 40),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   301
            (10, 35), (15, 30), (20, 30),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   302
            (25, 30), (30, 25), (30, 20),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   303
            (30, 15), (35, 10), (40, 10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   304
            (45, 10), (50, 5), (50, 0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   305
            (51, 0), (69, 0), (70, 0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   306
            (70, -5), (68, -5), (68, -10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   307
            (68, -15), (75, -15), (80, -15),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   308
            (85, -15), (92, -15), (92, -10),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   309
            (92, -5), (90, -5), (90, 0),
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   310
            (91, 0), (99, 0), (100, 0)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   311
                    ]
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   312
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   313
        self.drawShape(canvas, controls, colors.magenta)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   314
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   315
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   316
def run():
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   317
    c = reportlab.pdfgen.canvas.Canvas('customshape.pdf')
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   318
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   319
    J = Jigsaw(300, 540, 2)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   320
    J.drawOn(c)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   321
    c.save()
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   322
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   323
if __name__ == '__main__':
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   324
    run()
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   325