reportlab/demos/pythonpoint/stdparser.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/stdparser.py?cvsroot=reportlab
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 393
diff changeset
     4
#$Header: /tmp/reportlab/reportlab/demos/pythonpoint/Attic/stdparser.py,v 1.12 2000/10/25 08:57:44 rgbecker Exp $
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
     5
__version__=''' $Id $ '''
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
     6
__doc__="""
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
     7
Parser for PythonPoint using the xmllib.py in the standard Python
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
     8
distribution.  Slow, but always present.  We intend to add new parsers
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
     9
as Python 1.6 and the xml package spread in popularity.
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    10
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    11
The parser has a getPresentation method; it is called from
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    12
pythonpoint.py.
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    13
"""
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    14
189
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
    15
from reportlab.lib import xmllib
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    16
import string
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    17
import imp
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    18
import pythonpoint
393
61966cddbe13 Minor additions to styles etc.
andy_robinson
parents: 351
diff changeset
    19
from reportlab.lib import colors
129
623baa767856 Splitting layout.py
rgbecker
parents: 78
diff changeset
    20
from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    21
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    22
class PPMLParser(xmllib.XMLParser):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    23
    attributes = {
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    24
        #this defines the available attributes for all objects,
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    25
        #and their default values.  Although these don't have to
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    26
        #be strings, the ones parsed from the XML do, so
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    27
        #everything is a quoted string and the parser has to
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    28
        #convert these to numbers where appropriate.
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    29
        'stylesheet': {
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    30
            'path':'None',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    31
            'module':'None',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    32
            'function':'getParagraphStyles'
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    33
            },
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    34
        'frame': {
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    35
            'x':'0',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    36
            'y':'0',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    37
            'width':'0',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    38
            'height':'0',
222
f04b9db53afc Allowed intra-paragraph text; fixed various bugs
andy_robinson
parents: 189
diff changeset
    39
            'border':'false',
f04b9db53afc Allowed intra-paragraph text; fixed various bugs
andy_robinson
parents: 189
diff changeset
    40
            'leftmargin':'0',  #this is ignored
f04b9db53afc Allowed intra-paragraph text; fixed various bugs
andy_robinson
parents: 189
diff changeset
    41
            'topmargin':'0',  #this is ignored
f04b9db53afc Allowed intra-paragraph text; fixed various bugs
andy_robinson
parents: 189
diff changeset
    42
            'rightmargin':'0',  #this is ignored
f04b9db53afc Allowed intra-paragraph text; fixed various bugs
andy_robinson
parents: 189
diff changeset
    43
            'bottommargin':'0',  #this is ignored
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    44
            },
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    45
        'slide': {
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    46
            'id':'None',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    47
            'title':'None',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    48
            'effectname':'None',   # Split, Blinds, Box, Wipe, Dissolve, Glitter
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    49
            'effectdirection':'0',   # 0,90,180,270
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    50
            'effectdimension':'H',   # H or V - horizontal or vertical
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    51
            'effectmotion':'I',     # Inwards or Outwards
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    52
            'effectduration':'1',    #seconds,
180
f92b4f73b1b5 Changed to display multiple outline levels
andy_robinson
parents: 129
diff changeset
    53
            'outlineentry':'None',
f92b4f73b1b5 Changed to display multiple outline levels
andy_robinson
parents: 129
diff changeset
    54
            'outlinelevel':'0'       # 1 is a child, 2 is a grandchild etc.
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    55
            },
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    56
        'para': {
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    57
            'style':'Normal',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    58
            'bullettext':''
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    59
            },
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    60
        'image': {
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    61
            'filename':'',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    62
            'width':'None',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    63
            'height':'None'
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    64
            },
342
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
    65
        'table': {
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
    66
            'widths':'None',
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
    67
            'heights':'None',
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
    68
            'fieldDelim':',',
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
    69
            'rowDelim':'\n',
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
    70
            'style':'None'
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
    71
            },
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    72
        'rectangle': {
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    73
            'x':'0',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    74
            'y':'0',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    75
            'width':'100',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    76
            'height':'100',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    77
            'fill':'None',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    78
            'stroke':'(0,0,0)',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    79
            'linewidth':'0'
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    80
            },
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    81
        'roundrect': {
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    82
            'x':'0',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    83
            'y':'0',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    84
            'width':'100',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    85
            'height':'100',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    86
            'radius':'6',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    87
            'fill':'None',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    88
            'stroke':'(0,0,0)',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    89
            'linewidth':'0'
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    90
            
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    91
            },
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    92
        'line': {
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    93
            'x1':'0',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    94
            'y1':'0',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    95
            'x2':'100',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    96
            'y2':'100',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    97
            'stroke':'(0,0,0)',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    98
            'width':'0'
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
    99
            
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   100
            },
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   101
        'ellipse': {
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   102
            'x1':'0',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   103
            'y1':'0',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   104
            'x2':'100',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   105
            'y2':'100',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   106
            'stroke':'(0,0,0)',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   107
            'fill':'None',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   108
            'linewidth':'0'
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   109
            
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   110
            },
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   111
        'polygon': {
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   112
            'points':'(0,0),(50,0),(25,25)',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   113
            'stroke':'(0,0,0)',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   114
            'linewidth':'0',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   115
            'stroke':'(0,0,0)',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   116
            'fill':'None'
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   117
            
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   118
            },
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   119
        'string':{
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   120
            'x':'0',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   121
            'y':'0',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   122
            'color':'(0,0,0)',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   123
            'font':'Times-Roman',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   124
            'size':'12',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   125
            'align':'left'
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   126
            },
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   127
        'customshape':{
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   128
            'path':'None',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   129
            'module':'None',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   130
            'class':'None',
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   131
            'initargs':'None'
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   132
            }
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   133
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   134
        }
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   135
    
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   136
    def __init__(self):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   137
        self.presentations = []
342
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   138
        #yes, I know a generic stack would be easier...
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   139
        #still, testing if we are 'in' something gives
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   140
        #a degree of validation.
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   141
        self._curPres = None
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   142
        self._curSection = None
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   143
        self._curSlide = None
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   144
        self._curFrame = None
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   145
        self._curPara = None  #the only places we are interested in
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   146
        self._curPrefmt = None
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   147
        self._curString = None
342
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   148
        self._curTable = None
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   149
        xmllib.XMLParser.__init__(self)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   150
189
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   151
    def _arg(self,tag,args,name):
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   152
        if args.has_key(name):
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   153
            v = args[name]
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   154
        else:
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   155
            if self.attributes.has_key(tag):
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   156
                v = self.attributes[tag][name]
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   157
            else:
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   158
                v = None
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   159
        return v
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   160
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   161
    def ceval(self,tag,args,name):
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   162
        if args.has_key(name):
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   163
            v = args[name]
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   164
        else:
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   165
            if self.attributes.has_key(tag):
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   166
                v = self.attributes[tag][name]
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   167
            else:
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   168
                return None
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   169
        return eval(v)
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   170
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   171
    def getPresentation(self):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   172
        return self._curPres
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   173
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   174
    def handle_data(self, data):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   175
        #the only data should be paragraph text, preformatted para
342
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   176
        #text, 'string text' for a fixed string on the page,
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   177
        #or table data
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   178
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   179
        if self._curPara:
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   180
            self._curPara.rawtext = self._curPara.rawtext + data
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   181
        elif self._curPrefmt:
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   182
            self._curPrefmt.rawtext = self._curPrefmt.rawtext + data
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   183
        elif  self._curString:
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   184
            self._curString.text = self._curString.text + data
342
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   185
        elif self._curTable:
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   186
            self._curTable.rawBlocks.append(data)
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   187
            
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   188
    def handle_cdata(self, data):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   189
        #just append to current paragraph text, so we can quote XML
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   190
        if self._curPara:
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   191
            self._curPara.rawtext = self._curPara.rawtext + data
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   192
        if self._curPrefmt:
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   193
            self._curPrefmt.rawtext = self._curPrefmt.rawtext + data
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   194
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   195
            
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   196
    def start_presentation(self, args):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   197
        #print 'started presentation:', args['filename']
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   198
        self._curPres = pythonpoint.PPPresentation()
189
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   199
        self._curPres.filename = self._arg('presentation',args,'filename')
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   200
        self._curPres.effectName = self._arg('presentation',args,'effect')
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   201
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   202
    def end_presentation(self):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   203
        #print 'ended presentation'
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   204
        print 'Fully parsed presentation',self._curPres.filename
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   205
189
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   206
    def start_stylesheet(self, args):
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   207
        #makes it the current style sheet.
189
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   208
        path = self._arg('stylesheet',args,'path')
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   209
        if path=='None':
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   210
            path = None
189
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   211
        modulename = self._arg('stylesheet',args,'module')
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   212
        funcname = self._arg('stylesheet',args,'function')
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   213
        found = imp.find_module(modulename, path)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   214
        assert found, "StyleSheet %s not found" % modulename
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   215
        (file, pathname, description) = found
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   216
        mod = imp.load_module(modulename, file, pathname, description)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   217
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   218
        #now get the function
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   219
        func = getattr(mod, funcname)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   220
        pythonpoint.setStyles(func())
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   221
        print 'set global stylesheet to %s.%s()' % (modulename, funcname)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   222
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   223
    def end_stylesheet(self):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   224
        pass
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   225
189
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   226
    def start_section(self, args):
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   227
        name = self._arg('section',args,'name')
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   228
        self._curSection = pythonpoint.PPSection(name)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   229
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   230
    def end_section(self):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   231
        self._curSection = None
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   232
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   233
    def start_slide(self, args):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   234
        s = pythonpoint.PPSlide()
189
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   235
        s.id = self._arg('slide',args,'id')
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   236
        s.title = self._arg('slide',args,'title')
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   237
        a = self._arg('slide',args,'effectname')
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   238
        if a <> 'None': s.effectName = a
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   239
        s.effectDirection = self.ceval('slide',args,'effectdirection')
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   240
        s.effectDimension = self._arg('slide',args,'effectdimension')
393
61966cddbe13 Minor additions to styles etc.
andy_robinson
parents: 351
diff changeset
   241
        s.effectDuration = self.ceval('slide',args,'effectduration')
189
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   242
        s.effectMotion = self._arg('slide',args,'effectmotion')
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   243
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   244
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   245
        #HACK - may not belong here in the long run...
393
61966cddbe13 Minor additions to styles etc.
andy_robinson
parents: 351
diff changeset
   246
        #be default, use the slide title for the outline entry,
61966cddbe13 Minor additions to styles etc.
andy_robinson
parents: 351
diff changeset
   247
        #unless it is specified as an arg.
189
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   248
        a = self._arg('slide',args,'outlineentry')
393
61966cddbe13 Minor additions to styles etc.
andy_robinson
parents: 351
diff changeset
   249
        if a == "Hide":
61966cddbe13 Minor additions to styles etc.
andy_robinson
parents: 351
diff changeset
   250
            s.outlineEntry = None
61966cddbe13 Minor additions to styles etc.
andy_robinson
parents: 351
diff changeset
   251
        elif a <> 'None':
189
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   252
            s.outlineEntry = a
180
f92b4f73b1b5 Changed to display multiple outline levels
andy_robinson
parents: 129
diff changeset
   253
        else:
189
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   254
            s.outlineEntry = s.title
393
61966cddbe13 Minor additions to styles etc.
andy_robinson
parents: 351
diff changeset
   255
        
189
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   256
        s.outlineLevel = self.ceval('slide',args,'outlinelevel')
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   257
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   258
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   259
        #let it know its section, which may be none
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   260
        s.section = self._curSection
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   261
        self._curSlide = s
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   262
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   263
    def end_slide(self):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   264
        self._curPres.slides.append(self._curSlide)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   265
        self._curSlide = None
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   266
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   267
    def start_frame(self, args):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   268
        self._curFrame = pythonpoint.PPFrame(
189
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   269
            self.ceval('frame',args,'x'),
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   270
            self.ceval('frame',args,'y'),
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   271
            self.ceval('frame',args,'width'),
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   272
            self.ceval('frame',args,'height')
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   273
            )
189
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   274
        if self._arg('frame',args,'border')=='true':
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   275
            self._curFrame.showBoundary = 1
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   276
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   277
    def end_frame(self):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   278
        self._curSlide.frames.append(self._curFrame)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   279
        self._curFrame = None
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   280
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   281
    def start_para(self, args):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   282
        self._curPara = pythonpoint.PPPara()
189
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   283
        self._curPara.style = self._arg('para',args,'style')
222
f04b9db53afc Allowed intra-paragraph text; fixed various bugs
andy_robinson
parents: 189
diff changeset
   284
f04b9db53afc Allowed intra-paragraph text; fixed various bugs
andy_robinson
parents: 189
diff changeset
   285
        # hack - bullet character if bullet style        
f04b9db53afc Allowed intra-paragraph text; fixed various bugs
andy_robinson
parents: 189
diff changeset
   286
        bt = self._arg('para',args,'bullettext')
f04b9db53afc Allowed intra-paragraph text; fixed various bugs
andy_robinson
parents: 189
diff changeset
   287
        if self._curPara.style == 'Bullet' and bt == '':
f04b9db53afc Allowed intra-paragraph text; fixed various bugs
andy_robinson
parents: 189
diff changeset
   288
            bt = '\267'  # Symbol Font bullet character, reasonable default
f04b9db53afc Allowed intra-paragraph text; fixed various bugs
andy_robinson
parents: 189
diff changeset
   289
        self._curPara.bulletText = bt
78
32def40f4893 Updated example XML to include full tag reference
andy_robinson
parents: 75
diff changeset
   290
        
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   291
    def end_para(self):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   292
        self._curFrame.content.append(self._curPara)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   293
        self._curPara = None
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   294
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   295
    def start_prefmt(self, args):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   296
        self._curPrefmt = pythonpoint.PPPreformattedText()
189
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   297
        self._curPrefmt.style = self._arg('prefmt',args,'style')
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   298
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   299
    def end_prefmt(self):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   300
        self._curFrame.content.append(self._curPrefmt)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   301
        self._curPrefmt = None
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   302
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   303
    def start_image(self, args):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   304
        self._curImage = pythonpoint.PPImage()
189
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   305
        self._curImage.filename = self._arg('image',args,'filename')
223
0b0f63bec91c Bug in Image tag
andy_robinson
parents: 222
diff changeset
   306
        self._curImage.width = self.ceval('image',args,'width')
0b0f63bec91c Bug in Image tag
andy_robinson
parents: 222
diff changeset
   307
        self._curImage.height = self.ceval('image',args,'height')
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   308
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   309
    def end_image(self):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   310
        self._curFrame.content.append(self._curImage)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   311
        self._curImage = None
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   312
342
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   313
    def start_table(self, args):
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   314
        self._curTable = pythonpoint.PPTable()
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   315
        self._curTable.widths = self.ceval('table',args,'widths')
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   316
        self._curTable.heights = self.ceval('table',args,'heights')
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   317
        #these may contain escapes like tabs - handle with
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   318
        #a bit more care.
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   319
        if args.has_key('fieldDelim'):
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   320
            self._curTable.fieldDelim = eval('"' + args['fieldDelim'] + '"')
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   321
        if args.has_key('rowDelim'):
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   322
            self._curTable.rowDelim = eval('"' + args['rowDelim'] + '"')
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   323
        if args.has_key('style'):
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   324
            self._curTable.style = args['style']
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   325
        
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   326
        
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   327
        
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   328
    def end_table(self):
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   329
        self._curFrame.content.append(self._curTable)
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   330
        self._curTable = None
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   331
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   332
    def start_spacer(self, args):
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   333
        """No contents so deal with it here."""
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   334
        sp = pythonpoint.PPSpacer()
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   335
        sp.height = eval(args['height'])
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 253
diff changeset
   336
        self._curFrame.content.append(sp)
351
78623c3d0932 Added end_spacer
rgbecker
parents: 342
diff changeset
   337
78623c3d0932 Added end_spacer
rgbecker
parents: 342
diff changeset
   338
    def end_spacer(self):
78623c3d0932 Added end_spacer
rgbecker
parents: 342
diff changeset
   339
        pass
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   340
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   341
    ## the graphics objects - go into either the current section
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   342
    ## or the current slide.
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   343
    def start_fixedimage(self, args):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   344
        img = pythonpoint.PPFixedImage()
189
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   345
        img.filename = self._arg('fixedimage',args,'filename')
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   346
        img.x = self.ceval('fixedimage',args,'x')
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   347
        img.y = self.ceval('fixedimage',args,'y')
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   348
        img.width = self.ceval('fixedimage',args,'width')
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   349
        img.height = self.ceval('fixedimage',args,'height')
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   350
        self._curFixedImage = img
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   351
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   352
    def end_fixedimage(self):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   353
        if self._curSlide:
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   354
            self._curSlide.graphics.append(self._curFixedImage)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   355
        elif self._curSection:
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   356
            self._curSection.graphics.append(self._curFixedImage)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   357
        self._curFixedImage = None
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   358
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   359
    def start_rectangle(self, args):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   360
        rect = pythonpoint.PPRectangle(
189
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   361
                    self.ceval('rectangle',args,'x'),
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   362
                    self.ceval('rectangle',args,'y'),
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   363
                    self.ceval('rectangle',args,'width'),
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   364
                    self.ceval('rectangle',args,'height')
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   365
                    )
189
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   366
        rect.fillColor = self.ceval('rectangle',args,'fill')
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   367
        rect.strokeColor = self.ceval('rectangle',args,'stroke')
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   368
        self._curRectangle = rect
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   369
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   370
    def end_rectangle(self):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   371
        if self._curSlide:
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   372
            self._curSlide.graphics.append(self._curRectangle)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   373
        elif self._curSection:
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   374
            self._curSection.graphics.append(self._curRectangle)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   375
        self._curRectangle = None
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   376
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   377
    def start_roundrect(self, args):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   378
        rrect = pythonpoint.PPRoundRect(
189
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   379
                    self.ceval('roundrect',args,'x'),
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   380
                    self.ceval('roundrect',args,'y'),
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   381
                    self.ceval('roundrect',args,'width'),
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   382
                    self.ceval('roundrect',args,'height'),
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   383
                    self.ceval('roundrect',args,'radius')
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   384
                    )
189
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   385
        rrect.fillColor = self.ceval('roundrect',args,'fill')
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   386
        rrect.strokeColor = self.ceval('roundrect',args,'stroke')
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   387
        self._curRoundRect = rrect
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   388
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   389
    def end_roundrect(self):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   390
        if self._curSlide:
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   391
            self._curSlide.graphics.append(self._curRoundRect)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   392
        elif self._curSection:
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   393
            self._curSection.graphics.append(self._curRoundRect)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   394
        self._curRoundRect = None
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   395
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   396
    def start_line(self, args):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   397
        self._curLine = pythonpoint.PPLine(
189
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   398
                    self.ceval('line',args,'x1'),
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   399
                    self.ceval('line',args,'y1'),
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   400
                    self.ceval('line',args,'x2'),
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   401
                    self.ceval('line',args,'y2')
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   402
                    )
189
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   403
        self._curLine.strokeColor = self.ceval('line',args,'stroke')
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   404
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   405
    def end_line(self):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   406
        if self._curSlide:
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   407
            self._curSlide.graphics.append(self._curLine)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   408
        elif self._curSection:
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   409
            self._curSection.graphics.append(self._curLine)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   410
        self._curLine = None
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   411
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   412
    def start_ellipse(self, args):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   413
        self._curEllipse = pythonpoint.PPEllipse(
189
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   414
                    self.ceval('ellipse',args,'x1'),
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   415
                    self.ceval('ellipse',args,'y1'),
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   416
                    self.ceval('ellipse',args,'x2'),
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   417
                    self.ceval('ellipse',args,'y2')
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   418
                    )
189
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   419
        self._curEllipse.strokeColor = self.ceval('ellipse',args,'stroke')
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   420
        self._curEllipse.fillColor = self.ceval('ellipse',args,'fill')
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   421
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   422
    def end_ellipse(self):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   423
        if self._curSlide:
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   424
            self._curSlide.graphics.append(self._curEllipse)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   425
        elif self._curSection:
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   426
            self._curSection.graphics.append(self._curEllipse)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   427
        self._curEllipse = None
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   428
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   429
    def start_polygon(self, args):
189
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   430
        self._curPolygon = pythonpoint.PPPolygon(self.ceval('polygon',args,'points'))
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   431
        self._curPolygon.strokeColor = self.ceval('polygon',args,'stroke')
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   432
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   433
    def end_polygon(self):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   434
        if self._curSlide:
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   435
            self._curSlide.graphics.append(self._curPolygon)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   436
        elif self._curSection:
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   437
            self._curSection.graphics.append(self._curPolygon)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   438
        self._curEllipse = None
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   439
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   440
    def start_string(self, args):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   441
        self._curString = pythonpoint.PPString(
189
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   442
                            self.ceval('string',args,'x'),
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   443
                            self.ceval('string',args,'y')
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   444
                            )
189
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   445
        self._curString.color = self.ceval('string',args,'color')
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   446
        self._curString.font = self._arg('string',args,'font')
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   447
        self._curString.size = self.ceval('string',args,'size')
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   448
        if args['align'] == 'left':
129
623baa767856 Splitting layout.py
rgbecker
parents: 78
diff changeset
   449
            self._curString.align = TA_LEFT
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   450
        elif args['align'] == 'center':
129
623baa767856 Splitting layout.py
rgbecker
parents: 78
diff changeset
   451
            self._curString.align = TA_CENTER
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   452
        elif args['align'] == 'right':
129
623baa767856 Splitting layout.py
rgbecker
parents: 78
diff changeset
   453
            self._curString.align = TA_RIGHT
623baa767856 Splitting layout.py
rgbecker
parents: 78
diff changeset
   454
        elif args['align'] == 'justify':
623baa767856 Splitting layout.py
rgbecker
parents: 78
diff changeset
   455
            self._curString.align = TA_JUSTIFY
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   456
        #text comes later within the tag
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   457
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   458
    def end_string(self):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   459
        #controller should have set the text
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   460
        if self._curSlide:
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   461
            self._curSlide.graphics.append(self._curString)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   462
        elif self._curSection:
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   463
            self._curSection.graphics.append(self._curString)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   464
        self._curString = None
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   465
189
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   466
    def start_customshape(self, args):
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   467
        #loads one
189
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   468
        path = self._arg('customshape',args,'path')
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   469
        if path=='None':
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   470
            path = None
393
61966cddbe13 Minor additions to styles etc.
andy_robinson
parents: 351
diff changeset
   471
        else:
61966cddbe13 Minor additions to styles etc.
andy_robinson
parents: 351
diff changeset
   472
            path=[path]
189
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   473
        modulename = self._arg('customshape',args,'module')
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   474
        funcname = self._arg('customshape',args,'class')
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   475
        found = imp.find_module(modulename, path)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   476
        assert found, "CustomShape %s not found" % modulename
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   477
        (file, pathname, description) = found
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   478
        mod = imp.load_module(modulename, file, pathname, description)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   479
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   480
        #now get the function
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   481
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   482
        func = getattr(mod, funcname)
189
451c5befb07e Change to allow different xmllib
rgbecker
parents: 180
diff changeset
   483
        initargs = self.ceval('customshape',args,'initargs')
75
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   484
        self._curCustomShape = apply(func, initargs)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   485
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   486
        
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   487
    def end_customshape(self):
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   488
        if self._curSlide:
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   489
            self._curSlide.graphics.append(self._curCustomShape)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   490
        elif self._curSection:
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   491
            self._curSection.graphics.append(self._curCustomShape)
daedbd33f33e Added several new shape tags.
andy_robinson
parents:
diff changeset
   492
        self._curCustomShape = None
222
f04b9db53afc Allowed intra-paragraph text; fixed various bugs
andy_robinson
parents: 189
diff changeset
   493
f04b9db53afc Allowed intra-paragraph text; fixed various bugs
andy_robinson
parents: 189
diff changeset
   494
f04b9db53afc Allowed intra-paragraph text; fixed various bugs
andy_robinson
parents: 189
diff changeset
   495
    ## intra-paragraph XML should be allowed through into PLATYPUS
f04b9db53afc Allowed intra-paragraph text; fixed various bugs
andy_robinson
parents: 189
diff changeset
   496
    def unknown_starttag(self, tag, attrs):
f04b9db53afc Allowed intra-paragraph text; fixed various bugs
andy_robinson
parents: 189
diff changeset
   497
        if  self._curPara:
f04b9db53afc Allowed intra-paragraph text; fixed various bugs
andy_robinson
parents: 189
diff changeset
   498
            echo = '<%s' % tag
f04b9db53afc Allowed intra-paragraph text; fixed various bugs
andy_robinson
parents: 189
diff changeset
   499
            for (key, value) in attrs.items():
f04b9db53afc Allowed intra-paragraph text; fixed various bugs
andy_robinson
parents: 189
diff changeset
   500
                echo = echo + ' %s="%s"' % (key, value)
f04b9db53afc Allowed intra-paragraph text; fixed various bugs
andy_robinson
parents: 189
diff changeset
   501
            echo = echo + '>'
f04b9db53afc Allowed intra-paragraph text; fixed various bugs
andy_robinson
parents: 189
diff changeset
   502
            self._curPara.rawtext = self._curPara.rawtext + echo
f04b9db53afc Allowed intra-paragraph text; fixed various bugs
andy_robinson
parents: 189
diff changeset
   503
        else:
f04b9db53afc Allowed intra-paragraph text; fixed various bugs
andy_robinson
parents: 189
diff changeset
   504
            print 'Unknown start tag %s' % tag
f04b9db53afc Allowed intra-paragraph text; fixed various bugs
andy_robinson
parents: 189
diff changeset
   505
    def unknown_endtag(self, tag):
f04b9db53afc Allowed intra-paragraph text; fixed various bugs
andy_robinson
parents: 189
diff changeset
   506
        if  self._curPara:
f04b9db53afc Allowed intra-paragraph text; fixed various bugs
andy_robinson
parents: 189
diff changeset
   507
            self._curPara.rawtext = self._curPara.rawtext + '</%s>'% tag
f04b9db53afc Allowed intra-paragraph text; fixed various bugs
andy_robinson
parents: 189
diff changeset
   508
        else:
f04b9db53afc Allowed intra-paragraph text; fixed various bugs
andy_robinson
parents: 189
diff changeset
   509
            print 'Unknown end tag %s' % tag
253
cfcf8d555a2c Platypus re-organisation
rgbecker
parents: 223
diff changeset
   510