reportlab/platypus/frames.py
author rgbecker
Thu, 17 Jun 2004 15:26:05 +0000
changeset 2332 2a7ab4405e18
parent 2213 edf7d844279c
child 2375 1e175a4474d0
permissions -rw-r--r--
Remove $Header:, fix CopyRight & history
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2332
2a7ab4405e18 Remove $Header:, fix CopyRight & history
rgbecker
parents: 2213
diff changeset
     1
#Copyright ReportLab Europe Ltd. 2000-2004
494
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 470
diff changeset
     2
#see license.txt for license details
2332
2a7ab4405e18 Remove $Header:, fix CopyRight & history
rgbecker
parents: 2213
diff changeset
     3
#history http://www.reportlab.co.uk/cgi-bin/viewcvs.cgi/public/reportlab/trunk/reportlab/platypus/frames.py
565
179927300074 Minor changes.
dinu_gherman
parents: 541
diff changeset
     4
2332
2a7ab4405e18 Remove $Header:, fix CopyRight & history
rgbecker
parents: 2213
diff changeset
     5
__version__=''' $Id$ '''
565
179927300074 Minor changes.
dinu_gherman
parents: 541
diff changeset
     6
253
cfcf8d555a2c Platypus re-organisation
rgbecker
parents:
diff changeset
     7
__doc__="""
cfcf8d555a2c Platypus re-organisation
rgbecker
parents:
diff changeset
     8
"""
565
179927300074 Minor changes.
dinu_gherman
parents: 541
diff changeset
     9
179927300074 Minor changes.
dinu_gherman
parents: 541
diff changeset
    10
_geomAttr=('x1', 'y1', 'width', 'height', 'leftPadding', 'bottomPadding', 'rightPadding', 'topPadding')
179927300074 Minor changes.
dinu_gherman
parents: 541
diff changeset
    11
1002
6ce27679a1f5 added _FUZZ and changed frame add test
rgbecker
parents: 565
diff changeset
    12
_FUZZ=1e-6 # to avoid numerical difficulties we use this as an error band
565
179927300074 Minor changes.
dinu_gherman
parents: 541
diff changeset
    13
1231
05dc2104f72d disable LayoutError error for production use (option to enable for debug)
aaron_watters
parents: 1035
diff changeset
    14
from reportlab import rl_config
05dc2104f72d disable LayoutError error for production use (option to enable for debug)
aaron_watters
parents: 1035
diff changeset
    15
253
cfcf8d555a2c Platypus re-organisation
rgbecker
parents:
diff changeset
    16
class Frame:
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    17
    '''
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    18
    A Frame is a piece of space in a document that is filled by the
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    19
    "flowables" in the story.  For example in a book like document most
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    20
    pages have the text paragraphs in one or two frames.  For generality
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    21
    a page might have several frames (for example for 3 column text or
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    22
    for text that wraps around a graphic).
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
    23
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    24
    After creation a Frame is not usually manipulated directly by the
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    25
    applications program -- it is used internally by the platypus modules.
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
    26
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    27
    Here is a diagramatid abstraction for the definitional part of a Frame
253
cfcf8d555a2c Platypus re-organisation
rgbecker
parents:
diff changeset
    28
cfcf8d555a2c Platypus re-organisation
rgbecker
parents:
diff changeset
    29
                width                    x2,y2
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    30
        +---------------------------------+
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    31
        | l  top padding                r | h
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    32
        | e +-------------------------+ i | e
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    33
        | f |                         | g | i
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    34
        | t |                         | h | g
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    35
        |   |                         | t | h
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    36
        | p |                         |   | t
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    37
        | a |                         | p |
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    38
        | d |                         | a |
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    39
        |   |                         | d |
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    40
        |   +-------------------------+   |
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    41
        |    bottom padding               |
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    42
        +---------------------------------+
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    43
        (x1,y1) <-- lower left corner
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
    44
268
8414113fa500 more documentation changes
aaron_watters
parents: 253
diff changeset
    45
        NOTE!! Frames are stateful objects.  No single frame should be used in
8414113fa500 more documentation changes
aaron_watters
parents: 253
diff changeset
    46
        two documents at the same time (especially in the presence of multithreading.
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    47
    '''
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    48
    def __init__(self, x1, y1, width,height, leftPadding=6, bottomPadding=6,
2213
edf7d844279c Added overlapAttachedSpace
rgbecker
parents: 2200
diff changeset
    49
            rightPadding=6, topPadding=6, id=None, showBoundary=0,
edf7d844279c Added overlapAttachedSpace
rgbecker
parents: 2200
diff changeset
    50
            overlapAttachedSpace=None):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    51
        self.id = id
253
cfcf8d555a2c Platypus re-organisation
rgbecker
parents:
diff changeset
    52
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    53
        #these say where it goes on the page
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    54
        self.__dict__['_x1'] = x1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    55
        self.__dict__['_y1'] = y1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    56
        self.__dict__['_width'] = width
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    57
        self.__dict__['_height'] = height
253
cfcf8d555a2c Platypus re-organisation
rgbecker
parents:
diff changeset
    58
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    59
        #these create some padding.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    60
        self.__dict__['_leftPadding'] = leftPadding
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    61
        self.__dict__['_bottomPadding'] = bottomPadding
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    62
        self.__dict__['_rightPadding'] = rightPadding
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    63
        self.__dict__['_topPadding'] = topPadding
253
cfcf8d555a2c Platypus re-organisation
rgbecker
parents:
diff changeset
    64
1923
e692491f0967 Added relative indentation
andy_robinson
parents: 1838
diff changeset
    65
        # these two should NOT be set on a frame.
e692491f0967 Added relative indentation
andy_robinson
parents: 1838
diff changeset
    66
        # they are used when Indenter flowables want
e692491f0967 Added relative indentation
andy_robinson
parents: 1838
diff changeset
    67
        # to adjust edges e.g. to do nested lists
e692491f0967 Added relative indentation
andy_robinson
parents: 1838
diff changeset
    68
        self._leftExtraIndent = 0.0
e692491f0967 Added relative indentation
andy_robinson
parents: 1838
diff changeset
    69
        self._rightExtraIndent = 0.0
2200
be0cfccc662a Fixed up tabs and whitespace in all source files
andy_robinson
parents: 2013
diff changeset
    70
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    71
        # if we want a boundary to be shown
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    72
        self.showBoundary = showBoundary
253
cfcf8d555a2c Platypus re-organisation
rgbecker
parents:
diff changeset
    73
2213
edf7d844279c Added overlapAttachedSpace
rgbecker
parents: 2200
diff changeset
    74
        if overlapAttachedSpace is None: overlapAttachedSpace = rl_config.overlapAttachedSpace
edf7d844279c Added overlapAttachedSpace
rgbecker
parents: 2200
diff changeset
    75
        self._oASpace = overlapAttachedSpace
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    76
        self._geom()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    77
        self._reset()
253
cfcf8d555a2c Platypus re-organisation
rgbecker
parents:
diff changeset
    78
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    79
    def __getattr__(self,a):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    80
        if a in _geomAttr: return self.__dict__['_'+a]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    81
        raise AttributeError, a
410
b5c0992c9b99 geometry changing attributes now work
rgbecker
parents: 332
diff changeset
    82
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    83
    def __setattr__(self,a,v):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    84
        if a in _geomAttr:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    85
            self.__dict__['_'+a] = v
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    86
            self._geom()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    87
        else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    88
            self.__dict__[a] = v
410
b5c0992c9b99 geometry changing attributes now work
rgbecker
parents: 332
diff changeset
    89
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    90
    def _geom(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    91
        self._x2 = self._x1 + self._width
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    92
        self._y2 = self._y1 + self._height
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    93
        #efficiency
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    94
        self._y1p = self._y1 + self._bottomPadding
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    95
        #work out the available space
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    96
        self._aW = self._x2 - self._x1 - self._leftPadding - self._rightPadding
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    97
        self._aH = self._y2 - self._y1p - self._topPadding
410
b5c0992c9b99 geometry changing attributes now work
rgbecker
parents: 332
diff changeset
    98
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
    99
    def _reset(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   100
        #drawing starts at top left
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   101
        self._x = self._x1 + self._leftPadding
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   102
        self._y = self._y2 - self._topPadding
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   103
        self._atTop = 1
2213
edf7d844279c Added overlapAttachedSpace
rgbecker
parents: 2200
diff changeset
   104
        self._prevASpace = 0
253
cfcf8d555a2c Platypus re-organisation
rgbecker
parents:
diff changeset
   105
1923
e692491f0967 Added relative indentation
andy_robinson
parents: 1838
diff changeset
   106
    def _getAvailableWidth(self):
e692491f0967 Added relative indentation
andy_robinson
parents: 1838
diff changeset
   107
        return self._aW - self._leftExtraIndent - self._rightExtraIndent
2200
be0cfccc662a Fixed up tabs and whitespace in all source files
andy_robinson
parents: 2013
diff changeset
   108
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   109
    def _add(self, flowable, canv, trySplit=0):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   110
        """ Draws the flowable at the current position.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   111
        Returns 1 if successful, 0 if it would not fit.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   112
        Raises a LayoutError if the object is too wide,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   113
        or if it is too high for a totally empty frame,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   114
        to avoid infinite loops"""
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   115
        y = self._y
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   116
        p = self._y1p
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   117
        s = 0
2213
edf7d844279c Added overlapAttachedSpace
rgbecker
parents: 2200
diff changeset
   118
        if not self._atTop:
edf7d844279c Added overlapAttachedSpace
rgbecker
parents: 2200
diff changeset
   119
            s =flowable.getSpaceBefore()
edf7d844279c Added overlapAttachedSpace
rgbecker
parents: 2200
diff changeset
   120
            if self._oASpace:
edf7d844279c Added overlapAttachedSpace
rgbecker
parents: 2200
diff changeset
   121
                h = self._prevASpace
edf7d844279c Added overlapAttachedSpace
rgbecker
parents: 2200
diff changeset
   122
                if h>s: s = 0
edf7d844279c Added overlapAttachedSpace
rgbecker
parents: 2200
diff changeset
   123
                else: s = s - h
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   124
        h = y - p - s
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   125
        if h>0:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   126
            flowable.canv = canv #so they can use stringWidth etc
1923
e692491f0967 Added relative indentation
andy_robinson
parents: 1838
diff changeset
   127
            w, h = flowable.wrap(self._getAvailableWidth(), h)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   128
            del flowable.canv
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   129
        else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   130
            return 0
253
cfcf8d555a2c Platypus re-organisation
rgbecker
parents:
diff changeset
   131
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   132
        h = h + s
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   133
        y = y - h
253
cfcf8d555a2c Platypus re-organisation
rgbecker
parents:
diff changeset
   134
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   135
        if y < p-_FUZZ:
2013
6899a4177d08 I think we actually need a width check
rgbecker
parents: 1923
diff changeset
   136
            if not rl_config.allowTableBoundsErrors and ((h>self._aH or w>self._aW) and not trySplit):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   137
                raise "LayoutError", "Flowable %s (%sx%s points) too large for frame (%sx%s points)." % (
1923
e692491f0967 Added relative indentation
andy_robinson
parents: 1838
diff changeset
   138
                    flowable.__class__, w,h, self._getAvailableWidth(),self._aH)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   139
            return 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   140
        else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   141
            #now we can draw it, and update the current point.
1923
e692491f0967 Added relative indentation
andy_robinson
parents: 1838
diff changeset
   142
            flowable.drawOn(canv, self._x + self._leftExtraIndent, y, _sW=self._getAvailableWidth()-w)
2213
edf7d844279c Added overlapAttachedSpace
rgbecker
parents: 2200
diff changeset
   143
            s = flowable.getSpaceAfter()
edf7d844279c Added overlapAttachedSpace
rgbecker
parents: 2200
diff changeset
   144
            y = y - s
edf7d844279c Added overlapAttachedSpace
rgbecker
parents: 2200
diff changeset
   145
            if self._oASpace: self._prevASpace = s
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   146
            if y<>self._y: self._atTop = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   147
            self._y = y
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   148
            return 1
253
cfcf8d555a2c Platypus re-organisation
rgbecker
parents:
diff changeset
   149
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   150
    add = _add
253
cfcf8d555a2c Platypus re-organisation
rgbecker
parents:
diff changeset
   151
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   152
    def split(self,flowable,canv):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   153
        '''Ask the flowable to split using up the available space.'''
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   154
        y = self._y
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   155
        p = self._y1p
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   156
        s = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   157
        if not self._atTop: s = flowable.getSpaceBefore()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   158
        flowable.canv = canv    #some flowables might need this
2200
be0cfccc662a Fixed up tabs and whitespace in all source files
andy_robinson
parents: 2013
diff changeset
   159
1838
f7eeee67832c Changes to allow invariant documents when needed
andy_robinson
parents: 1683
diff changeset
   160
        #print 'asked table to split.  _aW = %0.2f, y-p-s=%0.2f' % (self._aW, y-p-s)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   161
        r = flowable.split(self._aW, y-p-s)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   162
        del flowable.canv
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   163
        return r
253
cfcf8d555a2c Platypus re-organisation
rgbecker
parents:
diff changeset
   164
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   165
    def drawBoundary(self,canv):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   166
        "draw the frame boundary as a rectangle (primarily for debugging)."
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   167
        from reportlab.lib.colors import Color, CMYKColor, toColor
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   168
        sb = self.showBoundary
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   169
        isColor = type(sb) in (type(''),type(()),type([])) or isinstance(sb,Color)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   170
        if isColor:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   171
            sb = toColor(sb,self)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   172
            if sb is self: isColor = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   173
            else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   174
                canv.saveState()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   175
                canv.setStrokeColor(sb)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   176
        canv.rect(
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   177
                self._x1,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   178
                self._y1,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   179
                self._x2 - self._x1,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   180
                self._y2 - self._y1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   181
                )
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   182
        if isColor: canv.restoreState()
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   183
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   184
    def addFromList(self, drawlist, canv):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   185
        """Consumes objects from the front of the list until the
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   186
        frame is full.  If it cannot fit one object, raises
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   187
        an exception."""
253
cfcf8d555a2c Platypus re-organisation
rgbecker
parents:
diff changeset
   188
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   189
        if self.showBoundary:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   190
            self.drawBoundary(canv)
253
cfcf8d555a2c Platypus re-organisation
rgbecker
parents:
diff changeset
   191
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   192
        while len(drawlist) > 0:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   193
            head = drawlist[0]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   194
            if self.add(head,canv,trySplit=0):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   195
                del drawlist[0]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   196
            else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1652
diff changeset
   197
                #leave it in the list for later
2013
6899a4177d08 I think we actually need a width check
rgbecker
parents: 1923
diff changeset
   198
                break