src/reportlab/graphics/testdrawings.py
author robin
Wed, 17 Feb 2016 12:25:38 +0000
changeset 4252 fe660f227cac
parent 3721 0c93dd8ff567
child 4330 617ffa6bbdc8
permissions -rw-r--r--
changes for release 3.3.0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
     1
#!/bin/env python
4252
fe660f227cac changes for release 3.3.0
robin
parents: 3721
diff changeset
     2
#Copyright ReportLab Europe Ltd. 2000-2016
817
8c3a399effda License text changes
rgbecker
parents: 568
diff changeset
     3
#see license.txt for license details
2332
2a7ab4405e18 Remove $Header:, fix CopyRight & history
rgbecker
parents: 1683
diff changeset
     4
#history http://www.reportlab.co.uk/cgi-bin/viewcvs.cgi/public/reportlab/trunk/reportlab/graphics/testdrawings.py
4252
fe660f227cac changes for release 3.3.0
robin
parents: 3721
diff changeset
     5
__version__='3.3.0'
3032
22224b1b4d24 New docstrings mainly for module titles
damian
parents: 2964
diff changeset
     6
__doc__="""Defines some standard drawings to use as test cases
22224b1b4d24 New docstrings mainly for module titles
damian
parents: 2964
diff changeset
     7
22224b1b4d24 New docstrings mainly for module titles
damian
parents: 2964
diff changeset
     8
This contains a number of routines to generate test drawings
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
     9
for reportlab/graphics.  For now they are contrived, but we will expand them
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    10
to try and trip up any parser. Feel free to add more.
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    11
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    12
"""
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    13
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    14
from reportlab.graphics.shapes import *
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    15
from reportlab.lib import colors
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    16
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    17
def getDrawing1():
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    18
    """Hello World, on a rectangular background"""
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 817
diff changeset
    19
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    20
    D = Drawing(400, 200)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 817
diff changeset
    21
    D.add(Rect(50, 50, 300, 100, fillColor=colors.yellow))  #round corners
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    22
    D.add(String(180,100, 'Hello World', fillColor=colors.red))
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    23
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 817
diff changeset
    24
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    25
    return D
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    26
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    27
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    28
def getDrawing2():
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    29
    """This demonstrates the basic shapes.  There are
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    30
    no groups or references.  Each solid shape should have
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    31
    a purple fill."""
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    32
    D = Drawing(400, 200) #, fillColor=colors.purple)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 817
diff changeset
    33
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    34
    D.add(Line(10,10,390,190))
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    35
    D.add(Circle(100,100,20, fillColor=colors.purple))
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    36
    D.add(Circle(200,100,20, fillColor=colors.purple))
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    37
    D.add(Circle(300,100,20, fillColor=colors.purple))
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    38
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    39
    D.add(Wedge(330,100,40, -10,40, fillColor=colors.purple))
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    40
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    41
    D.add(PolyLine([120,10,130,20,140,10,150,20,160,10,
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 817
diff changeset
    42
                    170,20,180,10,190,20,200,10]))
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    43
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    44
    D.add(Polygon([300,20,350,20,390,80,300,75, 330, 40]))
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    45
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    46
    D.add(Ellipse(50, 150, 40, 20))
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    47
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    48
    D.add(Rect(120, 150, 60, 30,
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    49
               strokeWidth=10,
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    50
               strokeColor=colors.red,
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    51
               fillColor=colors.yellow))  #square corners
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 817
diff changeset
    52
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 817
diff changeset
    53
    D.add(Rect(220, 150, 60, 30, 10, 10))  #round corners
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    54
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    55
    D.add(String(10,50, 'Basic Shapes', fillColor=colors.black))
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    56
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    57
    return D
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    58
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    59
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    60
##def getDrawing2():
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    61
##    """This drawing uses groups. Each group has two circles and a comment.
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    62
##    The line style is set at group level and should be red for the left,
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    63
##    bvlue for the right."""
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    64
##    D = Drawing(400, 200)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    65
##
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    66
##    Group1 = Group()
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    67
##
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    68
##    Group1.add(String(50, 50, 'Group 1', fillColor=colors.black))
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    69
##    Group1.add(Circle(75,100,25))
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    70
##    Group1.add(Circle(125,100,25))
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    71
##    D.add(Group1)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    72
##
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    73
##    Group2 = Group(
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    74
##        String(250, 50, 'Group 2', fillColor=colors.black),
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    75
##        Circle(275,100,25),
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    76
##        Circle(325,100,25)#,
817
8c3a399effda License text changes
rgbecker
parents: 568
diff changeset
    77
8c3a399effda License text changes
rgbecker
parents: 568
diff changeset
    78
8c3a399effda License text changes
rgbecker
parents: 568
diff changeset
    79
##def getDrawing2():
8c3a399effda License text changes
rgbecker
parents: 568
diff changeset
    80
##    """This drawing uses groups. Each group has two circles and a comment.
8c3a399effda License text changes
rgbecker
parents: 568
diff changeset
    81
##    The line style is set at group level and should be red for the left,
8c3a399effda License text changes
rgbecker
parents: 568
diff changeset
    82
##    bvlue for the right."""
8c3a399effda License text changes
rgbecker
parents: 568
diff changeset
    83
##    D = Drawing(400, 200)
8c3a399effda License text changes
rgbecker
parents: 568
diff changeset
    84
##
8c3a399effda License text changes
rgbecker
parents: 568
diff changeset
    85
##    Group1 = Group()
8c3a399effda License text changes
rgbecker
parents: 568
diff changeset
    86
##
8c3a399effda License text changes
rgbecker
parents: 568
diff changeset
    87
##    Group1.add(String(50, 50, 'Group 1', fillColor=colors.black))
8c3a399effda License text changes
rgbecker
parents: 568
diff changeset
    88
##    Group1.add(Circle(75,100,25))
8c3a399effda License text changes
rgbecker
parents: 568
diff changeset
    89
##    Group1.add(Circle(125,100,25))
8c3a399effda License text changes
rgbecker
parents: 568
diff changeset
    90
##    D.add(Group1)
8c3a399effda License text changes
rgbecker
parents: 568
diff changeset
    91
##
8c3a399effda License text changes
rgbecker
parents: 568
diff changeset
    92
##    Group2 = Group(
8c3a399effda License text changes
rgbecker
parents: 568
diff changeset
    93
##        String(250, 50, 'Group 2', fillColor=colors.black),
8c3a399effda License text changes
rgbecker
parents: 568
diff changeset
    94
##        Circle(275,100,25),
8c3a399effda License text changes
rgbecker
parents: 568
diff changeset
    95
##        Circle(325,100,25)#,
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    96
##
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    97
##        #group attributes
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    98
##        #strokeColor=colors.blue
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 817
diff changeset
    99
##        )
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   100
##    D.add(Group2)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   101
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   102
##    return D
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   103
##
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   104
##
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   105
##def getDrawing3():
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   106
##    """This uses a named reference object.  The house is a 'subroutine'
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   107
##    the basic brick colored walls are defined, but the roof and window
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   108
##    color are undefined and may be set by the container."""
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 817
diff changeset
   109
##
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   110
##    D = Drawing(400, 200, fill=colors.bisque)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   111
##
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 817
diff changeset
   112
##
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   113
##    House = Group(
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   114
##        Rect(2,20,36,30, fill=colors.bisque),  #walls
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   115
##        Polygon([0,20,40,20,20,5]), #roof
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   116
##        Rect(8, 38, 8, 12), #door
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   117
##        Rect(25, 38, 8, 7), #window
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   118
##        Rect(8, 25, 8, 7), #window
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   119
##        Rect(25, 25, 8, 7) #window
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 817
diff changeset
   120
##
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 817
diff changeset
   121
##        )
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   122
##    D.addDef('MyHouse', House)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   123
##
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   124
##    # one row all the same color
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   125
##    D.add(String(20, 40, 'British Street...',fill=colors.black))
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   126
##    for i in range(6):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   127
##        x = i * 50
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   128
##        D.add(NamedReference('MyHouse',
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   129
##                             House,
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   130
##                             transform=translate(x, 40),
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   131
##                             fill = colors.brown
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   132
##                             )
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   133
##              )
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   134
##
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   135
##    # now do a row all different
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   136
##    D.add(String(20, 120, 'Mediterranean Street...',fill=colors.black))
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   137
##    x = 0
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   138
##    for color in (colors.blue, colors.yellow, colors.orange,
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   139
##                       colors.red, colors.green, colors.chartreuse):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   140
##        D.add(NamedReference('MyHouse',
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   141
##                             House,
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   142
##                             transform=translate(x,120),
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   143
##                             fill = color,
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   144
##                             )
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   145
##              )
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   146
##        x = x + 50
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   147
##    #..by popular demand, the mayor gets a big one at the end
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   148
##    D.add(NamedReference('MyHouse',
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   149
##                             House,
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   150
##                             transform=mmult(translate(x,110), scale(1.2,1.2)),
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   151
##                             fill = color,
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   152
##                             )
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   153
##              )
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 817
diff changeset
   154
##
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 817
diff changeset
   155
##
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   156
##    return D
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   157
##
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   158
##def getDrawing4():
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   159
##    """This tests that attributes are 'unset' correctly when
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   160
##    one steps back out of a drawing node. All the circles are part of a
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   161
##    group setting the line color to blue; the second circle explicitly
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   162
##    sets it to red.  Ideally, the third circle should go back to blue."""
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   163
##    D = Drawing(400, 200)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   164
##
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   165
##
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   166
##    G = Group(
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   167
##            Circle(100,100,20),
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   168
##            Circle(200,100,20, stroke=colors.blue),
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   169
##            Circle(300,100,20),
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   170
##            stroke=colors.red,
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   171
##            stroke_width=3,
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   172
##            fill=colors.aqua
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   173
##            )
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 817
diff changeset
   174
##    D.add(G)
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   175
##
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 817
diff changeset
   176
##
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   177
##    D.add(String(10,50, 'Stack Unwinding - should be red, blue, red'))
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   178
##
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   179
##    return D
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   180
##
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   181
##
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   182
##def getDrawing5():
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   183
##    """This Rotates Coordinate Axes"""
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   184
##    D = Drawing(400, 200)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 817
diff changeset
   185
##
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   186
##
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   187
##
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   188
##    Axis = Group(
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   189
##        Line(0,0,100,0), #x axis
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   190
##        Line(0,0,0,50),   # y axis
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   191
##        Line(0,10,10,10), #ticks on y axis
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   192
##        Line(0,20,10,20),
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   193
##        Line(0,30,10,30),
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   194
##        Line(0,40,10,40),
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   195
##        Line(10,0,10,10), #ticks on x axis
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 817
diff changeset
   196
##        Line(20,0,20,10),
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 817
diff changeset
   197
##        Line(30,0,30,10),
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 817
diff changeset
   198
##        Line(40,0,40,10),
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 817
diff changeset
   199
##        Line(50,0,50,10),
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 817
diff changeset
   200
##        Line(60,0,60,10),
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 817
diff changeset
   201
##        Line(70,0,70,10),
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 817
diff changeset
   202
##        Line(80,0,80,10),
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   203
##        Line(90,0,90,10),
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   204
##        String(20, 35, 'Axes', fill=colors.black)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   205
##        )
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   206
##
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 817
diff changeset
   207
##    D.addDef('Axes', Axis)
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 817
diff changeset
   208
##
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   209
##    D.add(NamedReference('Axis', Axis,
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   210
##            transform=translate(10,10)))
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   211
##    D.add(NamedReference('Axis', Axis,
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   212
##            transform=mmult(translate(150,10),rotate(15)))
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   213
##          )
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   214
##    return D
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   215
##
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   216
##def getDrawing6():
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   217
##    """This Rotates Text"""
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   218
##    D = Drawing(400, 300, fill=colors.black)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   219
##
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   220
##    xform = translate(200,150)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   221
##    C = (colors.black,colors.red,colors.green,colors.blue,colors.brown,colors.gray, colors.pink,
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   222
##        colors.lavender,colors.lime, colors.mediumblue, colors.magenta, colors.limegreen)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   223
##
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 817
diff changeset
   224
##    for i in range(12):
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   225
##        D.add(String(0, 0, ' - - Rotated Text', fill=C[i%len(C)], transform=mmult(xform, rotate(30*i))))
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 817
diff changeset
   226
##
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   227
##    return D
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   228
##
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   229
##def getDrawing7():
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   230
##    """This defines and tests a simple UserNode0 (the trailing zero denotes
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   231
##    an experimental method which is not part of the supported API yet).
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   232
##    Each of the four charts is a subclass of UserNode which generates a random
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   233
##    series when rendered."""
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   234
##
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   235
##    class MyUserNode(UserNode0):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   236
##        import whrandom, math
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 817
diff changeset
   237
##
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   238
##
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   239
##        def provideNode(self, sender):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   240
##            """draw a simple chart that changes everytime it's drawn"""
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   241
##            # print "here's a random  number %s" % self.whrandom.random()
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   242
##            #print "MyUserNode.provideNode being called by %s" % sender
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   243
##            g = Group()
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   244
##            #g._state = self._state  # this is naughty
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   245
##            PingoNode.__init__(g, self._state)  # is this less naughty ?
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   246
##            w = 80.0
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   247
##            h = 50.0
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   248
##            g.add(Rect(0,0, w, h, stroke=colors.black))
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   249
##            N = 10.0
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   250
##            x,y = (0,h)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   251
##            dx = w/N
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   252
##            for ii in range(N):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   253
##                dy = (h/N) * self.whrandom.random()
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   254
##                g.add(Line(x,y,x+dx, y-dy))
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   255
##                x = x + dx
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   256
##                y = y - dy
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   257
##            return g
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   258
##
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   259
##    D = Drawing(400,200, fill=colors.white)  # AR - same size as others
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 817
diff changeset
   260
##
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   261
##    D.add(MyUserNode())
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   262
##
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   263
##    graphcolor= [colors.green, colors.red, colors.brown, colors.purple]
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   264
##    for ii in range(4):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   265
##        D.add(Group( MyUserNode(stroke=graphcolor[ii], stroke_width=2),
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   266
##                     transform=translate(ii*90,0) ))
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   267
##
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   268
##    #un = MyUserNode()
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   269
##    #print un.provideNode()
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   270
##    return D
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   271
##
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   272
##def getDrawing8():
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   273
##    """Test Path operations--lineto, curveTo, etc."""
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   274
##    D = Drawing(400, 200, fill=None, stroke=colors.purple, stroke_width=2)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   275
##
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   276
##    xform = translate(200,100)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   277
##    C = (colors.black,colors.red,colors.green,colors.blue,colors.brown,colors.gray, colors.pink,
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   278
##        colors.lavender,colors.lime, colors.mediumblue, colors.magenta, colors.limegreen)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   279
##    p = Path(50,50)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   280
##    p.lineTo(100,100)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   281
##    p.moveBy(-25,25)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   282
##    p.curveTo(150,125, 125,125, 200,50)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   283
##    p.curveTo(175, 75, 175, 98, 62, 87)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   284
##
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   285
##
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   286
##    D.add(p)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   287
##    D.add(String(10,30, 'Tests of path elements-lines and bezier curves-and text formating'))
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   288
##    D.add(Line(220,150, 220,200, stroke=colors.red))
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   289
##    D.add(String(220,180, "Text should be centered", text_anchor="middle") )
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   290
##
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 817
diff changeset
   291
##
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   292
##    return D
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 817
diff changeset
   293
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   294
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   295
if __name__=='__main__':
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
   296
    print(__doc__)