reportlab/platypus/figures.py
author rgbecker
Wed, 10 Dec 2003 18:37:40 +0000
changeset 2175 8570f75b54d7
parent 2170 65b8a82d0e3a
child 2188 0a4449882a3a
permissions -rw-r--r--
I can only get gensampler to work with these changes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1420
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
     1
#copyright ReportLab Inc. 2000
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
     2
#see license.txt for license details
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
     3
#history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/docs/tools/platdemos.py?cvsroot=reportlab
2175
8570f75b54d7 I can only get gensampler to work with these changes
rgbecker
parents: 2170
diff changeset
     4
#$Header: /tmp/reportlab/reportlab/platypus/figures.py,v 1.13 2003/12/10 18:37:40 rgbecker Exp $
1420
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
     5
"""This includes some demos of platypus for use in the API proposal"""
2175
8570f75b54d7 I can only get gensampler to work with these changes
rgbecker
parents: 2170
diff changeset
     6
__version__=''' $Id: figures.py,v 1.13 2003/12/10 18:37:40 rgbecker Exp $ '''
2157
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
     7
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
     8
import os
1420
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
     9
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
    10
from reportlab.lib import colors
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
    11
from reportlab.pdfgen.canvas import Canvas
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
    12
from reportlab.lib.styles import ParagraphStyle
2157
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
    13
from reportlab.lib.utils import recursiveImport
1420
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
    14
from reportlab.platypus import Frame
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
    15
from reportlab.platypus import Flowable
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
    16
from reportlab.platypus import Paragraph
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
    17
from reportlab.lib.units import inch
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
    18
from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER
2162
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
    19
from reportlab.lib.validators import isColor
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
    20
from reportlab.lib.colors import toColor
1420
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
    21
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
    22
captionStyle = ParagraphStyle('Caption', fontName='Times-Italic', fontSize=10, alignment=TA_CENTER)
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
    23
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
    24
class Figure(Flowable):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    25
    def __init__(self, width, height, caption="",
2162
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
    26
                 captionFont="Times-Italic", captionSize=12, background=None):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    27
        Flowable.__init__(self)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    28
        self.width = width
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    29
        self.figureHeight = height
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    30
        self.captionHeight = 0  # work out later
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    31
        self.caption = caption
2162
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
    32
        self.background = background
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    33
        self.captionStyle = ParagraphStyle(
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    34
            'Caption',
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    35
            fontName=captionFont,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    36
            fontSize=captionSize,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    37
            leading=1.2*captionSize,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    38
            spaceBefore=captionSize * 0.5,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    39
            alignment=TA_CENTER)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    40
        #must build paragraph now to get sequencing in synch
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    41
        #with rest of story
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    42
        self.captionPara = Paragraph(self.caption, self.captionStyle)
1420
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
    43
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    44
        self.spaceBefore = 12
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    45
        self.spaceAfter = 12
1420
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
    46
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    47
    def wrap(self, availWidth, availHeight):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    48
        # try to get the caption aligned
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    49
        (w, h) = self.captionPara.wrap(self.width, availHeight - self.figureHeight)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    50
        self.captionHeight = h
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    51
        self.height = self.captionHeight + self.figureHeight
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    52
        self.dx = 0.5 * (availWidth - self.width)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    53
        return (self.width, self.height)
1420
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
    54
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    55
    def draw(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    56
        self.canv.translate(self.dx, 0)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    57
        self.drawCaption()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    58
        self.canv.translate(0, self.captionHeight)
2162
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
    59
        if self.background:
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
    60
            self.drawBackground()
2164
55b8821c053b Previous change caused unforseen problems with borders, so we're
johnprecedo
parents: 2163
diff changeset
    61
        self.drawBorder()
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    62
        self.drawFigure()
1420
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
    63
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    64
    def drawBorder(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    65
        self.canv.rect(0, 0, self.width, self.figureHeight)
1420
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
    66
2162
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
    67
    def _doBackground(self, color):
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
    68
        self.canv.saveState()
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
    69
        self.canv.setFillColor(self.background)
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
    70
        self.canv.rect(0, 0, self.width, self.figureHeight, fill=1)
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
    71
        self.canv.restoreState()
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
    72
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
    73
    def drawBackground(self):
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
    74
        """For use when using a figure on a differently coloured background.
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
    75
        Allows you to specify a colour to be used as a background for the figure."""
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
    76
        if isColor(self.background):
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
    77
            self._doBackground(self.background)
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
    78
        else:
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
    79
            try:
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
    80
                c = toColor(self.background)
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
    81
                self._doBackground(c)
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
    82
            except:
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
    83
                pass
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
    84
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    85
    def drawCaption(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    86
        self.captionPara.drawOn(self.canv, 0, 0)
1420
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
    87
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    88
    def drawFigure(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    89
        pass
1420
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
    90
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
    91
def drawPage(canvas,x, y, width, height):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    92
    #draws something which looks like a page
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    93
    pth = canvas.beginPath()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    94
    corner = 0.05*width
1420
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
    95
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    96
    # shaded backdrop offset a little
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    97
    canvas.setFillColorRGB(0.5,0.5,0.5)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
    98
    canvas.rect(x + corner, y - corner, width, height, stroke=0, fill=1)
1420
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
    99
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   100
    #'sheet of paper' in light yellow
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   101
    canvas.setFillColorRGB(1,1,0.9)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   102
    canvas.setLineWidth(0)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   103
    canvas.rect(x, y, width, height, stroke=1, fill=1)
1420
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
   104
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   105
    #reset
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   106
    canvas.setFillColorRGB(0,0,0)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   107
    canvas.setStrokeColorRGB(0,0,0)
1420
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
   108
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
   109
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
   110
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
   111
class PageFigure(Figure):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   112
    """Shows a blank page in a frame, and draws on that.  Used in
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   113
    illustrations of how PLATYPUS works."""
2162
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
   114
    def __init__(self, background=None):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   115
        Figure.__init__(self, 3*inch, 3*inch)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   116
        self.caption = 'Figure 1 - a blank page'
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   117
        self.captionStyle = captionStyle
2162
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
   118
        self.background = background
1420
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
   119
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   120
    def drawVirtualPage(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   121
        pass
1420
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
   122
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   123
    def drawFigure(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   124
        drawPage(self.canv, 0.625*inch, 0.25*inch, 1.75*inch, 2.5*inch)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   125
        self.canv.translate(0.625*inch, 0.25*inch)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   126
        self.canv.scale(1.75/8.27, 2.5/11.69)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   127
        self.drawVirtualPage()
1420
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
   128
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
   129
class PlatPropFigure1(PageFigure):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   130
    """This shows a page with a frame on it"""
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   131
    def __init__(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   132
        PageFigure.__init__(self)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   133
        self.caption = "Figure 1 - a page with a simple frame"
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   134
    def drawVirtualPage(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   135
        demo1(self.canv)
1420
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
   136
2157
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   137
class FlexFigure(Figure):
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   138
    """Base for a figure class with a caption. Can grow or shrink in proportion"""
2162
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
   139
    def __init__(self, width, height, caption, background=None):
2157
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   140
        Figure.__init__(self, width, height, caption,
2162
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
   141
                        captionFont="Helvetica-Oblique", captionSize=8,
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
   142
                        background=None)
2157
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   143
        self.shrinkToFit = 1 #if set and wrap is too tight, shrinks
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   144
        self.growToFit = 1 #if set and wrap is too tight, shrinks
2175
8570f75b54d7 I can only get gensampler to work with these changes
rgbecker
parents: 2170
diff changeset
   145
        self.scaleFactor = None
2157
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   146
        self.captionStyle = ParagraphStyle(
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   147
            'Caption',
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   148
            fontName='Times', #'Helvetica-Oblique',
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   149
            fontSize=4, #8, 
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   150
            spaceBefore=9, #3,
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   151
            alignment=TA_CENTER
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   152
            )
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   153
        self._scaledWidth = None
2162
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
   154
        self.background = background
2157
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   155
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   156
    def wrap(self, availWidth, availHeight):
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   157
        "Rescale to fit according to the rules, but only once"
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   158
        if self._scaledWidth <> availWidth:
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   159
            self._scaledWidth = availWidth
2175
8570f75b54d7 I can only get gensampler to work with these changes
rgbecker
parents: 2170
diff changeset
   160
            #scale factor None means auto
2167
4ddf1ef71640 New pagecatcher and drawing tags (experimental)
andy_robinson
parents: 2164
diff changeset
   161
            if self.scaleFactor is None:
4ddf1ef71640 New pagecatcher and drawing tags (experimental)
andy_robinson
parents: 2164
diff changeset
   162
                self._scaleFactor = availWidth / self.width
4ddf1ef71640 New pagecatcher and drawing tags (experimental)
andy_robinson
parents: 2164
diff changeset
   163
            else: #they provided a factor
4ddf1ef71640 New pagecatcher and drawing tags (experimental)
andy_robinson
parents: 2164
diff changeset
   164
                self._scaleFactor = self.scaleFactor
4ddf1ef71640 New pagecatcher and drawing tags (experimental)
andy_robinson
parents: 2164
diff changeset
   165
            if self._scaleFactor < 1 and self.shrinkToFit:
2175
8570f75b54d7 I can only get gensampler to work with these changes
rgbecker
parents: 2170
diff changeset
   166
                self.width = self.width * self._scaleFactor - 0.0001
2167
4ddf1ef71640 New pagecatcher and drawing tags (experimental)
andy_robinson
parents: 2164
diff changeset
   167
                self.figureHeight = self.figureHeight * self._scaleFactor
4ddf1ef71640 New pagecatcher and drawing tags (experimental)
andy_robinson
parents: 2164
diff changeset
   168
            elif self._scaleFactor > 1 and self.growToFit:
2175
8570f75b54d7 I can only get gensampler to work with these changes
rgbecker
parents: 2170
diff changeset
   169
                self.width = self.width * self._scaleFactor - 0.0001
2167
4ddf1ef71640 New pagecatcher and drawing tags (experimental)
andy_robinson
parents: 2164
diff changeset
   170
                self.figureHeight = self.figureHeight * self._scaleFactor
2157
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   171
        return Figure.wrap(self, availWidth, availHeight)
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   172
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   173
class ImageFigure(FlexFigure):
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   174
    """Image with a caption below it"""
2162
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
   175
    def __init__(self, filename, caption, background=None):
2157
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   176
        assert os.path.isfile(filename), 'image file %s not found' % filename
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   177
        from reportlab.lib.utils import ImageReader
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   178
        w, h = ImageReader(filename).getSize()
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   179
        self.filename = filename
2162
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
   180
        FlexFigure.__init__(self, w, h, caption, background)
2157
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   181
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   182
    def drawFigure(self):
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   183
        self.canv.drawInlineImage(self.filename,
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   184
                                  0, 0,self.width, self.figureHeight)
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   185
        
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   186
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   187
class DrawingFigure(FlexFigure):
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   188
    """Drawing with a caption below it.  Clunky, scaling fails."""
2162
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
   189
    def __init__(self, modulename, classname, caption, baseDir=None, background=None):
2157
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   190
        module = recursiveImport(modulename, baseDir)
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   191
        klass = getattr(module, classname)
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   192
        self.drawing = klass()
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   193
        FlexFigure.__init__(self,
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   194
                            self.drawing.width,
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   195
                            self.drawing.height,
2162
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
   196
                            caption,
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
   197
                            background)
2157
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   198
        self.growToFit = 1
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   199
        
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   200
    def drawFigure(self):
2175
8570f75b54d7 I can only get gensampler to work with these changes
rgbecker
parents: 2170
diff changeset
   201
        self.canv.scale(self._scaleFactor, self._scaleFactor)
2157
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   202
        self.drawing.drawOn(self.canv, 0, 0)
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   203
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   204
2158
e9c34b93e317 Whoops, platform specific slashes.
andy_robinson
parents: 2157
diff changeset
   205
    ####################################################################
e9c34b93e317 Whoops, platform specific slashes.
andy_robinson
parents: 2157
diff changeset
   206
    #
e9c34b93e317 Whoops, platform specific slashes.
andy_robinson
parents: 2157
diff changeset
   207
    #    PageCatcher plugins
e9c34b93e317 Whoops, platform specific slashes.
andy_robinson
parents: 2157
diff changeset
   208
    # These let you use our PageCatcher product to add figures
e9c34b93e317 Whoops, platform specific slashes.
andy_robinson
parents: 2157
diff changeset
   209
    # to other documents easily.
e9c34b93e317 Whoops, platform specific slashes.
andy_robinson
parents: 2157
diff changeset
   210
    ####################################################################
e9c34b93e317 Whoops, platform specific slashes.
andy_robinson
parents: 2157
diff changeset
   211
2157
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   212
try:
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   213
    from rlextra.pageCatcher.pageCatcher import restoreForms, storeForms
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   214
    _hasPageCatcher = 1
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   215
except ImportError:
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   216
    _hasPageCatcher = 0
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   217
if _hasPageCatcher:
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   218
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   219
    class PageCatcherCachingMixIn:
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   220
        "Helper functions to cache pages for figures"
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   221
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   222
        def getFormName(self, pdfFileName, pageNo):
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   223
            #naming scheme works within a directory
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   224
            #only
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   225
            dirname, filename = os.path.split(pdfFileName)
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   226
            root, ext = os.path.splitext(filename)
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   227
            return '%s_page%d' % (root, pageNo)
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   228
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   229
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   230
        def needsProcessing(self, pdfFileName, pageNo):
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   231
            "returns 1 if no forms or form is older"
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   232
            formName = self.getFormName(pdfFileName, pageNo)
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   233
            if os.path.exists(formName + '.frm'):
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   234
                formModTime = os.stat(formName + '.frm')[8]
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   235
                pdfModTime = os.stat(pdfFileName)[8]
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   236
                return (pdfModTime > formModTime)
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   237
            else:
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   238
                return 1
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   239
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   240
        def processPDF(self, pdfFileName, pageNo):
2159
c3bef6ff4917 Bug in one figure
andy_robinson
parents: 2158
diff changeset
   241
            formName = self.getFormName(pdfFileName, pageNo)
2157
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   242
            storeForms(pdfFileName, formName + '.frm',
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   243
                                    prefix= formName + '_',
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   244
                                    pagenumbers=[pageNo])
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   245
            print 'stored %s.frm' % formName
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   246
            return formName + '.frm'
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   247
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   248
        
2167
4ddf1ef71640 New pagecatcher and drawing tags (experimental)
andy_robinson
parents: 2164
diff changeset
   249
    class PageCatcherFigure(FlexFigure, PageCatcherCachingMixIn):
2157
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   250
        """PageCatcher page with a caption below it.  Presumes A4, Portrait.
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   251
        This needs our commercial PageCatcher product, or you'll get a blank."""
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   252
2162
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
   253
        def __init__(self, filename, pageNo, caption, width=595, height=842, background=None):
2157
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   254
            self.dirname, self.filename = os.path.split(filename)
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   255
            if self.dirname == '':
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   256
                self.dirname = os.curdir
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   257
            self.pageNo = pageNo
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   258
            self.formName = self.getFormName(self.filename, self.pageNo) + '_' + str(pageNo)
2162
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
   259
            FlexFigure.__init__(self, width, height, caption, background)
2157
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   260
            #print 'self.width=%0.2f, self.figureHeight=%0.2f' % (self.width, self.figureHeight)
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   261
            
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   262
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   263
        def drawFigure(self):
2170
65b8a82d0e3a Pythonpoint fixups
andy_robinson
parents: 2167
diff changeset
   264
            #print 'drawing ',self.formName
65b8a82d0e3a Pythonpoint fixups
andy_robinson
parents: 2167
diff changeset
   265
            #print 'self.width=%0.2f, self.figureHeight=%0.2f' % (self.width, self.figureHeight)
2157
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   266
            self.canv.saveState()
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   267
            if not self.canv.hasForm(self.formName):
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   268
                restorePath = self.dirname + os.sep + self.filename
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   269
                #does the form file exist?  if not, generate it.
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   270
                formFileName = self.getFormName(restorePath, self.pageNo) + '.frm'
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   271
                if self.needsProcessing(restorePath, self.pageNo):
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   272
                    print 'preprocessing PDF %s page %s' % (restorePath, self.pageNo)
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   273
                    self.processPDF(restorePath, self.pageNo)
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   274
                names = restoreForms(formFileName, self.canv)
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   275
                #print 'restored',names
2167
4ddf1ef71640 New pagecatcher and drawing tags (experimental)
andy_robinson
parents: 2164
diff changeset
   276
            self.canv.scale(self._scaleFactor, self._scaleFactor)
2157
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   277
            #print 'doing form',self.formName
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   278
            self.canv.doForm(self.formName)
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   279
            self.canv.restoreState()
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   280
2167
4ddf1ef71640 New pagecatcher and drawing tags (experimental)
andy_robinson
parents: 2164
diff changeset
   281
    class PageCatcherFigureNonA4(FlexFigure, PageCatcherCachingMixIn):
2157
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   282
        """PageCatcher page with a caption below it.  Size to be supplied."""
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   283
        # This should merge with PageFigure into one class that reuses
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   284
        # form information to determine the page orientation...
2162
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
   285
        def __init__(self, filename, pageNo, caption, width, height, background=None):
2157
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   286
            self.dirname, self.filename = os.path.split(filename)
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   287
            if self.dirname == '':
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   288
                self.dirname = os.curdir
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   289
            self.pageNo = pageNo
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   290
            self.formName = self.getFormName(self.filename, self.pageNo) + '_' + str(pageNo)
2162
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
   291
            FlexFigure.__init__(self, width, height, caption, background)
bdd60afa3e48 Added a background attribute (default None) to most figures - if it's a
johnprecedo
parents: 2159
diff changeset
   292
2157
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   293
        def drawFigure(self):
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   294
            self.canv.saveState()
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   295
            if not self.canv.hasForm(self.formName):
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   296
                restorePath = self.dirname + os.sep + self.filename
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   297
                #does the form file exist?  if not, generate it.
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   298
                formFileName = self.getFormName(restorePath, self.pageNo) + '.frm'
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   299
                if self.needsProcessing(restorePath, self.pageNo):
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   300
                    print 'preprocessing PDF %s page %s' % (restorePath, self.pageNo)
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   301
                    self.processPDF(restorePath, self.pageNo)
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   302
                names = restoreForms(formFileName, self.canv)
2175
8570f75b54d7 I can only get gensampler to work with these changes
rgbecker
parents: 2170
diff changeset
   303
            self.canv.scale(self._scaleFactor, self._scaleFactor)
2157
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   304
            self.canv.doForm(self.formName)
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   305
            self.canv.restoreState()
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   306
cc8354f2171e Added figure classes, made XML editable in XML-SPY
andy_robinson
parents: 1683
diff changeset
   307
1420
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
   308
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
   309
def demo1(canvas):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   310
    frame = Frame(
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   311
                    2*inch,     # x
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   312
                    4*inch,     # y at bottom
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   313
                    4*inch,     # width
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   314
                    5*inch,     # height
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   315
                    showBoundary = 1  # helps us see what's going on
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   316
                    )
1420
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
   317
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   318
    bodyStyle = ParagraphStyle('Body', fontName='Times-Roman', fontSize=24, leading=28, spaceBefore=6)
1420
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
   319
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   320
    para1 = Paragraph('Spam spam spam spam. ' * 5, bodyStyle)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   321
    para2 = Paragraph('Eggs eggs eggs. ' * 5, bodyStyle)
1420
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
   322
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   323
    mydata = [para1, para2]
1420
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
   324
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   325
    #this does the packing and drawing.  The frame will consume
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   326
    #items from the front of the list as it prints them
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   327
    frame.addFromList(mydata,canvas)
1420
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
   328
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
   329
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
   330
def test1():
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   331
    c  = Canvas('figures.pdf')
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   332
    f = Frame(inch, inch, 6*inch, 9*inch, showBoundary=1)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   333
    v = PlatPropFigure1()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   334
    f.addFromList([v],c)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1559
diff changeset
   335
    c.save()
1420
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
   336
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
   337
bd1f0adf63d3 Initial checkin, copy of tools/docco/platdemos.py.
dinu_gherman
parents:
diff changeset
   338
if __name__ == '__main__':
2175
8570f75b54d7 I can only get gensampler to work with these changes
rgbecker
parents: 2170
diff changeset
   339
    test1()