reportlab/demos/pythonpoint/pythonpoint.py
author rgbecker
Wed, 25 Oct 2000 08:57:46 +0000
changeset 494 54257447cfe9
parent 393 61966cddbe13
child 500 58d712fef651
permissions -rw-r--r--
Changed to indirect copyright
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
494
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 393
diff changeset
     1
#copyright ReportLab Inc. 2000
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 393
diff changeset
     2
#see license.txt for license details
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 393
diff changeset
     3
#history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/demos/pythonpoint/pythonpoint.py?cvsroot=reportlab
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 393
diff changeset
     4
#$Header: /tmp/reportlab/reportlab/demos/pythonpoint/Attic/pythonpoint.py,v 1.26 2000/10/25 08:57:44 rgbecker Exp $
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 393
diff changeset
     5
__version__=''' $Id: pythonpoint.py,v 1.26 2000/10/25 08:57:44 rgbecker Exp $ '''
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
     6
# xml parser stuff for PythonPoint
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
     7
# PythonPoint Markup Language!
16
f9c7525619fb Docstring & other fixes
rgbecker
parents: 10
diff changeset
     8
__doc__="""
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
     9
This is PythonPoint!
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    10
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    11
The idea is a simple markup languages for describing
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    12
presentation slides, and other documents which run
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    13
page by page.  I expect most of it will be reusable
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    14
in other page layout stuff.
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    15
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    16
Look at the sample near the top, which shows how the presentation
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    17
should be coded up.
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    18
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
    19
The parser, which is in a separate module to allow for multiple
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
    20
parsers, turns the XML sample into an object tree.  There is a
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    21
simple class hierarchy of items, the inner levels of which create
122
fd68411f49db Drawable ==> Flowable
rgbecker
parents: 98
diff changeset
    22
flowable objects to go in the frames.  These know how to draw
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
    23
themselves.
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
    24
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
    25
The currently available 'Presentation Objects' are:
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
    26
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
    27
    The main hierarchy...
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
    28
        PPPresentation
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
    29
        PPSection
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
    30
        PPSlide
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
    31
        PPFrame
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
    32
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
    33
    Things to flow within frames...
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
    34
        PPPara - flowing text
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
    35
        PPPreformatted - text with line breaks and tabs, for code..
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
    36
        PPImage
342
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
    37
        PPTable - bulk formatted tabular data
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
    38
        PPSpacer
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
    39
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
    40
    Things to draw directly on the page...
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
    41
        PPRect
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
    42
        PPRoundRect
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
    43
        PPDrawingElement - user base class for graphics
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
    44
        PPLine
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
    45
        PPEllipse
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    46
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    47
"""
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    48
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    49
import os
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    50
import string
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    51
import pprint
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    52
import imp
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    53
10
0cb88428a663 Conversion to reportlab package
rgbecker
parents: 7
diff changeset
    54
from reportlab.pdfgen import canvas
342
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
    55
from reportlab.platypus import Preformatted, Paragraph, Frame, Image, \
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
    56
     Table, TableStyle, Spacer
129
623baa767856 Splitting layout.py
rgbecker
parents: 122
diff changeset
    57
from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY
623baa767856 Splitting layout.py
rgbecker
parents: 122
diff changeset
    58
from reportlab.lib import styles
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
    59
import stdparser 
253
cfcf8d555a2c Platypus re-organisation
rgbecker
parents: 240
diff changeset
    60
from reportlab.lib.pagesizes import DEFAULT_PAGE_SIZE
342
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
    61
from reportlab.lib import colors
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    62
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    63
class PPPresentation:
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    64
    def __init__(self):
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    65
        self.filename = None
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    66
        self.description = None
353
c24bbfd09f1c Added Speaker Notes facility
andy_robinson
parents: 342
diff changeset
    67
        self.speakerNotes = 0   # different printing mode
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    68
        self.slides = []
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    69
        self.effectName = None
180
f92b4f73b1b5 Changed to display multiple outline levels
andy_robinson
parents: 163
diff changeset
    70
        self.showOutline = 1   #should it be displayed when opening?
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    71
        
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    72
        #assume landscape        
253
cfcf8d555a2c Platypus re-organisation
rgbecker
parents: 240
diff changeset
    73
        self.pageWidth = DEFAULT_PAGE_SIZE[1]  
cfcf8d555a2c Platypus re-organisation
rgbecker
parents: 240
diff changeset
    74
        self.pageHeight = DEFAULT_PAGE_SIZE[0]  
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    75
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    76
    def save(self):
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    77
        """This writes out the PDF document"""
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    78
        canv = canvas.Canvas(self.filename,
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    79
                                pagesize = (self.pageWidth, self.pageHeight)
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    80
                               )
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    81
        canv.setPageCompression(0)
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    82
            
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    83
        for slide in self.slides:
353
c24bbfd09f1c Added Speaker Notes facility
andy_robinson
parents: 342
diff changeset
    84
c24bbfd09f1c Added Speaker Notes facility
andy_robinson
parents: 342
diff changeset
    85
            
c24bbfd09f1c Added Speaker Notes facility
andy_robinson
parents: 342
diff changeset
    86
            if self.speakerNotes:
c24bbfd09f1c Added Speaker Notes facility
andy_robinson
parents: 342
diff changeset
    87
                #frame and shift the slide
c24bbfd09f1c Added Speaker Notes facility
andy_robinson
parents: 342
diff changeset
    88
                canv.scale(0.67, 0.67)
c24bbfd09f1c Added Speaker Notes facility
andy_robinson
parents: 342
diff changeset
    89
                canv.translate(self.pageWidth / 6.0, self.pageHeight / 3.0)
c24bbfd09f1c Added Speaker Notes facility
andy_robinson
parents: 342
diff changeset
    90
                canv.rect(0,0,self.pageWidth, self.pageHeight)
c24bbfd09f1c Added Speaker Notes facility
andy_robinson
parents: 342
diff changeset
    91
c24bbfd09f1c Added Speaker Notes facility
andy_robinson
parents: 342
diff changeset
    92
c24bbfd09f1c Added Speaker Notes facility
andy_robinson
parents: 342
diff changeset
    93
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    94
            slide.drawOn(canv)
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
    95
            canv.showPage()
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
    96
180
f92b4f73b1b5 Changed to display multiple outline levels
andy_robinson
parents: 163
diff changeset
    97
        #ensure outline visible by default
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
    98
        if self.showOutline:
233
8ab418168999 Bring in line with canvas changes
rgbecker
parents: 227
diff changeset
    99
            canv.showOutline()
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   100
        canv.save()        
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   101
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   102
class PPSection:
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   103
    """A section can hold graphics which will be drawn on all
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   104
    pages within it, before frames and other content are done.
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   105
    In other words, a background template."""
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   106
    def __init__(self, name):
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   107
        self.name = name
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   108
        self.graphics = []
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   109
        
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   110
    def drawOn(self, canv):
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   111
        for graphic in self.graphics:
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   112
            graphic.drawOn(canv)
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   113
            
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   114
        
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   115
class PPSlide:
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   116
    def __init__(self):
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   117
        self.id = None
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   118
        self.title = None
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   119
        self.outlineEntry = None
180
f92b4f73b1b5 Changed to display multiple outline levels
andy_robinson
parents: 163
diff changeset
   120
        self.outlineLevel = 0   # can be higher for sub-headings
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   121
        self.effectName = None
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   122
        self.effectDirection = 0
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   123
        self.effectDimension = 'H'
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   124
        self.effectMotion = 'I'
393
61966cddbe13 Minor additions to styles etc.
andy_robinson
parents: 356
diff changeset
   125
        self.effectDuration = 1
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   126
        self.frames = []
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   127
        self.graphics = []
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   128
        self.section = None
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   129
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   130
    def drawOn(self, canv):
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   131
        if self.effectName:
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   132
            canv.setPageTransition(
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   133
                        effectname=self.effectName,
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   134
                        direction = self.effectDirection,
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   135
                        dimension = self.effectDimension,
393
61966cddbe13 Minor additions to styles etc.
andy_robinson
parents: 356
diff changeset
   136
                        motion = self.effectMotion,
61966cddbe13 Minor additions to styles etc.
andy_robinson
parents: 356
diff changeset
   137
                        duration = self.effectDuration
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   138
                        )
180
f92b4f73b1b5 Changed to display multiple outline levels
andy_robinson
parents: 163
diff changeset
   139
        if self.outlineEntry:
f92b4f73b1b5 Changed to display multiple outline levels
andy_robinson
parents: 163
diff changeset
   140
            #gets an outline automatically
f92b4f73b1b5 Changed to display multiple outline levels
andy_robinson
parents: 163
diff changeset
   141
            self.showOutline = 1
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   142
            #put an outline entry in the left pane
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   143
            tag = self.title
233
8ab418168999 Bring in line with canvas changes
rgbecker
parents: 227
diff changeset
   144
            canv.bookmarkPage(tag)
8ab418168999 Bring in line with canvas changes
rgbecker
parents: 227
diff changeset
   145
            canv.addOutlineEntry(tag, tag, self.outlineLevel)
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   146
            
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   147
            
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   148
        
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   149
        if self.section:
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   150
            self.section.drawOn(canv)
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   151
                
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   152
        canv.drawRightString(800, 36, 'id: %s, title: %s' % (self.id, self.title))
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   153
        for graphic in self.graphics:
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   154
            graphic.drawOn(canv)
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   155
            
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   156
        for frame in self.frames:
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   157
            frame.drawOn(canv)
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   158
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   159
class PPFrame:
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   160
    def __init__(self, x, y, width, height):
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   161
        self.x = x
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   162
        self.y = y
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   163
        self.width = width
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   164
        self.height = height
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   165
        self.content = []
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   166
        self.showBoundary = 0        
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   167
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   168
    def drawOn(self, canv):
253
cfcf8d555a2c Platypus re-organisation
rgbecker
parents: 240
diff changeset
   169
        #make a frame
cfcf8d555a2c Platypus re-organisation
rgbecker
parents: 240
diff changeset
   170
        frame = Frame( self.x,
227
fa5b4d81f471 Renamed BasicFrame to Frame
rgbecker
parents: 226
diff changeset
   171
                              self.y,
fa5b4d81f471 Renamed BasicFrame to Frame
rgbecker
parents: 226
diff changeset
   172
                              self.width,
240
022c939a6d55 Preformatted objects now know how to split themselves.
andy_robinson
parents: 233
diff changeset
   173
                              self.height
022c939a6d55 Preformatted objects now know how to split themselves.
andy_robinson
parents: 233
diff changeset
   174
                              )
022c939a6d55 Preformatted objects now know how to split themselves.
andy_robinson
parents: 233
diff changeset
   175
        frame.showBoundary = self.showBoundary
226
a9acb67cdef7 Removal of SimpleFrame
rgbecker
parents: 222
diff changeset
   176
 
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   177
        #build a story for the frame
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   178
        story = []
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   179
        for thingy in self.content:
122
fd68411f49db Drawable ==> Flowable
rgbecker
parents: 98
diff changeset
   180
            #ask it for any flowables
fd68411f49db Drawable ==> Flowable
rgbecker
parents: 98
diff changeset
   181
            story.append(thingy.getFlowable())
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   182
        #draw it
226
a9acb67cdef7 Removal of SimpleFrame
rgbecker
parents: 222
diff changeset
   183
        frame.addFromList(story,canv)
a9acb67cdef7 Removal of SimpleFrame
rgbecker
parents: 222
diff changeset
   184
 
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   185
class PPPara:
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   186
    """This is a placeholder for a paragraph."""
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   187
    def __init__(self):
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   188
        self.rawtext = ''
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   189
        self.style = None
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   190
122
fd68411f49db Drawable ==> Flowable
rgbecker
parents: 98
diff changeset
   191
    def getFlowable(self):
222
f04b9db53afc Allowed intra-paragraph text; fixed various bugs
andy_robinson
parents: 180
diff changeset
   192
        p = Paragraph(
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   193
                    self.rawtext,
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   194
                    getStyles()[self.style],
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   195
                    self.bulletText
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   196
                    )
222
f04b9db53afc Allowed intra-paragraph text; fixed various bugs
andy_robinson
parents: 180
diff changeset
   197
        return p
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   198
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   199
class PPPreformattedText:
222
f04b9db53afc Allowed intra-paragraph text; fixed various bugs
andy_robinson
parents: 180
diff changeset
   200
    """Use this for source code, or stuff you do not want to wrap"""
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   201
    def __init__(self):
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   202
        self.rawtext = ''
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   203
        self.style = None
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   204
122
fd68411f49db Drawable ==> Flowable
rgbecker
parents: 98
diff changeset
   205
    def getFlowable(self):
253
cfcf8d555a2c Platypus re-organisation
rgbecker
parents: 240
diff changeset
   206
        return Preformatted(self.rawtext, getStyles()[self.style])
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   207
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   208
class PPImage:
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   209
    """Flowing image within the text"""
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   210
    def __init__(self):
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   211
        self.filename = None
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   212
        self.width = None
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   213
        self.height = None
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   214
122
fd68411f49db Drawable ==> Flowable
rgbecker
parents: 98
diff changeset
   215
    def getFlowable(self):
253
cfcf8d555a2c Platypus re-organisation
rgbecker
parents: 240
diff changeset
   216
        return Image(self.filename, self.width, self.height)
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   217
342
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   218
class PPTable:
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   219
    """Designed for bulk loading of data for use in presentations."""
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   220
    def __init__(self):
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   221
        self.rawBlocks = [] #parser stuffs things in here...
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   222
        self.fieldDelim = ','  #tag args can override
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   223
        self.rowDelim = '\n'   #tag args can override
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   224
        self.data = None
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   225
        self.style = None  #tag args must specify
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   226
        self.widths = None  #tag args can override
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   227
        self.heights = None #tag args can override
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   228
342
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   229
    def getFlowable(self):
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   230
        self.parseData()
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   231
        t = Table(
356
377367fe28cb Table argument order changed
rgbecker
parents: 353
diff changeset
   232
				self.data,
342
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   233
                self.widths,
356
377367fe28cb Table argument order changed
rgbecker
parents: 353
diff changeset
   234
                self.heights)
342
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   235
        if self.style:
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   236
            t.setStyle(getStyles()[self.style])
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   237
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   238
        return t
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   239
                
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   240
    def parseData(self):
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   241
        """Try to make sense of the table data!"""
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   242
        rawdata = string.strip(string.join(self.rawBlocks, ''))
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   243
        lines = string.split(rawdata, self.rowDelim)
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   244
        #clean up...
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   245
        lines = map(string.strip, lines)
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   246
        self.data = []
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   247
        for line in lines:
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   248
            cells = string.split(line, self.fieldDelim)
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   249
            self.data.append(cells)
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   250
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   251
        #get the width list if not given
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   252
        if not self.widths:
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   253
            self.widths = [None] * len(self.data[0])
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   254
        if not self.heights:
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   255
            self.heights = [None] * len(self.data)
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   256
        
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   257
    
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   258
##        import pprint
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   259
##        print 'table data:'
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   260
##        print 'style=',self.style
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   261
##        print 'widths=',self.widths
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   262
##        print 'heights=',self.heights
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   263
##        print 'fieldDelim=',repr(self.fieldDelim)
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   264
##        print 'rowDelim=',repr(self.rowDelim)
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   265
##        pprint.pprint(self.data)
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   266
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   267
class PPSpacer:
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   268
    def __init__(self):
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   269
        self.height = 24  #points
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   270
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   271
    def getFlowable(self):
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   272
        return Spacer(72, self.height)
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   273
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   274
    #############################################################
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   275
    #
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   276
    #   The following are things you can draw on a page directly.
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   277
    #
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   278
    ##############################################################
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   279
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   280
class PPDrawingElement:
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   281
    """Base class for something which you draw directly on the page."""
222
f04b9db53afc Allowed intra-paragraph text; fixed various bugs
andy_robinson
parents: 180
diff changeset
   282
    def drawOn(self, canv):
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   283
        raise "NotImplementedError", "Abstract base class!"
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   284
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   285
        
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   286
class PPFixedImage(PPDrawingElement):
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   287
    """You place this on the page, rather than flowing it"""
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   288
    def __init__(self):
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   289
        self.filename = None
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   290
        self.x = 0
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   291
        self.y = 0
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   292
        self.width = None
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   293
        self.height = None
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   294
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   295
    def drawOn(self, canv):
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   296
        if self.filename:
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   297
            canv.drawInlineImage(
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   298
                                self.filename,
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   299
                                self.x,
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   300
                                self.y,
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   301
                                self.width,
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   302
                                self.height
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   303
                                   )
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   304
class PPRectangle:
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   305
    def __init__(self, x, y, width, height):
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   306
        self.x = x
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   307
        self.y = y
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   308
        self.width = width
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   309
        self.height = height
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   310
        self.fillColor = None
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   311
        self.strokeColor = (1,1,1)
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   312
        self.lineWidth=0
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   313
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   314
    def drawOn(self, canv):
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   315
        canv.saveState()
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   316
        canv.setLineWidth(self.lineWidth)
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   317
        if self.fillColor:
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   318
            r,g,b = self.fillColor
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   319
            canv.setFillColorRGB(r,g,b)
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   320
        if self.strokeColor:
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   321
            r,g,b = self.strokeColor
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   322
            canv.setStrokeColorRGB(r,g,b)
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   323
        canv.rect(self.x, self.y, self.width, self.height,
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   324
                    stroke=(self.strokeColor<>None),
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   325
                    fill = (self.fillColor<>None)
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   326
                    )
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   327
        canv.restoreState()
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   328
                                   
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   329
class PPRoundRect:
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   330
    def __init__(self, x, y, width, height, radius):
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   331
        self.x = x
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   332
        self.y = y
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   333
        self.width = width
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   334
        self.height = height
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   335
        self.radius = radius
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   336
        self.fillColor = None
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   337
        self.strokeColor = (1,1,1)
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   338
        self.lineWidth=0
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   339
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   340
    def drawOn(self, canv):
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   341
        canv.saveState()
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   342
        canv.setLineWidth(self.lineWidth)
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   343
        if self.fillColor:
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   344
            r,g,b = self.fillColor
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   345
            canv.setFillColorRGB(r,g,b)
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   346
        if self.strokeColor:
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   347
            r,g,b = self.strokeColor
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   348
            canv.setStrokeColorRGB(r,g,b)
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   349
        canv.roundRect(self.x, self.y, self.width, self.height,
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   350
                    self.radius,
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   351
                    stroke=(self.strokeColor<>None),
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   352
                    fill = (self.fillColor<>None)
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   353
                    )
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   354
        canv.restoreState()
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   355
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   356
class PPLine:
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   357
    def __init__(self, x1, y1, x2, y2):
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   358
        self.x1 = x1
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   359
        self.y1 = y1
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   360
        self.x2 = x2
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   361
        self.y2 = y2
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   362
        self.fillColor = None
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   363
        self.strokeColor = (1,1,1)
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   364
        self.lineWidth=0
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   365
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   366
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   367
    def drawOn(self, canv):
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   368
        canv.saveState()
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   369
        canv.setLineWidth(self.lineWidth)
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   370
        if self.strokeColor:
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   371
            r,g,b = self.strokeColor
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   372
            canv.setStrokeColorRGB(r,g,b)
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   373
        canv.line(self.x1, self.y1, self.x2, self.y2)
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   374
        canv.restoreState()
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   375
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   376
class PPEllipse:
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   377
    def __init__(self, x1, y1, x2, y2):
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   378
        self.x1 = x1
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   379
        self.y1 = y1
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   380
        self.x2 = x2
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   381
        self.y2 = y2
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   382
        self.fillColor = None
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   383
        self.strokeColor = (1,1,1)
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   384
        self.lineWidth=0
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   385
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   386
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   387
    def drawOn(self, canv):
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   388
        canv.saveState()
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   389
        canv.setLineWidth(self.lineWidth)
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   390
        if self.strokeColor:
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   391
            r,g,b = self.strokeColor
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   392
            canv.setStrokeColorRGB(r,g,b)
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   393
        if self.fillColor:
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   394
            r,g,b = self.fillColor
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   395
            canv.setFillColorRGB(r,g,b)
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   396
        canv.ellipse(self.x1, self.y1, self.x2, self.y2,
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   397
                    stroke=(self.strokeColor<>None),
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   398
                    fill = (self.fillColor<>None)
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   399
                     )
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   400
        canv.restoreState()
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   401
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   402
class PPPolygon:
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   403
    def __init__(self, pointlist):
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   404
        self.points = pointlist
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   405
        self.fillColor = None
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   406
        self.strokeColor = (1,1,1)
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   407
        self.lineWidth=0
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   408
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   409
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   410
    def drawOn(self, canv):
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   411
        canv.saveState()
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   412
        canv.setLineWidth(self.lineWidth)
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   413
        if self.strokeColor:
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   414
            r,g,b = self.strokeColor
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   415
            canv.setStrokeColorRGB(r,g,b)
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   416
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   417
        path = canv.beginPath()
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   418
        (x,y) = self.points[0]
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   419
        path.moveTo(x,y)
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   420
        for (x,y) in self.points[1:]:
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   421
            path.lineTo(x,y)
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   422
        path.close()
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   423
        canv.drawPath(path, stroke=(self.strokeColor<>None))
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   424
        canv.restoreState()
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   425
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   426
    
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   427
class PPString:
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   428
    def __init__(self, x, y):
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   429
        self.text = ''
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   430
        self.x = x
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   431
        self.y = y
129
623baa767856 Splitting layout.py
rgbecker
parents: 122
diff changeset
   432
        self.align = TA_LEFT
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   433
        self.font = 'Times-Roman'
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   434
        self.size = 12
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   435
        self.color = (0,0,0)
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   436
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   437
    def normalizeText(self):
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   438
        """It contains literal XML text typed over several lines.
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   439
        We want to throw away
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   440
        tabs, newlines and so on, and only accept embedded string
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   441
        like '\n'"""
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   442
        lines = string.split(self.text, '\n')
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   443
        newtext = []
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   444
        for line in lines:
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   445
            newtext.append(string.strip(line))
98
98dd46590deb - Fixed multi-line strings
andy_robinson
parents: 94
diff changeset
   446
        #accept all the '\n' as newlines
98dd46590deb - Fixed multi-line strings
andy_robinson
parents: 94
diff changeset
   447
            
98dd46590deb - Fixed multi-line strings
andy_robinson
parents: 94
diff changeset
   448
        self.text = newtext
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   449
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   450
    def drawOn(self, canv):
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   451
        if self.color is None:
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   452
            return
98
98dd46590deb - Fixed multi-line strings
andy_robinson
parents: 94
diff changeset
   453
        lines = string.split(string.strip(self.text), '\\n')
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   454
        canv.saveState()
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   455
        canv.setFont(self.font, self.size)
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   456
        r,g,b = self.color
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   457
        canv.setFillColorRGB(r,g,b)
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   458
        cur_y = self.y
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   459
        for line in lines:
129
623baa767856 Splitting layout.py
rgbecker
parents: 122
diff changeset
   460
            if self.align == TA_LEFT:
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   461
                canv.drawString(self.x, cur_y, line)
129
623baa767856 Splitting layout.py
rgbecker
parents: 122
diff changeset
   462
            elif self.align == TA_CENTER:
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   463
                canv.drawCentredString(self.x, cur_y, line)
129
623baa767856 Splitting layout.py
rgbecker
parents: 122
diff changeset
   464
            elif self.align == TA_RIGHT:
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   465
                canv.drawRightString(self.x, cur_y, line)
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   466
            cur_y = cur_y - 1.2*self.size
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   467
                
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   468
        canv.restoreState()
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   469
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   470
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   471
def getSampleStyleSheet():
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   472
    """Returns a dictionary of styles to get you started.  We will
342
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   473
    provide a way to specify a module of these.  Note that this
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   474
    ust includes TableStyles as well as ParagraphStyles for any
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   475
    tables you wish to use."""
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   476
    stylesheet = {}
129
623baa767856 Splitting layout.py
rgbecker
parents: 122
diff changeset
   477
    ParagraphStyle = styles.ParagraphStyle
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   478
    
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   479
    para = ParagraphStyle('Normal', None)   #the ancestor of all
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   480
    para.fontName = 'Times-Roman'
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   481
    para.fontSize = 24
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   482
    para.leading = 28
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   483
    stylesheet['Normal'] = para
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   484
78
32def40f4893 Updated example XML to include full tag reference
andy_robinson
parents: 75
diff changeset
   485
    #This one is spaced out a bit...
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   486
    para = ParagraphStyle('BodyText', stylesheet['Normal'])
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   487
    para.spaceBefore = 12
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   488
    stylesheet['BodyText'] = para
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   489
    
78
32def40f4893 Updated example XML to include full tag reference
andy_robinson
parents: 75
diff changeset
   490
    #Indented, for lists
32def40f4893 Updated example XML to include full tag reference
andy_robinson
parents: 75
diff changeset
   491
    para = ParagraphStyle('Indent', stylesheet['Normal'])
32def40f4893 Updated example XML to include full tag reference
andy_robinson
parents: 75
diff changeset
   492
    para.leftIndent = 36
32def40f4893 Updated example XML to include full tag reference
andy_robinson
parents: 75
diff changeset
   493
    para.firstLineIndent = 36
32def40f4893 Updated example XML to include full tag reference
andy_robinson
parents: 75
diff changeset
   494
    stylesheet['Indent'] = para
32def40f4893 Updated example XML to include full tag reference
andy_robinson
parents: 75
diff changeset
   495
32def40f4893 Updated example XML to include full tag reference
andy_robinson
parents: 75
diff changeset
   496
    para = ParagraphStyle('Centered', stylesheet['Normal'])
129
623baa767856 Splitting layout.py
rgbecker
parents: 122
diff changeset
   497
    para.alignment = TA_CENTER
78
32def40f4893 Updated example XML to include full tag reference
andy_robinson
parents: 75
diff changeset
   498
    stylesheet['Centered'] = para
32def40f4893 Updated example XML to include full tag reference
andy_robinson
parents: 75
diff changeset
   499
    
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   500
    para = ParagraphStyle('BigCentered', stylesheet['Normal'])
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   501
    para.spaceBefore = 12
129
623baa767856 Splitting layout.py
rgbecker
parents: 122
diff changeset
   502
    para.alignment = TA_CENTER
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   503
    stylesheet['BigCentered'] = para
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   504
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   505
    para = ParagraphStyle('Italic', stylesheet['BodyText'])
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   506
    para.fontName = 'Times-Italic'
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   507
    stylesheet['Italic'] = para
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   508
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   509
    para = ParagraphStyle('Title', stylesheet['Normal'])
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   510
    para.fontName = 'Times-Roman'
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   511
    para.fontSize = 48
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   512
    para.Leading = 58
129
623baa767856 Splitting layout.py
rgbecker
parents: 122
diff changeset
   513
    para.alignment = TA_CENTER
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   514
    stylesheet['Title'] = para
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   515
    
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   516
    para = ParagraphStyle('Heading1', stylesheet['Normal'])
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   517
    para.fontName = 'Times-Bold'
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   518
    para.fontSize = 36
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   519
    para.leading = 44
129
623baa767856 Splitting layout.py
rgbecker
parents: 122
diff changeset
   520
    para.alignment = TA_CENTER
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   521
    stylesheet['Heading1'] = para
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   522
    
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   523
    para = ParagraphStyle('Heading2', stylesheet['Normal'])
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   524
    para.fontName = 'Times-Bold'
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   525
    para.fontSize = 28
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   526
    para.leading = 34
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   527
    para.spaceBefore = 24
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   528
    stylesheet['Heading2'] = para
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   529
    
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   530
    para = ParagraphStyle('Heading3', stylesheet['Normal'])
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   531
    para.fontName = 'Times-BoldItalic'
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   532
    para.spaceBefore = 24
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   533
    stylesheet['Heading3'] = para
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   534
393
61966cddbe13 Minor additions to styles etc.
andy_robinson
parents: 356
diff changeset
   535
    para = ParagraphStyle('Heading4', stylesheet['Normal'])
61966cddbe13 Minor additions to styles etc.
andy_robinson
parents: 356
diff changeset
   536
    para.fontName = 'Times-BoldItalic'
61966cddbe13 Minor additions to styles etc.
andy_robinson
parents: 356
diff changeset
   537
    para.spaceBefore = 6
61966cddbe13 Minor additions to styles etc.
andy_robinson
parents: 356
diff changeset
   538
    stylesheet['Heading4'] = para
61966cddbe13 Minor additions to styles etc.
andy_robinson
parents: 356
diff changeset
   539
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   540
    para = ParagraphStyle('Bullet', stylesheet['Normal'])
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   541
    para.firstLineIndent = 40
393
61966cddbe13 Minor additions to styles etc.
andy_robinson
parents: 356
diff changeset
   542
    para.leftIndent = 56
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   543
    para.spaceBefore = 6
222
f04b9db53afc Allowed intra-paragraph text; fixed various bugs
andy_robinson
parents: 180
diff changeset
   544
    para.bulletFontName = 'Symbol'
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   545
    para.bulletFontSize = 24
78
32def40f4893 Updated example XML to include full tag reference
andy_robinson
parents: 75
diff changeset
   546
    para.bulletIndent = 20
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   547
    stylesheet['Bullet'] = para
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   548
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   549
    para = ParagraphStyle('Definition', stylesheet['Normal'])
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   550
    #use this for definition lists
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   551
    para.firstLineIndent = 72
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   552
    para.leftIndent = 72
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   553
    para.bulletIndent = 0
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   554
    para.spaceBefore = 12
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   555
    para.bulletFontName = 'Helvetica-BoldOblique'
393
61966cddbe13 Minor additions to styles etc.
andy_robinson
parents: 356
diff changeset
   556
    para.bulletFontSize = 24
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   557
    stylesheet['Definition'] = para
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   558
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   559
    para = ParagraphStyle('Code', stylesheet['Normal'])
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   560
    para.fontName = 'Courier'
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   561
    para.fontSize = 16
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   562
    para.leading = 18
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   563
    para.leftIndent = 36
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   564
    stylesheet['Code'] = para
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   565
393
61966cddbe13 Minor additions to styles etc.
andy_robinson
parents: 356
diff changeset
   566
    para = ParagraphStyle('Small', stylesheet['Normal'])
61966cddbe13 Minor additions to styles etc.
andy_robinson
parents: 356
diff changeset
   567
    para.fontSize = 12
61966cddbe13 Minor additions to styles etc.
andy_robinson
parents: 356
diff changeset
   568
    para.leading = 14
61966cddbe13 Minor additions to styles etc.
andy_robinson
parents: 356
diff changeset
   569
    stylesheet['Small'] = para
61966cddbe13 Minor additions to styles etc.
andy_robinson
parents: 356
diff changeset
   570
342
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   571
    #now for a table
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   572
    ts = TableStyle([
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   573
         ('FONT', (0,0), (-1,-1), 'Times-Roman', 24),
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   574
         ('LINEABOVE', (0,0), (-1,0), 2, colors.green),
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   575
         ('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black),
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   576
         ('LINEBELOW', (0,-1), (-1,-1), 2, colors.green),
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   577
         ('LINEBEFORE', (-1,0), (-1,-1), 2, colors.black),
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   578
         ('ALIGN', (1,1), (-1,-1), 'RIGHT'),   #all numeric cells right aligned
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   579
         ('TEXTCOLOR', (0,1), (0,-1), colors.red),
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   580
         ('BACKGROUND', (0,0), (-1,0), colors.Color(0,0.7,0.7))
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   581
         ])
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   582
    stylesheet['table1'] = ts
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   583
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   584
    return stylesheet
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   585
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   586
#make a singleton and a function to access it        
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   587
_styles = None
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   588
def getStyles():
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   589
    global _styles
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   590
    if not _styles:
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   591
        _styles = getSampleStyleSheet()
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   592
    return _styles
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   593
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   594
def setStyles(newStyleSheet):
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   595
    global _styles
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   596
    _styles = newStyleSheet
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   597
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   598
        
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   599
def test():
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   600
    p = stdparser.PPMLParser()
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   601
    p.feed(sample)
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   602
    p.getPresentation().save()
25
19e8698c4a76 Memory leak fixes
rgbecker
parents: 16
diff changeset
   603
    p.close()
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   604
353
c24bbfd09f1c Added Speaker Notes facility
andy_robinson
parents: 342
diff changeset
   605
def process(datafilename, speakerNotes=0):
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   606
    parser = stdparser.PPMLParser()
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   607
    rawdata = open(datafilename).read()
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   608
    parser.feed(rawdata)
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   609
    pres = parser.getPresentation()
353
c24bbfd09f1c Added Speaker Notes facility
andy_robinson
parents: 342
diff changeset
   610
    pres.speakerNotes = speakerNotes
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   611
    pres.save()
353
c24bbfd09f1c Added Speaker Notes facility
andy_robinson
parents: 342
diff changeset
   612
    print 'saved presentation %s.pdf' % os.path.splitext(datafilename)[0]
25
19e8698c4a76 Memory leak fixes
rgbecker
parents: 16
diff changeset
   613
    parser.close()
4
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   614
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   615
if __name__ == '__main__':
490f6b790498 Initial revision
rgbecker
parents:
diff changeset
   616
    import sys
353
c24bbfd09f1c Added Speaker Notes facility
andy_robinson
parents: 342
diff changeset
   617
    #see if there is a '/n' argument
c24bbfd09f1c Added Speaker Notes facility
andy_robinson
parents: 342
diff changeset
   618
    speakernotes = 0
c24bbfd09f1c Added Speaker Notes facility
andy_robinson
parents: 342
diff changeset
   619
    for arg in sys.argv:
c24bbfd09f1c Added Speaker Notes facility
andy_robinson
parents: 342
diff changeset
   620
        if arg in ['/n','/no','/not','/note','/notes']:
c24bbfd09f1c Added Speaker Notes facility
andy_robinson
parents: 342
diff changeset
   621
            speakernotes = 1
c24bbfd09f1c Added Speaker Notes facility
andy_robinson
parents: 342
diff changeset
   622
            sys.argv.remove(arg)
c24bbfd09f1c Added Speaker Notes facility
andy_robinson
parents: 342
diff changeset
   623
            print 'speaker notes mode'
c24bbfd09f1c Added Speaker Notes facility
andy_robinson
parents: 342
diff changeset
   624
            
90
a537951b0851 Allow multiple files, default to pythonpoint.xml if present
rgbecker
parents: 78
diff changeset
   625
    if len(sys.argv) == 1 and os.path.isfile('pythonpoint.xml'):
94
0a8eb8fda6a1 Fixe apendi() typo
rgbecker
parents: 90
diff changeset
   626
		sys.argv.append('pythonpoint.xml')
90
a537951b0851 Allow multiple files, default to pythonpoint.xml if present
rgbecker
parents: 78
diff changeset
   627
    if len(sys.argv) == 1:
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   628
        print """PythonPoint - copyright ReportLab Inc. 1999-2000
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   629
usage:
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   630
    pythonpoint.py my_presentation.xml
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   631
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   632
To create the PythonPoint user guide, do:
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   633
    pythonpoint.py pythonpoint.xml
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   634
daedbd33f33e Added several new shape tags.
andy_robinson
parents: 47
diff changeset
   635
Read it, then look at the XML; all should be clear!"""
90
a537951b0851 Allow multiple files, default to pythonpoint.xml if present
rgbecker
parents: 78
diff changeset
   636
    else:
a537951b0851 Allow multiple files, default to pythonpoint.xml if present
rgbecker
parents: 78
diff changeset
   637
        for datafile in sys.argv[1:]:
a537951b0851 Allow multiple files, default to pythonpoint.xml if present
rgbecker
parents: 78
diff changeset
   638
            if os.path.isfile(datafile):
353
c24bbfd09f1c Added Speaker Notes facility
andy_robinson
parents: 342
diff changeset
   639
                process(datafile, speakernotes)   #see just above
90
a537951b0851 Allow multiple files, default to pythonpoint.xml if present
rgbecker
parents: 78
diff changeset
   640
            else:
a537951b0851 Allow multiple files, default to pythonpoint.xml if present
rgbecker
parents: 78
diff changeset
   641
                print 'Data file not found:', datafile