src/reportlab/graphics/widgets/grids.py
author robin <robin@reportlab.com>
Tue, 07 Mar 2017 10:00:34 +0000
changeset 4330 617ffa6bbdc8
parent 4252 fe660f227cac
child 4370 823a8c33ce43
permissions -rw-r--r--
changes for release 3.4.0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4330
617ffa6bbdc8 changes for release 3.4.0
robin <robin@reportlab.com>
parents: 4252
diff changeset
     1
#Copyright ReportLab Europe Ltd. 2000-2017
1023
af677b0199f6 Initial checkin.
dinu_gherman
parents:
diff changeset
     2
#see license.txt for license details
2332
2a7ab4405e18 Remove $Header:, fix CopyRight & history
rgbecker
parents: 2295
diff changeset
     3
#history http://www.reportlab.co.uk/cgi-bin/viewcvs.cgi/public/reportlab/trunk/reportlab/graphics/widgets/grids.py
4252
fe660f227cac changes for release 3.3.0
robin
parents: 3965
diff changeset
     4
__version__='3.3.0'
1023
af677b0199f6 Initial checkin.
dinu_gherman
parents:
diff changeset
     5
af677b0199f6 Initial checkin.
dinu_gherman
parents:
diff changeset
     6
from reportlab.lib import colors
2821
af061d9d3523 grids.py: validation fix from Dirk Datzert
rgbecker
parents: 2332
diff changeset
     7
from reportlab.lib.validators import isNumber, isColorOrNone, isBoolean, isListOfNumbers, OneOf, isListOfColors, isNumberOrNone
1706
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
     8
from reportlab.lib.attrmap import AttrMap, AttrMapValue
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
     9
from reportlab.graphics.shapes import Drawing, Group, Line, Rect, LineShape, definePath, EmptyClipPath
1023
af677b0199f6 Initial checkin.
dinu_gherman
parents:
diff changeset
    10
from reportlab.graphics.widgetbase import Widget
af677b0199f6 Initial checkin.
dinu_gherman
parents:
diff changeset
    11
1027
1b5a9e769a73 Added some tiny fixes plus more samples.
dinu_gherman
parents: 1024
diff changeset
    12
def frange(start, end=None, inc=None):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    13
    "A range function, that does accept float increments..."
1027
1b5a9e769a73 Added some tiny fixes plus more samples.
dinu_gherman
parents: 1024
diff changeset
    14
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    15
    if end == None:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    16
        end = start + 0.0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    17
        start = 0.0
1027
1b5a9e769a73 Added some tiny fixes plus more samples.
dinu_gherman
parents: 1024
diff changeset
    18
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    19
    if inc == None:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    20
        inc = 1.0
1027
1b5a9e769a73 Added some tiny fixes plus more samples.
dinu_gherman
parents: 1024
diff changeset
    21
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    22
    L = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    23
    end = end - inc*0.0001  #to avoid numrical problems
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    24
    while 1:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    25
        next = start + len(L) * inc
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    26
        if inc > 0 and next >= end:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    27
            break
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    28
        elif inc < 0 and next <= end:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    29
            break
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    30
        L.append(next)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
    31
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    32
    return L
1027
1b5a9e769a73 Added some tiny fixes plus more samples.
dinu_gherman
parents: 1024
diff changeset
    33
1b5a9e769a73 Added some tiny fixes plus more samples.
dinu_gherman
parents: 1024
diff changeset
    34
1053
b31b6c1e542d Massive code simplifications plus arbitrary delta steps implemented.
dinu_gherman
parents: 1052
diff changeset
    35
def makeDistancesList(list):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    36
    """Returns a list of distances between adjacent numbers in some input list.
1053
b31b6c1e542d Massive code simplifications plus arbitrary delta steps implemented.
dinu_gherman
parents: 1052
diff changeset
    37
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    38
    E.g. [1, 1, 2, 3, 5, 7] -> [0, 1, 1, 2, 2]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    39
    """
1053
b31b6c1e542d Massive code simplifications plus arbitrary delta steps implemented.
dinu_gherman
parents: 1052
diff changeset
    40
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    41
    d = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    42
    for i in range(len(list[:-1])):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    43
        d.append(list[i+1] - list[i])
1139
d4da066f39cc Added another output PDF test document.
dinu_gherman
parents: 1102
diff changeset
    44
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    45
    return d
1053
b31b6c1e542d Massive code simplifications plus arbitrary delta steps implemented.
dinu_gherman
parents: 1052
diff changeset
    46
b31b6c1e542d Massive code simplifications plus arbitrary delta steps implemented.
dinu_gherman
parents: 1052
diff changeset
    47
1088
518a118debc0 Removed trailing 0 from Grid and ShadedRect; robustified
andy_robinson
parents: 1086
diff changeset
    48
class Grid(Widget):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    49
    """This makes a rectangular grid of equidistant stripes.
1023
af677b0199f6 Initial checkin.
dinu_gherman
parents:
diff changeset
    50
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    51
    The grid contains an outer border rectangle, and stripes
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    52
    inside which can be drawn with lines and/or as solid tiles.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    53
    The drawing order is: outer rectangle, then lines and tiles.
1023
af677b0199f6 Initial checkin.
dinu_gherman
parents:
diff changeset
    54
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    55
    The stripes' width is indicated as 'delta'. The sequence of
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    56
    stripes can have an offset named 'delta0'. Both values need
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    57
    to be positive!
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    58
    """
1023
af677b0199f6 Initial checkin.
dinu_gherman
parents:
diff changeset
    59
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    60
    _attrMap = AttrMap(
1804
88c2e7684c45 Fix backgrounds
rgbecker
parents: 1717
diff changeset
    61
        x = AttrMapValue(isNumber, desc="The grid's lower-left x position."),
88c2e7684c45 Fix backgrounds
rgbecker
parents: 1717
diff changeset
    62
        y = AttrMapValue(isNumber, desc="The grid's lower-left y position."),
88c2e7684c45 Fix backgrounds
rgbecker
parents: 1717
diff changeset
    63
        width = AttrMapValue(isNumber, desc="The grid's width."),
88c2e7684c45 Fix backgrounds
rgbecker
parents: 1717
diff changeset
    64
        height = AttrMapValue(isNumber, desc="The grid's height."),
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    65
        orientation = AttrMapValue(OneOf(('vertical', 'horizontal')),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    66
            desc='Determines if stripes are vertical or horizontal.'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    67
        useLines = AttrMapValue(OneOf((0, 1)),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    68
            desc='Determines if stripes are drawn with lines.'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    69
        useRects = AttrMapValue(OneOf((0, 1)),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    70
            desc='Determines if stripes are drawn with solid rectangles.'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    71
        delta = AttrMapValue(isNumber,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    72
            desc='Determines the width/height of the stripes.'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    73
        delta0 = AttrMapValue(isNumber,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    74
            desc='Determines the stripes initial width/height offset.'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    75
        deltaSteps = AttrMapValue(isListOfNumbers,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    76
            desc='List of deltas to be used cyclically.'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    77
        stripeColors = AttrMapValue(isListOfColors,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    78
            desc='Colors applied cyclically in the right or upper direction.'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    79
        fillColor = AttrMapValue(isColorOrNone,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    80
            desc='Background color for entire rectangle.'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    81
        strokeColor = AttrMapValue(isColorOrNone,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    82
            desc='Color used for lines.'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    83
        strokeWidth = AttrMapValue(isNumber,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    84
            desc='Width used for lines.'),
1884
96f7f6c333e3 Allow for outer rect to be special
rgbecker
parents: 1804
diff changeset
    85
        rectStrokeColor = AttrMapValue(isColorOrNone, desc='Color for outer rect stroke.'),
2821
af061d9d3523 grids.py: validation fix from Dirk Datzert
rgbecker
parents: 2332
diff changeset
    86
        rectStrokeWidth = AttrMapValue(isNumberOrNone, desc='Width for outer rect stroke.'),
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    87
        )
1023
af677b0199f6 Initial checkin.
dinu_gherman
parents:
diff changeset
    88
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    89
    def __init__(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    90
        self.x = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    91
        self.y = 0
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
    92
        self.width = 100
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
    93
        self.height = 100
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
    94
        self.orientation = 'vertical'
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    95
        self.useLines = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    96
        self.useRects = 1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    97
        self.delta = 20
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    98
        self.delta0 = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
    99
        self.deltaSteps = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   100
        self.fillColor = colors.white
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   101
        self.stripeColors = [colors.red, colors.green, colors.blue]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   102
        self.strokeColor = colors.black
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   103
        self.strokeWidth = 2
1023
af677b0199f6 Initial checkin.
dinu_gherman
parents:
diff changeset
   104
af677b0199f6 Initial checkin.
dinu_gherman
parents:
diff changeset
   105
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   106
    def demo(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   107
        D = Drawing(100, 100)
1023
af677b0199f6 Initial checkin.
dinu_gherman
parents:
diff changeset
   108
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   109
        g = Grid()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   110
        D.add(g)
1023
af677b0199f6 Initial checkin.
dinu_gherman
parents:
diff changeset
   111
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   112
        return D
1023
af677b0199f6 Initial checkin.
dinu_gherman
parents:
diff changeset
   113
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   114
    def makeOuterRect(self):
1884
96f7f6c333e3 Allow for outer rect to be special
rgbecker
parents: 1804
diff changeset
   115
        strokeColor = getattr(self,'rectStrokeColor',self.strokeColor)
96f7f6c333e3 Allow for outer rect to be special
rgbecker
parents: 1804
diff changeset
   116
        strokeWidth = getattr(self,'rectStrokeWidth',self.strokeWidth)
96f7f6c333e3 Allow for outer rect to be special
rgbecker
parents: 1804
diff changeset
   117
        if self.fillColor or (strokeColor and strokeWidth):
1804
88c2e7684c45 Fix backgrounds
rgbecker
parents: 1717
diff changeset
   118
            rect = Rect(self.x, self.y, self.width, self.height)
88c2e7684c45 Fix backgrounds
rgbecker
parents: 1717
diff changeset
   119
            rect.fillColor = self.fillColor
1884
96f7f6c333e3 Allow for outer rect to be special
rgbecker
parents: 1804
diff changeset
   120
            rect.strokeColor = strokeColor
96f7f6c333e3 Allow for outer rect to be special
rgbecker
parents: 1804
diff changeset
   121
            rect.strokeWidth = strokeWidth
1804
88c2e7684c45 Fix backgrounds
rgbecker
parents: 1717
diff changeset
   122
            return rect
88c2e7684c45 Fix backgrounds
rgbecker
parents: 1717
diff changeset
   123
        else:
88c2e7684c45 Fix backgrounds
rgbecker
parents: 1717
diff changeset
   124
            return None
1023
af677b0199f6 Initial checkin.
dinu_gherman
parents:
diff changeset
   125
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   126
    def makeLinePosList(self, start, isX=0):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   127
        "Returns a list of positions where to place lines."
1053
b31b6c1e542d Massive code simplifications plus arbitrary delta steps implemented.
dinu_gherman
parents: 1052
diff changeset
   128
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   129
        w, h = self.width, self.height
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   130
        if isX:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   131
            length = w
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   132
        else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   133
            length = h
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   134
        if self.deltaSteps:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   135
            r = [start + self.delta0]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   136
            i = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   137
            while 1:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   138
                if r[-1] > start + length:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   139
                    del r[-1]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   140
                    break
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   141
                r.append(r[-1] + self.deltaSteps[i % len(self.deltaSteps)])
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   142
                i = i + 1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   143
        else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   144
            r = frange(start + self.delta0, start + length, self.delta)
1053
b31b6c1e542d Massive code simplifications plus arbitrary delta steps implemented.
dinu_gherman
parents: 1052
diff changeset
   145
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   146
        r.append(start + length)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   147
        if self.delta0 != 0:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   148
            r.insert(0, start)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   149
        #print 'Grid.makeLinePosList() -> %s' % r
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   150
        return r
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   151
1053
b31b6c1e542d Massive code simplifications plus arbitrary delta steps implemented.
dinu_gherman
parents: 1052
diff changeset
   152
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   153
    def makeInnerLines(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   154
        # inner grid lines
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   155
        group = Group()
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   156
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   157
        w, h = self.width, self.height
1027
1b5a9e769a73 Added some tiny fixes plus more samples.
dinu_gherman
parents: 1024
diff changeset
   158
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   159
        if self.useLines == 1:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   160
            if self.orientation == 'vertical':
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   161
                r = self.makeLinePosList(self.x, isX=1)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   162
                for x in r:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   163
                    line = Line(x, self.y, x, self.y + h)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   164
                    line.strokeColor = self.strokeColor
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   165
                    line.strokeWidth = self.strokeWidth
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   166
                    group.add(line)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   167
            elif self.orientation == 'horizontal':
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   168
                r = self.makeLinePosList(self.y, isX=0)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   169
                for y in r:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   170
                    line = Line(self.x, y, self.x + w, y)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   171
                    line.strokeColor = self.strokeColor
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   172
                    line.strokeWidth = self.strokeWidth
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   173
                    group.add(line)
1023
af677b0199f6 Initial checkin.
dinu_gherman
parents:
diff changeset
   174
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   175
        return group
1023
af677b0199f6 Initial checkin.
dinu_gherman
parents:
diff changeset
   176
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   177
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   178
    def makeInnerTiles(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   179
        # inner grid lines
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   180
        group = Group()
1023
af677b0199f6 Initial checkin.
dinu_gherman
parents:
diff changeset
   181
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   182
        w, h = self.width, self.height
1027
1b5a9e769a73 Added some tiny fixes plus more samples.
dinu_gherman
parents: 1024
diff changeset
   183
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   184
        # inner grid stripes (solid rectangles)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   185
        if self.useRects == 1:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   186
            cols = self.stripeColors
1053
b31b6c1e542d Massive code simplifications plus arbitrary delta steps implemented.
dinu_gherman
parents: 1052
diff changeset
   187
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   188
            if self.orientation == 'vertical':
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   189
                r = self.makeLinePosList(self.x, isX=1)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   190
            elif self.orientation == 'horizontal':
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   191
                r = self.makeLinePosList(self.y, isX=0)
1023
af677b0199f6 Initial checkin.
dinu_gherman
parents:
diff changeset
   192
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   193
            dist = makeDistancesList(r)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   194
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   195
            i = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   196
            for j in range(len(dist)):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   197
                if self.orientation == 'vertical':
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   198
                    x = r[j]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   199
                    stripe = Rect(x, self.y, dist[j], h)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   200
                elif self.orientation == 'horizontal':
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   201
                    y = r[j]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   202
                    stripe = Rect(self.x, y, w, dist[j])
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   203
                stripe.fillColor = cols[i % len(cols)]
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   204
                stripe.strokeColor = None
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   205
                group.add(stripe)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   206
                i = i + 1
1023
af677b0199f6 Initial checkin.
dinu_gherman
parents:
diff changeset
   207
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   208
        return group
1023
af677b0199f6 Initial checkin.
dinu_gherman
parents:
diff changeset
   209
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   210
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   211
    def draw(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   212
        # general widget bits
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   213
        group = Group()
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   214
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   215
        group.add(self.makeOuterRect())
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   216
        group.add(self.makeInnerTiles())
2016
a816a3167340 Comment problematic PICT code
rgbecker
parents: 1884
diff changeset
   217
        group.add(self.makeInnerLines(),name='_gridLines')
1023
af677b0199f6 Initial checkin.
dinu_gherman
parents:
diff changeset
   218
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   219
        return group
1023
af677b0199f6 Initial checkin.
dinu_gherman
parents:
diff changeset
   220
af677b0199f6 Initial checkin.
dinu_gherman
parents:
diff changeset
   221
1102
6fb285f5f382 Added DoubleGrid class.
dinu_gherman
parents: 1088
diff changeset
   222
class DoubleGrid(Widget):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   223
    """This combines two ordinary Grid objects orthogonal to each other.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   224
    """
1102
6fb285f5f382 Added DoubleGrid class.
dinu_gherman
parents: 1088
diff changeset
   225
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   226
    _attrMap = AttrMap(
1804
88c2e7684c45 Fix backgrounds
rgbecker
parents: 1717
diff changeset
   227
        x = AttrMapValue(isNumber, desc="The grid's lower-left x position."),
88c2e7684c45 Fix backgrounds
rgbecker
parents: 1717
diff changeset
   228
        y = AttrMapValue(isNumber, desc="The grid's lower-left y position."),
88c2e7684c45 Fix backgrounds
rgbecker
parents: 1717
diff changeset
   229
        width = AttrMapValue(isNumber, desc="The grid's width."),
88c2e7684c45 Fix backgrounds
rgbecker
parents: 1717
diff changeset
   230
        height = AttrMapValue(isNumber, desc="The grid's height."),
88c2e7684c45 Fix backgrounds
rgbecker
parents: 1717
diff changeset
   231
        grid0 = AttrMapValue(None, desc="The first grid component."),
88c2e7684c45 Fix backgrounds
rgbecker
parents: 1717
diff changeset
   232
        grid1 = AttrMapValue(None, desc="The second grid component."),
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   233
        )
1102
6fb285f5f382 Added DoubleGrid class.
dinu_gherman
parents: 1088
diff changeset
   234
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   235
    def __init__(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   236
        self.x = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   237
        self.y = 0
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   238
        self.width = 100
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   239
        self.height = 100
1102
6fb285f5f382 Added DoubleGrid class.
dinu_gherman
parents: 1088
diff changeset
   240
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   241
        g0 = Grid()
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   242
        g0.x = self.x
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   243
        g0.y = self.y
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   244
        g0.width = self.width
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   245
        g0.height = self.height
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   246
        g0.orientation = 'vertical'
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   247
        g0.useLines = 1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   248
        g0.useRects = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   249
        g0.delta = 20
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   250
        g0.delta0 = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   251
        g0.deltaSteps = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   252
        g0.fillColor = colors.white
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   253
        g0.stripeColors = [colors.red, colors.green, colors.blue]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   254
        g0.strokeColor = colors.black
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   255
        g0.strokeWidth = 1
1102
6fb285f5f382 Added DoubleGrid class.
dinu_gherman
parents: 1088
diff changeset
   256
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   257
        g1 = Grid()
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   258
        g1.x = self.x
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   259
        g1.y = self.y
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   260
        g1.width = self.width
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   261
        g1.height = self.height
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   262
        g1.orientation = 'horizontal'
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   263
        g1.useLines = 1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   264
        g1.useRects = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   265
        g1.delta = 20
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   266
        g1.delta0 = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   267
        g1.deltaSteps = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   268
        g1.fillColor = colors.white
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   269
        g1.stripeColors = [colors.red, colors.green, colors.blue]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   270
        g1.strokeColor = colors.black
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   271
        g1.strokeWidth = 1
1102
6fb285f5f382 Added DoubleGrid class.
dinu_gherman
parents: 1088
diff changeset
   272
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   273
        self.grid0 = g0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   274
        self.grid1 = g1
1102
6fb285f5f382 Added DoubleGrid class.
dinu_gherman
parents: 1088
diff changeset
   275
6fb285f5f382 Added DoubleGrid class.
dinu_gherman
parents: 1088
diff changeset
   276
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   277
##    # This gives an AttributeError:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   278
##    #   DoubleGrid instance has no attribute 'grid0'
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   279
##    def __setattr__(self, name, value):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   280
##        if name in ('x', 'y', 'width', 'height'):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   281
##            setattr(self.grid0, name, value)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   282
##            setattr(self.grid1, name, value)
1102
6fb285f5f382 Added DoubleGrid class.
dinu_gherman
parents: 1088
diff changeset
   283
6fb285f5f382 Added DoubleGrid class.
dinu_gherman
parents: 1088
diff changeset
   284
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   285
    def demo(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   286
        D = Drawing(100, 100)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   287
        g = DoubleGrid()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   288
        D.add(g)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   289
        return D
1102
6fb285f5f382 Added DoubleGrid class.
dinu_gherman
parents: 1088
diff changeset
   290
6fb285f5f382 Added DoubleGrid class.
dinu_gherman
parents: 1088
diff changeset
   291
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   292
    def draw(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   293
        group = Group()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   294
        g0, g1 = self.grid0, self.grid1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   295
        # Order groups to make sure both v and h lines
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   296
        # are visible (works only when there is only
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   297
        # one kind of stripes, v or h).
1804
88c2e7684c45 Fix backgrounds
rgbecker
parents: 1717
diff changeset
   298
        G = g0.useRects == 1 and g1.useRects == 0 and (g0,g1) or (g1,g0)
88c2e7684c45 Fix backgrounds
rgbecker
parents: 1717
diff changeset
   299
        for g in G:
88c2e7684c45 Fix backgrounds
rgbecker
parents: 1717
diff changeset
   300
            group.add(g.makeOuterRect())
88c2e7684c45 Fix backgrounds
rgbecker
parents: 1717
diff changeset
   301
        for g in G:
88c2e7684c45 Fix backgrounds
rgbecker
parents: 1717
diff changeset
   302
            group.add(g.makeInnerTiles())
2016
a816a3167340 Comment problematic PICT code
rgbecker
parents: 1884
diff changeset
   303
            group.add(g.makeInnerLines(),name='_gridLines')
1102
6fb285f5f382 Added DoubleGrid class.
dinu_gherman
parents: 1088
diff changeset
   304
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   305
        return group
1102
6fb285f5f382 Added DoubleGrid class.
dinu_gherman
parents: 1088
diff changeset
   306
6fb285f5f382 Added DoubleGrid class.
dinu_gherman
parents: 1088
diff changeset
   307
1088
518a118debc0 Removed trailing 0 from Grid and ShadedRect; robustified
andy_robinson
parents: 1086
diff changeset
   308
class ShadedRect(Widget):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   309
    """This makes a rectangle with shaded colors between two colors.
1027
1b5a9e769a73 Added some tiny fixes plus more samples.
dinu_gherman
parents: 1024
diff changeset
   310
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   311
    Colors are interpolated linearly between 'fillColorStart'
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   312
    and 'fillColorEnd', both of which appear at the margins.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   313
    If 'numShades' is set to one, though, only 'fillColorStart'
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   314
    is used.
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   315
    """
1023
af677b0199f6 Initial checkin.
dinu_gherman
parents:
diff changeset
   316
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   317
    _attrMap = AttrMap(
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   318
        x = AttrMapValue(isNumber, desc="The grid's lower-left x position."),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   319
        y = AttrMapValue(isNumber, desc="The grid's lower-left y position."),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   320
        width = AttrMapValue(isNumber, desc="The grid's width."),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   321
        height = AttrMapValue(isNumber, desc="The grid's height."),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   322
        orientation = AttrMapValue(OneOf(('vertical', 'horizontal')), desc='Determines if stripes are vertical or horizontal.'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   323
        numShades = AttrMapValue(isNumber, desc='The number of interpolating colors.'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   324
        fillColorStart = AttrMapValue(isColorOrNone, desc='Start value of the color shade.'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   325
        fillColorEnd = AttrMapValue(isColorOrNone, desc='End value of the color shade.'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   326
        strokeColor = AttrMapValue(isColorOrNone, desc='Color used for border line.'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   327
        strokeWidth = AttrMapValue(isNumber, desc='Width used for lines.'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   328
        cylinderMode = AttrMapValue(isBoolean, desc='True if shading reverses in middle.'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   329
        )
1023
af677b0199f6 Initial checkin.
dinu_gherman
parents:
diff changeset
   330
1706
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   331
    def __init__(self,**kw):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   332
        self.x = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   333
        self.y = 0
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   334
        self.width = 100
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   335
        self.height = 100
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   336
        self.orientation = 'vertical'
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   337
        self.numShades = 20
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   338
        self.fillColorStart = colors.pink
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   339
        self.fillColorEnd = colors.black
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   340
        self.strokeColor = colors.black
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   341
        self.strokeWidth = 2
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   342
        self.cylinderMode = 0
1706
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   343
        self.setProperties(kw)
1023
af677b0199f6 Initial checkin.
dinu_gherman
parents:
diff changeset
   344
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   345
    def demo(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   346
        D = Drawing(100, 100)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   347
        g = ShadedRect()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   348
        D.add(g)
1215
7725238396e5 Added cylinderMode to shaded rectangle
rgbecker
parents: 1154
diff changeset
   349
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   350
        return D
1050
6868f03bccac Fixed bug with negative width/height.
dinu_gherman
parents: 1049
diff changeset
   351
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   352
    def _flipRectCorners(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   353
        "Flip rectangle's corners if width or height is negative."
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   354
        x, y, width, height, fillColorStart, fillColorEnd = self.x, self.y, self.width, self.height, self.fillColorStart, self.fillColorEnd
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   355
        if width < 0 and height > 0:
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   356
            x = x + width
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   357
            width = -width
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   358
            if self.orientation=='vertical': fillColorStart, fillColorEnd = fillColorEnd, fillColorStart
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   359
        elif height<0 and width>0:
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   360
            y = y + height
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   361
            height = -height
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   362
            if self.orientation=='horizontal': fillColorStart, fillColorEnd = fillColorEnd, fillColorStart
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   363
        elif height < 0 and height < 0:
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   364
            x = x + width
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   365
            width = -width
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   366
            y = y + height
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   367
            height = -height
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   368
        return x, y, width, height, fillColorStart, fillColorEnd
1023
af677b0199f6 Initial checkin.
dinu_gherman
parents:
diff changeset
   369
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   370
    def draw(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   371
        # general widget bits
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   372
        group = Group()
1717
b726c5ffa12f Allow stroke to appear
rgbecker
parents: 1707
diff changeset
   373
        x, y, w, h, c0, c1 = self._flipRectCorners()
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   374
        numShades = self.numShades
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   375
        if self.cylinderMode:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   376
            if not numShades%2: numShades = numShades+1
3965
af94dc5ef720 flags.py & grids.py: fix some divisions
robin
parents: 3721
diff changeset
   377
            halfNumShades = int((numShades-1)/2) + 1
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   378
        num = float(numShades) # must make it float!
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   379
        vertical = self.orientation == 'vertical'
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   380
        if vertical:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   381
            if numShades == 1:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   382
                V = [x]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   383
            else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   384
                V = frange(x, x + w, w/num)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   385
        else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   386
            if numShades == 1:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   387
                V = [y]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   388
            else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   389
                V = frange(y, y + h, h/num)
1215
7725238396e5 Added cylinderMode to shaded rectangle
rgbecker
parents: 1154
diff changeset
   390
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   391
        for v in V:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   392
            stripe = vertical and Rect(v, y, w/num, h) or Rect(x, v, w, h/num)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   393
            if self.cylinderMode:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   394
                if V.index(v)>=halfNumShades:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   395
                    col = colors.linearlyInterpolatedColor(c1,c0,V[halfNumShades],V[-1], v)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   396
                else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   397
                    col = colors.linearlyInterpolatedColor(c0,c1,V[0],V[halfNumShades], v)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   398
            else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   399
                col = colors.linearlyInterpolatedColor(c0,c1,V[0],V[-1], v)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   400
            stripe.fillColor = col
2295
08eb55311a12 Make stripe strokeColor same as fill
rgbecker
parents: 2016
diff changeset
   401
            stripe.strokeColor = col
08eb55311a12 Make stripe strokeColor same as fill
rgbecker
parents: 2016
diff changeset
   402
            stripe.strokeWidth = 1
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   403
            group.add(stripe)
1717
b726c5ffa12f Allow stroke to appear
rgbecker
parents: 1707
diff changeset
   404
        if self.strokeColor and self.strokeWidth>=0:
b726c5ffa12f Allow stroke to appear
rgbecker
parents: 1707
diff changeset
   405
            rect = Rect(x, y, w, h)
b726c5ffa12f Allow stroke to appear
rgbecker
parents: 1707
diff changeset
   406
            rect.strokeColor = self.strokeColor
b726c5ffa12f Allow stroke to appear
rgbecker
parents: 1707
diff changeset
   407
            rect.strokeWidth = self.strokeWidth
b726c5ffa12f Allow stroke to appear
rgbecker
parents: 1707
diff changeset
   408
            rect.fillColor = None
b726c5ffa12f Allow stroke to appear
rgbecker
parents: 1707
diff changeset
   409
            group.add(rect)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   410
        return group
1215
7725238396e5 Added cylinderMode to shaded rectangle
rgbecker
parents: 1154
diff changeset
   411
7725238396e5 Added cylinderMode to shaded rectangle
rgbecker
parents: 1154
diff changeset
   412
7725238396e5 Added cylinderMode to shaded rectangle
rgbecker
parents: 1154
diff changeset
   413
def colorRange(c0, c1, n):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   414
    "Return a range of intermediate colors between c0 and c1"
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   415
    if n==1: return [c0]
1215
7725238396e5 Added cylinderMode to shaded rectangle
rgbecker
parents: 1154
diff changeset
   416
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   417
    C = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   418
    if n>1:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   419
        lim = n-1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   420
        for i in range(n):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   421
            C.append(colors.linearlyInterpolatedColor(c0,c1,0,lim, i))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1656
diff changeset
   422
    return C
1149
2988abf8fcda Added test code.
dinu_gherman
parents: 1139
diff changeset
   423
1706
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   424
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   425
def centroid(P):
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   426
    '''compute average point of a set of points'''
3533
13190e8cf64e widgets\grids.py: try to fix some obvious problems
rgbecker
parents: 3326
diff changeset
   427
    cx = 0
13190e8cf64e widgets\grids.py: try to fix some obvious problems
rgbecker
parents: 3326
diff changeset
   428
    cy = 0
13190e8cf64e widgets\grids.py: try to fix some obvious problems
rgbecker
parents: 3326
diff changeset
   429
    for x,y in P:
13190e8cf64e widgets\grids.py: try to fix some obvious problems
rgbecker
parents: 3326
diff changeset
   430
        cx+=x
13190e8cf64e widgets\grids.py: try to fix some obvious problems
rgbecker
parents: 3326
diff changeset
   431
        cy+=y
13190e8cf64e widgets\grids.py: try to fix some obvious problems
rgbecker
parents: 3326
diff changeset
   432
    n = float(len(P))
13190e8cf64e widgets\grids.py: try to fix some obvious problems
rgbecker
parents: 3326
diff changeset
   433
    return cx/n, cy/n
1706
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   434
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   435
def rotatedEnclosingRect(P, angle, rect):
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   436
    '''
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   437
    given P a sequence P of x,y coordinate pairs and an angle in degrees
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   438
    find the centroid of P and the axis at angle theta through it
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   439
    find the extreme points of P wrt axis parallel distance and axis
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   440
    orthogonal distance. Then compute the least rectangle that will still
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   441
    enclose P when rotated by angle.
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   442
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   443
    The class R
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   444
    '''
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   445
    from math import pi, cos, sin, tan
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   446
    x0, y0 = centroid(P)
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   447
    theta = (angle/180.)*pi
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   448
    s,c=sin(theta),cos(theta)
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 2964
diff changeset
   449
    def parallelAxisDist(xy,s=s,c=c,x0=x0,y0=y0):
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 2964
diff changeset
   450
        x,y = xy
1706
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   451
        return (s*(y-y0)+c*(x-x0))
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 2964
diff changeset
   452
    def orthogonalAxisDist(xy,s=s,c=c,x0=x0,y0=y0):
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 2964
diff changeset
   453
        x,y = xy
1706
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   454
        return (c*(y-y0)+s*(x-x0))
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
   455
    L = list(map(parallelAxisDist,P))
1706
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   456
    L.sort()
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   457
    a0, a1 = L[0], L[-1]
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
   458
    L = list(map(orthogonalAxisDist,P))
1706
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   459
    L.sort()
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   460
    b0, b1 = L[0], L[-1]
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   461
    rect.x, rect.width = a0, a1-a0
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   462
    rect.y, rect.height = b0, b1-b0
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   463
    g = Group(transform=(c,s,-s,c,x0,y0))
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   464
    g.add(rect)
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   465
    return g
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   466
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   467
class ShadedPolygon(Widget,LineShape):
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   468
    _attrMap = AttrMap(BASE=LineShape,
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   469
        angle = AttrMapValue(isNumber,desc="Shading angle"),
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   470
        fillColorStart = AttrMapValue(isColorOrNone),
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   471
        fillColorEnd = AttrMapValue(isColorOrNone),
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   472
        numShades = AttrMapValue(isNumber, desc='The number of interpolating colors.'),
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   473
        cylinderMode = AttrMapValue(isBoolean, desc='True if shading reverses in middle.'),
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   474
        points = AttrMapValue(isListOfNumbers),
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   475
        )
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   476
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   477
    def __init__(self,**kw):
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   478
        self.angle = 90
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   479
        self.fillColorStart = colors.red
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   480
        self.fillColorEnd = colors.green
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   481
        self.cylinderMode = 0
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   482
        self.numShades = 50
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   483
        self.points = [-1,-1,2,2,3,-1]
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   484
        LineShape.__init__(self,kw)
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   485
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   486
    def draw(self):
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   487
        P = self.points
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
   488
        P = list(map(lambda i, P=P:(P[i],P[i+1]),range(0,len(P),2)))
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
   489
        path = definePath([('moveTo',)+P[0]]+[('lineTo',)+x for x in P[1:]]+['closePath'],
1706
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   490
            fillColor=None, strokeColor=None)
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   491
        path.isClipPath = 1
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   492
        g = Group()
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   493
        g.add(path)
3533
13190e8cf64e widgets\grids.py: try to fix some obvious problems
rgbecker
parents: 3326
diff changeset
   494
        angle = self.angle
13190e8cf64e widgets\grids.py: try to fix some obvious problems
rgbecker
parents: 3326
diff changeset
   495
        orientation = 'vertical'
13190e8cf64e widgets\grids.py: try to fix some obvious problems
rgbecker
parents: 3326
diff changeset
   496
        if angle==180:
13190e8cf64e widgets\grids.py: try to fix some obvious problems
rgbecker
parents: 3326
diff changeset
   497
            angle = 0
13190e8cf64e widgets\grids.py: try to fix some obvious problems
rgbecker
parents: 3326
diff changeset
   498
        elif angle in (90,270):
13190e8cf64e widgets\grids.py: try to fix some obvious problems
rgbecker
parents: 3326
diff changeset
   499
            orientation ='horizontal'
13190e8cf64e widgets\grids.py: try to fix some obvious problems
rgbecker
parents: 3326
diff changeset
   500
            angle = 0
13190e8cf64e widgets\grids.py: try to fix some obvious problems
rgbecker
parents: 3326
diff changeset
   501
        rect = ShadedRect(strokeWidth=0,strokeColor=None,orientation=orientation)
1706
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   502
        for k in 'fillColorStart', 'fillColorEnd', 'numShades', 'cylinderMode':
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   503
            setattr(rect,k,getattr(self,k))
3533
13190e8cf64e widgets\grids.py: try to fix some obvious problems
rgbecker
parents: 3326
diff changeset
   504
        g.add(rotatedEnclosingRect(P, angle, rect))
1706
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   505
        g.add(EmptyClipPath)
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   506
        path = path.copy()
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   507
        path.isClipPath = 0
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   508
        path.strokeColor = self.strokeColor
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   509
        path.strokeWidth = self.strokeWidth
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   510
        g.add(path)
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   511
        return g
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   512
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   513
if __name__=='__main__': #noruntests
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   514
    from reportlab.lib.colors import blue
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   515
    from reportlab.graphics.shapes import Drawing
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   516
    angle=45
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   517
    D = Drawing(120,120)
1717
b726c5ffa12f Allow stroke to appear
rgbecker
parents: 1707
diff changeset
   518
    D.add(ShadedPolygon(points=(10,10,60,60,110,10),strokeColor=None,strokeWidth=1,angle=90,numShades=50,cylinderMode=0))
1706
3081471a4e9d Experimental ShadedPolygon added
rgbecker
parents: 1683
diff changeset
   519
    D.save(formats=['gif'],fnRoot='shobj',outDir='/tmp')