2963
|
1 |
#!/usr/bin/env python
|
|
2 |
|
|
3 |
"""
|
|
4 |
This is PythonPoint!
|
|
5 |
|
|
6 |
The idea is a simple markup languages for describing presentation
|
|
7 |
slides, and other documents which run page by page. I expect most
|
|
8 |
of it will be reusable in other page layout stuff.
|
|
9 |
|
|
10 |
Look at the sample near the top, which shows how the presentation
|
|
11 |
should be coded up.
|
|
12 |
|
|
13 |
The parser, which is in a separate module to allow for multiple
|
|
14 |
parsers, turns the XML sample into an object tree. There is a
|
|
15 |
simple class hierarchy of items, the inner levels of which create
|
|
16 |
flowable objects to go in the frames. These know how to draw
|
|
17 |
themselves.
|
|
18 |
|
|
19 |
The currently available 'Presentation Objects' are:
|
|
20 |
|
|
21 |
The main hierarchy...
|
|
22 |
PPPresentation
|
|
23 |
PPSection
|
|
24 |
PPSlide
|
|
25 |
PPFrame
|
|
26 |
|
|
27 |
PPAuthor, PPTitle and PPSubject are optional
|
|
28 |
|
|
29 |
Things to flow within frames...
|
|
30 |
PPPara - flowing text
|
|
31 |
PPPreformatted - text with line breaks and tabs, for code..
|
|
32 |
PPImage
|
|
33 |
PPTable - bulk formatted tabular data
|
|
34 |
PPSpacer
|
|
35 |
|
|
36 |
Things to draw directly on the page...
|
|
37 |
PPRect
|
|
38 |
PPRoundRect
|
|
39 |
PPDrawingElement - user base class for graphics
|
|
40 |
PPLine
|
|
41 |
PPEllipse
|
|
42 |
|
|
43 |
Features added by H. Turgut Uyar <uyar@cs.itu.edu.tr>
|
|
44 |
- TrueType support (actually, just an import in the style file);
|
|
45 |
this also enables the use of Unicode symbols
|
|
46 |
- para, image, table, line, rectangle, roundrect, ellipse, polygon
|
|
47 |
and string elements can now have effect attributes
|
|
48 |
(careful: new slide for each effect!)
|
|
49 |
- added printout mode (no new slides for effects, see item above)
|
|
50 |
- added a second-level bullet: Bullet2
|
|
51 |
- small bugfixes in handleHiddenSlides:
|
|
52 |
corrected the outlineEntry of included hidden slide
|
|
53 |
and made sure to include the last slide even if hidden
|
|
54 |
|
|
55 |
Recently added features are:
|
|
56 |
|
|
57 |
- file globbing
|
|
58 |
- package structure
|
|
59 |
- named colors throughout (using names from reportlab/lib/colors.py)
|
|
60 |
- handout mode with arbitrary number of columns per page
|
|
61 |
- stripped off pages hidden in the outline tree (hackish)
|
|
62 |
- new <notes> tag for speaker notes (paragraphs only)
|
|
63 |
- new <pycode> tag for syntax-colorized Python code
|
|
64 |
- reformatted pythonpoint.xml and monterey.xml demos
|
|
65 |
- written/extended DTD
|
|
66 |
- arbitrary font support
|
|
67 |
- print proper speaker notes (TODO)
|
|
68 |
- fix bug with partially hidden graphics (TODO)
|
|
69 |
- save in combined presentation/handout mode (TODO)
|
|
70 |
- add pyRXP support (TODO)
|
|
71 |
"""
|
|
72 |
|
|
73 |
import os, sys, imp, string, pprint, getopt, glob
|
|
74 |
|
|
75 |
from reportlab import rl_config
|
|
76 |
from reportlab.lib import styles
|
|
77 |
from reportlab.lib import colors
|
|
78 |
from reportlab.lib.units import cm
|
|
79 |
from reportlab.lib.utils import getStringIO
|
|
80 |
from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY
|
|
81 |
from reportlab.pdfbase import pdfmetrics
|
|
82 |
from reportlab.pdfgen import canvas
|
|
83 |
from reportlab.platypus.doctemplate import SimpleDocTemplate
|
|
84 |
from reportlab.platypus.flowables import Flowable
|
|
85 |
from reportlab.platypus.xpreformatted import PythonPreformatted
|
|
86 |
from reportlab.platypus import Preformatted, Paragraph, Frame, \
|
|
87 |
Image, Table, TableStyle, Spacer
|
|
88 |
|
|
89 |
|
|
90 |
USAGE_MESSAGE = """\
|
|
91 |
PythonPoint - a tool for making presentations in PDF.
|
|
92 |
|
|
93 |
Usage:
|
|
94 |
pythonpoint.py [options] file1.xml [file2.xml [...]]
|
|
95 |
|
|
96 |
where options can be any of these:
|
|
97 |
|
|
98 |
-h / --help prints this message
|
|
99 |
-n / --notes leave room for comments
|
|
100 |
-v / --verbose verbose mode
|
|
101 |
-s / --silent silent mode (NO output)
|
|
102 |
--handout produce handout document
|
|
103 |
--printout produce printout document
|
|
104 |
--cols specify number of columns
|
|
105 |
on handout pages (default: 2)
|
|
106 |
|
|
107 |
To create the PythonPoint user guide, do:
|
|
108 |
pythonpoint.py pythonpoint.xml
|
|
109 |
"""
|
|
110 |
|
|
111 |
|
|
112 |
#####################################################################
|
|
113 |
# This should probably go into reportlab/lib/fonts.py...
|
|
114 |
#####################################################################
|
|
115 |
|
|
116 |
class FontNameNotFoundError(Exception):
|
|
117 |
pass
|
|
118 |
|
|
119 |
|
|
120 |
class FontFilesNotFoundError(Exception):
|
|
121 |
pass
|
|
122 |
|
|
123 |
|
|
124 |
##def findFontName(path):
|
|
125 |
## "Extract a Type-1 font name from an AFM file."
|
|
126 |
##
|
|
127 |
## f = open(path)
|
|
128 |
##
|
|
129 |
## found = 0
|
|
130 |
## while not found:
|
|
131 |
## line = f.readline()[:-1]
|
|
132 |
## if not found and line[:16] == 'StartCharMetrics':
|
|
133 |
## raise FontNameNotFoundError, path
|
|
134 |
## if line[:8] == 'FontName':
|
|
135 |
## fontName = line[9:]
|
|
136 |
## found = 1
|
|
137 |
##
|
|
138 |
## return fontName
|
|
139 |
##
|
|
140 |
##
|
|
141 |
##def locateFilesForFontWithName(name):
|
|
142 |
## "Search known paths for AFM/PFB files describing T1 font with given name."
|
|
143 |
##
|
|
144 |
## join = os.path.join
|
|
145 |
## splitext = os.path.splitext
|
|
146 |
##
|
|
147 |
## afmFile = None
|
|
148 |
## pfbFile = None
|
|
149 |
##
|
|
150 |
## found = 0
|
|
151 |
## while not found:
|
|
152 |
## for p in rl_config.T1SearchPath:
|
|
153 |
## afmFiles = glob.glob(join(p, '*.[aA][fF][mM]'))
|
|
154 |
## for f in afmFiles:
|
|
155 |
## T1name = findFontName(f)
|
|
156 |
## if T1name == name:
|
|
157 |
## afmFile = f
|
|
158 |
## found = 1
|
|
159 |
## break
|
|
160 |
## if afmFile:
|
|
161 |
## break
|
|
162 |
## break
|
|
163 |
##
|
|
164 |
## if afmFile:
|
|
165 |
## pfbFile = glob.glob(join(splitext(afmFile)[0] + '.[pP][fF][bB]'))[0]
|
|
166 |
##
|
|
167 |
## return afmFile, pfbFile
|
|
168 |
##
|
|
169 |
##
|
|
170 |
##def registerFont(name):
|
|
171 |
## "Register Type-1 font for future use."
|
|
172 |
##
|
|
173 |
## rl_config.warnOnMissingFontGlyphs = 0
|
|
174 |
## rl_config.T1SearchPath.append(r'C:\Programme\Python21\reportlab\test')
|
|
175 |
##
|
|
176 |
## afmFile, pfbFile = locateFilesForFontWithName(name)
|
|
177 |
## if not afmFile and not pfbFile:
|
|
178 |
## raise FontFilesNotFoundError
|
|
179 |
##
|
|
180 |
## T1face = pdfmetrics.EmbeddedType1Face(afmFile, pfbFile)
|
|
181 |
## T1faceName = name
|
|
182 |
## pdfmetrics.registerTypeFace(T1face)
|
|
183 |
## T1font = pdfmetrics.Font(name, T1faceName, 'WinAnsiEncoding')
|
|
184 |
## pdfmetrics.registerFont(T1font)
|
|
185 |
|
|
186 |
|
|
187 |
def registerFont0(sourceFile, name, path):
|
|
188 |
"Register Type-1 font for future use, simple version."
|
|
189 |
|
|
190 |
rl_config.warnOnMissingFontGlyphs = 0
|
|
191 |
|
|
192 |
p = os.path.join(os.path.dirname(sourceFile), path)
|
|
193 |
afmFiles = glob.glob(p + '.[aA][fF][mM]')
|
|
194 |
pfbFiles = glob.glob(p + '.[pP][fF][bB]')
|
|
195 |
assert len(afmFiles) == len(pfbFiles) == 1, FontFilesNotFoundError
|
|
196 |
|
|
197 |
T1face = pdfmetrics.EmbeddedType1Face(afmFiles[0], pfbFiles[0])
|
|
198 |
T1faceName = name
|
|
199 |
pdfmetrics.registerTypeFace(T1face)
|
|
200 |
T1font = pdfmetrics.Font(name, T1faceName, 'WinAnsiEncoding')
|
|
201 |
pdfmetrics.registerFont(T1font)
|
|
202 |
|
|
203 |
#####################################################################
|
|
204 |
|
|
205 |
|
|
206 |
def checkColor(col):
|
|
207 |
"Converts a color name to an RGB tuple, if possible."
|
|
208 |
|
|
209 |
if type(col) == type('') and col in dir(colors):
|
|
210 |
col = getattr(colors, col)
|
|
211 |
col = (col.red, col.green, col.blue)
|
|
212 |
|
|
213 |
return col
|
|
214 |
|
|
215 |
|
|
216 |
def handleHiddenSlides(slides):
|
|
217 |
"""Filters slides from a list of slides.
|
|
218 |
|
|
219 |
In a sequence of hidden slides all but the last one are
|
|
220 |
removed. Also, the slide before the sequence of hidden
|
|
221 |
ones is removed.
|
|
222 |
|
|
223 |
This assumes to leave only those slides in the handout
|
|
224 |
that also appear in the outline, hoping to reduce se-
|
|
225 |
quences where each new slide only adds one new line
|
|
226 |
to a list of items...
|
|
227 |
"""
|
|
228 |
|
|
229 |
itd = indicesToDelete = map(lambda s:s.outlineEntry == None, slides)
|
|
230 |
|
|
231 |
for i in range(len(itd)-1):
|
|
232 |
if itd[i] == 1:
|
|
233 |
if itd[i+1] == 0:
|
|
234 |
itd[i] = 0
|
|
235 |
if i > 0 and itd[i-1] == 0:
|
|
236 |
itd[i-1] = 1
|
|
237 |
|
|
238 |
itd[len(itd)-1] = 0
|
|
239 |
|
|
240 |
for i in range(len(itd)):
|
|
241 |
if slides[i].outlineEntry:
|
|
242 |
curOutlineEntry = slides[i].outlineEntry
|
|
243 |
if itd[i] == 1:
|
|
244 |
slides[i].delete = 1
|
|
245 |
else:
|
|
246 |
slides[i].outlineEntry = curOutlineEntry
|
|
247 |
slides[i].delete = 0
|
|
248 |
|
|
249 |
slides = filter(lambda s:s.delete == 0, slides)
|
|
250 |
|
|
251 |
return slides
|
|
252 |
|
|
253 |
|
|
254 |
def makeSlideTable(slides, pageSize, docWidth, numCols):
|
|
255 |
"""Returns a table containing a collection of SlideWrapper flowables.
|
|
256 |
"""
|
|
257 |
|
|
258 |
slides = handleHiddenSlides(slides)
|
|
259 |
|
|
260 |
# Set table style.
|
|
261 |
tabStyle = TableStyle(
|
|
262 |
[('GRID', (0,0), (-1,-1), 0.25, colors.black),
|
|
263 |
('ALIGN', (0,0), (-1,-1), 'CENTRE')
|
|
264 |
])
|
|
265 |
|
|
266 |
# Build table content.
|
|
267 |
width = docWidth/numCols
|
|
268 |
height = width * pageSize[1]/pageSize[0]
|
|
269 |
matrix = []
|
|
270 |
row = []
|
|
271 |
for slide in slides:
|
|
272 |
sw = SlideWrapper(width, height, slide, pageSize)
|
|
273 |
if (len(row)) < numCols:
|
|
274 |
row.append(sw)
|
|
275 |
else:
|
|
276 |
matrix.append(row)
|
|
277 |
row = []
|
|
278 |
row.append(sw)
|
|
279 |
if len(row) > 0:
|
|
280 |
for i in range(numCols-len(row)):
|
|
281 |
row.append('')
|
|
282 |
matrix.append(row)
|
|
283 |
|
|
284 |
# Make Table flowable.
|
|
285 |
t = Table(matrix,
|
|
286 |
[width + 5]*len(matrix[0]),
|
|
287 |
[height + 5]*len(matrix))
|
|
288 |
t.setStyle(tabStyle)
|
|
289 |
|
|
290 |
return t
|
|
291 |
|
|
292 |
|
|
293 |
class SlideWrapper(Flowable):
|
|
294 |
"""A Flowable wrapping a PPSlide object.
|
|
295 |
"""
|
|
296 |
|
|
297 |
def __init__(self, width, height, slide, pageSize):
|
|
298 |
Flowable.__init__(self)
|
|
299 |
self.width = width
|
|
300 |
self.height = height
|
|
301 |
self.slide = slide
|
|
302 |
self.pageSize = pageSize
|
|
303 |
|
|
304 |
|
|
305 |
def __repr__(self):
|
|
306 |
return "SlideWrapper(w=%s, h=%s)" % (self.width, self.height)
|
|
307 |
|
|
308 |
|
|
309 |
def draw(self):
|
|
310 |
"Draw the slide in our relative coordinate system."
|
|
311 |
|
|
312 |
slide = self.slide
|
|
313 |
pageSize = self.pageSize
|
|
314 |
canv = self.canv
|
|
315 |
|
|
316 |
canv.saveState()
|
|
317 |
canv.scale(self.width/pageSize[0], self.height/pageSize[1])
|
|
318 |
slide.effectName = None
|
|
319 |
slide.drawOn(self.canv)
|
|
320 |
canv.restoreState()
|
|
321 |
|
|
322 |
|
|
323 |
class PPPresentation:
|
|
324 |
def __init__(self):
|
|
325 |
self.sourceFilename = None
|
|
326 |
self.filename = None
|
|
327 |
self.outDir = None
|
|
328 |
self.description = None
|
|
329 |
self.title = None
|
|
330 |
self.author = None
|
|
331 |
self.subject = None
|
|
332 |
self.notes = 0 # different printing mode
|
|
333 |
self.handout = 0 # prints many slides per page
|
|
334 |
self.printout = 0 # remove hidden slides
|
|
335 |
self.cols = 0 # columns per handout page
|
|
336 |
self.slides = []
|
|
337 |
self.effectName = None
|
|
338 |
self.showOutline = 1 #should it be displayed when opening?
|
|
339 |
self.compression = rl_config.pageCompression
|
|
340 |
self.pageDuration = None
|
|
341 |
#assume landscape
|
|
342 |
self.pageWidth = rl_config.defaultPageSize[1]
|
|
343 |
self.pageHeight = rl_config.defaultPageSize[0]
|
|
344 |
self.verbose = rl_config.verbose
|
|
345 |
|
|
346 |
|
|
347 |
def saveAsPresentation(self):
|
|
348 |
"""Write the PDF document, one slide per page."""
|
|
349 |
if self.verbose:
|
|
350 |
print 'saving presentation...'
|
|
351 |
pageSize = (self.pageWidth, self.pageHeight)
|
|
352 |
if self.sourceFilename:
|
|
353 |
filename = os.path.splitext(self.sourceFilename)[0] + '.pdf'
|
|
354 |
if self.outDir: filename = os.path.join(self.outDir,os.path.basename(filename))
|
|
355 |
if self.verbose:
|
|
356 |
print filename
|
|
357 |
#canv = canvas.Canvas(filename, pagesize = pageSize)
|
|
358 |
outfile = getStringIO()
|
|
359 |
if self.notes:
|
|
360 |
#translate the page from landscape to portrait
|
|
361 |
pageSize= pageSize[1], pageSize[0]
|
|
362 |
canv = canvas.Canvas(outfile, pagesize = pageSize)
|
|
363 |
canv.setPageCompression(self.compression)
|
|
364 |
canv.setPageDuration(self.pageDuration)
|
|
365 |
if self.title:
|
|
366 |
canv.setTitle(self.title)
|
|
367 |
if self.author:
|
|
368 |
canv.setAuthor(self.author)
|
|
369 |
if self.subject:
|
|
370 |
canv.setSubject(self.subject)
|
|
371 |
|
|
372 |
slideNo = 0
|
|
373 |
for slide in self.slides:
|
|
374 |
#need diagnostic output if something wrong with XML
|
|
375 |
slideNo = slideNo + 1
|
|
376 |
if self.verbose:
|
|
377 |
print 'doing slide %d, id = %s' % (slideNo, slide.id)
|
|
378 |
if self.notes:
|
|
379 |
#frame and shift the slide
|
|
380 |
#canv.scale(0.67, 0.67)
|
|
381 |
scale_amt = (min(pageSize)/float(max(pageSize)))*.95
|
|
382 |
#canv.translate(self.pageWidth / 6.0, self.pageHeight / 3.0)
|
|
383 |
#canv.translate(self.pageWidth / 2.0, .025*self.pageHeight)
|
|
384 |
canv.translate(.025*self.pageHeight, (self.pageWidth/2.0) + 5)
|
|
385 |
#canv.rotate(90)
|
|
386 |
canv.scale(scale_amt, scale_amt)
|
|
387 |
canv.rect(0,0,self.pageWidth, self.pageHeight)
|
|
388 |
slide.drawOn(canv)
|
|
389 |
canv.showPage()
|
|
390 |
|
|
391 |
#ensure outline visible by default
|
|
392 |
if self.showOutline:
|
|
393 |
canv.showOutline()
|
|
394 |
|
|
395 |
canv.save()
|
|
396 |
return self.savetofile(outfile, filename)
|
|
397 |
|
|
398 |
|
|
399 |
def saveAsHandout(self):
|
|
400 |
"""Write the PDF document, multiple slides per page."""
|
|
401 |
|
|
402 |
styleSheet = getSampleStyleSheet()
|
|
403 |
h1 = styleSheet['Heading1']
|
|
404 |
bt = styleSheet['BodyText']
|
|
405 |
|
|
406 |
if self.sourceFilename :
|
|
407 |
filename = os.path.splitext(self.sourceFilename)[0] + '.pdf'
|
|
408 |
|
|
409 |
outfile = getStringIO()
|
|
410 |
doc = SimpleDocTemplate(outfile, pagesize=rl_config.defaultPageSize, showBoundary=0)
|
|
411 |
doc.leftMargin = 1*cm
|
|
412 |
doc.rightMargin = 1*cm
|
|
413 |
doc.topMargin = 2*cm
|
|
414 |
doc.bottomMargin = 2*cm
|
|
415 |
multiPageWidth = rl_config.defaultPageSize[0] - doc.leftMargin - doc.rightMargin - 50
|
|
416 |
|
|
417 |
story = []
|
|
418 |
orgFullPageSize = (self.pageWidth, self.pageHeight)
|
|
419 |
t = makeSlideTable(self.slides, orgFullPageSize, multiPageWidth, self.cols)
|
|
420 |
story.append(t)
|
|
421 |
|
|
422 |
## #ensure outline visible by default
|
|
423 |
## if self.showOutline:
|
|
424 |
## doc.canv.showOutline()
|
|
425 |
|
|
426 |
doc.build(story)
|
|
427 |
return self.savetofile(outfile, filename)
|
|
428 |
|
|
429 |
def savetofile(self, pseudofile, filename):
|
|
430 |
"""Save the pseudo file to disk and return its content as a
|
|
431 |
string of text."""
|
|
432 |
pseudofile.flush()
|
|
433 |
content = pseudofile.getvalue()
|
|
434 |
pseudofile.close()
|
|
435 |
if filename :
|
|
436 |
outf = open(filename, "wb")
|
|
437 |
outf.write(content)
|
|
438 |
outf.close()
|
|
439 |
return content
|
|
440 |
|
|
441 |
|
|
442 |
|
|
443 |
def save(self):
|
|
444 |
"Save the PDF document."
|
|
445 |
|
|
446 |
if self.handout:
|
|
447 |
return self.saveAsHandout()
|
|
448 |
else:
|
|
449 |
return self.saveAsPresentation()
|
|
450 |
|
|
451 |
|
|
452 |
#class PPSection:
|
|
453 |
# """A section can hold graphics which will be drawn on all
|
|
454 |
# pages within it, before frames and other content are done.
|
|
455 |
# In other words, a background template."""
|
|
456 |
# def __init__(self, name):
|
|
457 |
# self.name = name
|
|
458 |
# self.graphics = []
|
|
459 |
#
|
|
460 |
# def drawOn(self, canv):
|
|
461 |
# for graphic in self.graphics:
|
|
462 |
### graphic.drawOn(canv)
|
|
463 |
#
|
|
464 |
# name = str(hash(graphic))
|
|
465 |
# internalname = canv._doc.hasForm(name)
|
|
466 |
#
|
|
467 |
# canv.saveState()
|
|
468 |
# if not internalname:
|
|
469 |
# canv.beginForm(name)
|
|
470 |
# graphic.drawOn(canv)
|
|
471 |
# canv.endForm()
|
|
472 |
# canv.doForm(name)
|
|
473 |
# else:
|
|
474 |
# canv.doForm(name)
|
|
475 |
# canv.restoreState()
|
|
476 |
|
|
477 |
|
|
478 |
definedForms = {}
|
|
479 |
|
|
480 |
class PPSection:
|
|
481 |
"""A section can hold graphics which will be drawn on all
|
|
482 |
pages within it, before frames and other content are done.
|
|
483 |
In other words, a background template."""
|
|
484 |
|
|
485 |
def __init__(self, name):
|
|
486 |
self.name = name
|
|
487 |
self.graphics = []
|
|
488 |
|
|
489 |
def drawOn(self, canv):
|
|
490 |
for graphic in self.graphics:
|
|
491 |
graphic.drawOn(canv)
|
|
492 |
continue
|
|
493 |
name = str(hash(graphic))
|
|
494 |
#internalname = canv._doc.hasForm(name)
|
|
495 |
if definedForms.has_key(name):
|
|
496 |
internalname = 1
|
|
497 |
else:
|
|
498 |
internalname = None
|
|
499 |
definedForms[name] = 1
|
|
500 |
if not internalname:
|
|
501 |
canv.beginForm(name)
|
|
502 |
canv.saveState()
|
|
503 |
graphic.drawOn(canv)
|
|
504 |
canv.restoreState()
|
|
505 |
canv.endForm()
|
|
506 |
canv.doForm(name)
|
|
507 |
else:
|
|
508 |
canv.doForm(name)
|
|
509 |
|
|
510 |
|
|
511 |
class PPNotes:
|
|
512 |
def __init__(self):
|
|
513 |
self.content = []
|
|
514 |
|
|
515 |
def drawOn(self, canv):
|
|
516 |
print self.content
|
|
517 |
|
|
518 |
|
|
519 |
class PPSlide:
|
|
520 |
def __init__(self):
|
|
521 |
self.id = None
|
|
522 |
self.title = None
|
|
523 |
self.outlineEntry = None
|
|
524 |
self.outlineLevel = 0 # can be higher for sub-headings
|
|
525 |
self.effectName = None
|
|
526 |
self.effectDirection = 0
|
|
527 |
self.effectDimension = 'H'
|
|
528 |
self.effectMotion = 'I'
|
|
529 |
self.effectDuration = 1
|
|
530 |
self.frames = []
|
|
531 |
self.notes = []
|
|
532 |
self.graphics = []
|
|
533 |
self.section = None
|
|
534 |
|
|
535 |
def drawOn(self, canv):
|
|
536 |
if self.effectName:
|
|
537 |
canv.setPageTransition(
|
|
538 |
effectname=self.effectName,
|
|
539 |
direction = self.effectDirection,
|
|
540 |
dimension = self.effectDimension,
|
|
541 |
motion = self.effectMotion,
|
|
542 |
duration = self.effectDuration
|
|
543 |
)
|
|
544 |
|
|
545 |
if self.outlineEntry:
|
|
546 |
#gets an outline automatically
|
|
547 |
self.showOutline = 1
|
|
548 |
#put an outline entry in the left pane
|
|
549 |
tag = self.title
|
|
550 |
canv.bookmarkPage(tag)
|
|
551 |
canv.addOutlineEntry(tag, tag, self.outlineLevel)
|
|
552 |
|
|
553 |
if self.section:
|
|
554 |
self.section.drawOn(canv)
|
|
555 |
|
|
556 |
for graphic in self.graphics:
|
|
557 |
graphic.drawOn(canv)
|
|
558 |
|
|
559 |
for frame in self.frames:
|
|
560 |
frame.drawOn(canv)
|
|
561 |
|
|
562 |
## # Need to draw the notes *somewhere*...
|
|
563 |
## for note in self.notes:
|
|
564 |
## print note
|
|
565 |
|
|
566 |
|
|
567 |
class PPFrame:
|
|
568 |
def __init__(self, x, y, width, height):
|
|
569 |
self.x = x
|
|
570 |
self.y = y
|
|
571 |
self.width = width
|
|
572 |
self.height = height
|
|
573 |
self.content = []
|
|
574 |
self.showBoundary = 0
|
|
575 |
|
|
576 |
def drawOn(self, canv):
|
|
577 |
#make a frame
|
|
578 |
frame = Frame( self.x,
|
|
579 |
self.y,
|
|
580 |
self.width,
|
|
581 |
self.height
|
|
582 |
)
|
|
583 |
frame.showBoundary = self.showBoundary
|
|
584 |
|
|
585 |
#build a story for the frame
|
|
586 |
story = []
|
|
587 |
for thingy in self.content:
|
|
588 |
#ask it for any flowables
|
|
589 |
story.append(thingy.getFlowable())
|
|
590 |
#draw it
|
|
591 |
frame.addFromList(story,canv)
|
|
592 |
|
|
593 |
|
|
594 |
class PPPara:
|
|
595 |
"""This is a placeholder for a paragraph."""
|
|
596 |
def __init__(self):
|
|
597 |
self.rawtext = ''
|
|
598 |
self.style = None
|
|
599 |
|
|
600 |
def escapeAgain(self, text):
|
|
601 |
"""The XML has been parsed once, so '>' became '>'
|
|
602 |
in rawtext. We need to escape this to get back to
|
|
603 |
something the Platypus parser can accept"""
|
|
604 |
pass
|
|
605 |
|
|
606 |
def getFlowable(self):
|
|
607 |
## print 'rawText for para:'
|
|
608 |
## print repr(self.rawtext)
|
|
609 |
p = Paragraph(
|
|
610 |
self.rawtext,
|
|
611 |
getStyles()[self.style],
|
|
612 |
self.bulletText
|
|
613 |
)
|
|
614 |
return p
|
|
615 |
|
|
616 |
|
|
617 |
class PPPreformattedText:
|
|
618 |
"""Use this for source code, or stuff you do not want to wrap"""
|
|
619 |
def __init__(self):
|
|
620 |
self.rawtext = ''
|
|
621 |
self.style = None
|
|
622 |
|
|
623 |
def getFlowable(self):
|
|
624 |
return Preformatted(self.rawtext, getStyles()[self.style])
|
|
625 |
|
|
626 |
|
|
627 |
class PPPythonCode:
|
|
628 |
"""Use this for colored Python source code"""
|
|
629 |
def __init__(self):
|
|
630 |
self.rawtext = ''
|
|
631 |
self.style = None
|
|
632 |
|
|
633 |
def getFlowable(self):
|
|
634 |
return PythonPreformatted(self.rawtext, getStyles()[self.style])
|
|
635 |
|
|
636 |
|
|
637 |
class PPImage:
|
|
638 |
"""Flowing image within the text"""
|
|
639 |
def __init__(self):
|
|
640 |
self.filename = None
|
|
641 |
self.width = None
|
|
642 |
self.height = None
|
|
643 |
|
|
644 |
def getFlowable(self):
|
|
645 |
return Image(self.filename, self.width, self.height)
|
|
646 |
|
|
647 |
|
|
648 |
class PPTable:
|
|
649 |
"""Designed for bulk loading of data for use in presentations."""
|
|
650 |
def __init__(self):
|
|
651 |
self.rawBlocks = [] #parser stuffs things in here...
|
|
652 |
self.fieldDelim = ',' #tag args can override
|
|
653 |
self.rowDelim = '\n' #tag args can override
|
|
654 |
self.data = None
|
|
655 |
self.style = None #tag args must specify
|
|
656 |
self.widths = None #tag args can override
|
|
657 |
self.heights = None #tag args can override
|
|
658 |
|
|
659 |
def getFlowable(self):
|
|
660 |
self.parseData()
|
|
661 |
t = Table(
|
|
662 |
self.data,
|
|
663 |
self.widths,
|
|
664 |
self.heights)
|
|
665 |
if self.style:
|
|
666 |
t.setStyle(getStyles()[self.style])
|
|
667 |
|
|
668 |
return t
|
|
669 |
|
|
670 |
def parseData(self):
|
|
671 |
"""Try to make sense of the table data!"""
|
|
672 |
rawdata = string.strip(string.join(self.rawBlocks, ''))
|
|
673 |
lines = string.split(rawdata, self.rowDelim)
|
|
674 |
#clean up...
|
|
675 |
lines = map(string.strip, lines)
|
|
676 |
self.data = []
|
|
677 |
for line in lines:
|
|
678 |
cells = string.split(line, self.fieldDelim)
|
|
679 |
self.data.append(cells)
|
|
680 |
|
|
681 |
#get the width list if not given
|
|
682 |
if not self.widths:
|
|
683 |
self.widths = [None] * len(self.data[0])
|
|
684 |
if not self.heights:
|
|
685 |
self.heights = [None] * len(self.data)
|
|
686 |
|
|
687 |
## import pprint
|
|
688 |
## print 'table data:'
|
|
689 |
## print 'style=',self.style
|
|
690 |
## print 'widths=',self.widths
|
|
691 |
## print 'heights=',self.heights
|
|
692 |
## print 'fieldDelim=',repr(self.fieldDelim)
|
|
693 |
## print 'rowDelim=',repr(self.rowDelim)
|
|
694 |
## pprint.pprint(self.data)
|
|
695 |
|
|
696 |
|
|
697 |
class PPSpacer:
|
|
698 |
def __init__(self):
|
|
699 |
self.height = 24 #points
|
|
700 |
|
|
701 |
def getFlowable(self):
|
|
702 |
return Spacer(72, self.height)
|
|
703 |
|
|
704 |
|
|
705 |
#############################################################
|
|
706 |
#
|
|
707 |
# The following are things you can draw on a page directly.
|
|
708 |
#
|
|
709 |
##############################################################
|
|
710 |
|
|
711 |
##class PPDrawingElement:
|
|
712 |
## """Base class for something which you draw directly on the page."""
|
|
713 |
## def drawOn(self, canv):
|
|
714 |
## raise "NotImplementedError", "Abstract base class!"
|
|
715 |
|
|
716 |
|
|
717 |
class PPFixedImage:
|
|
718 |
"""You place this on the page, rather than flowing it"""
|
|
719 |
def __init__(self):
|
|
720 |
self.filename = None
|
|
721 |
self.x = 0
|
|
722 |
self.y = 0
|
|
723 |
self.width = None
|
|
724 |
self.height = None
|
|
725 |
|
|
726 |
def drawOn(self, canv):
|
|
727 |
if self.filename:
|
|
728 |
x, y = self.x, self.y
|
|
729 |
w, h = self.width, self.height
|
|
730 |
canv.drawImage(self.filename, x, y, w, h)
|
|
731 |
|
|
732 |
|
|
733 |
class PPRectangle:
|
|
734 |
def __init__(self, x, y, width, height):
|
|
735 |
self.x = x
|
|
736 |
self.y = y
|
|
737 |
self.width = width
|
|
738 |
self.height = height
|
|
739 |
self.fillColor = None
|
|
740 |
self.strokeColor = (1,1,1)
|
|
741 |
self.lineWidth=0
|
|
742 |
|
|
743 |
def drawOn(self, canv):
|
|
744 |
canv.saveState()
|
|
745 |
canv.setLineWidth(self.lineWidth)
|
|
746 |
if self.fillColor:
|
|
747 |
r,g,b = checkColor(self.fillColor)
|
|
748 |
canv.setFillColorRGB(r,g,b)
|
|
749 |
if self.strokeColor:
|
|
750 |
r,g,b = checkColor(self.strokeColor)
|
|
751 |
canv.setStrokeColorRGB(r,g,b)
|
|
752 |
canv.rect(self.x, self.y, self.width, self.height,
|
|
753 |
stroke=(self.strokeColor<>None),
|
|
754 |
fill = (self.fillColor<>None)
|
|
755 |
)
|
|
756 |
canv.restoreState()
|
|
757 |
|
|
758 |
|
|
759 |
class PPRoundRect:
|
|
760 |
def __init__(self, x, y, width, height, radius):
|
|
761 |
self.x = x
|
|
762 |
self.y = y
|
|
763 |
self.width = width
|
|
764 |
self.height = height
|
|
765 |
self.radius = radius
|
|
766 |
self.fillColor = None
|
|
767 |
self.strokeColor = (1,1,1)
|
|
768 |
self.lineWidth=0
|
|
769 |
|
|
770 |
def drawOn(self, canv):
|
|
771 |
canv.saveState()
|
|
772 |
canv.setLineWidth(self.lineWidth)
|
|
773 |
if self.fillColor:
|
|
774 |
r,g,b = checkColor(self.fillColor)
|
|
775 |
canv.setFillColorRGB(r,g,b)
|
|
776 |
if self.strokeColor:
|
|
777 |
r,g,b = checkColor(self.strokeColor)
|
|
778 |
canv.setStrokeColorRGB(r,g,b)
|
|
779 |
canv.roundRect(self.x, self.y, self.width, self.height,
|
|
780 |
self.radius,
|
|
781 |
stroke=(self.strokeColor<>None),
|
|
782 |
fill = (self.fillColor<>None)
|
|
783 |
)
|
|
784 |
canv.restoreState()
|
|
785 |
|
|
786 |
|
|
787 |
class PPLine:
|
|
788 |
def __init__(self, x1, y1, x2, y2):
|
|
789 |
self.x1 = x1
|
|
790 |
self.y1 = y1
|
|
791 |
self.x2 = x2
|
|
792 |
self.y2 = y2
|
|
793 |
self.fillColor = None
|
|
794 |
self.strokeColor = (1,1,1)
|
|
795 |
self.lineWidth=0
|
|
796 |
|
|
797 |
def drawOn(self, canv):
|
|
798 |
canv.saveState()
|
|
799 |
canv.setLineWidth(self.lineWidth)
|
|
800 |
if self.strokeColor:
|
|
801 |
r,g,b = checkColor(self.strokeColor)
|
|
802 |
canv.setStrokeColorRGB(r,g,b)
|
|
803 |
canv.line(self.x1, self.y1, self.x2, self.y2)
|
|
804 |
canv.restoreState()
|
|
805 |
|
|
806 |
|
|
807 |
class PPEllipse:
|
|
808 |
def __init__(self, x1, y1, x2, y2):
|
|
809 |
self.x1 = x1
|
|
810 |
self.y1 = y1
|
|
811 |
self.x2 = x2
|
|
812 |
self.y2 = y2
|
|
813 |
self.fillColor = None
|
|
814 |
self.strokeColor = (1,1,1)
|
|
815 |
self.lineWidth=0
|
|
816 |
|
|
817 |
def drawOn(self, canv):
|
|
818 |
canv.saveState()
|
|
819 |
canv.setLineWidth(self.lineWidth)
|
|
820 |
if self.strokeColor:
|
|
821 |
r,g,b = checkColor(self.strokeColor)
|
|
822 |
canv.setStrokeColorRGB(r,g,b)
|
|
823 |
if self.fillColor:
|
|
824 |
r,g,b = checkColor(self.fillColor)
|
|
825 |
canv.setFillColorRGB(r,g,b)
|
|
826 |
canv.ellipse(self.x1, self.y1, self.x2, self.y2,
|
|
827 |
stroke=(self.strokeColor<>None),
|
|
828 |
fill = (self.fillColor<>None)
|
|
829 |
)
|
|
830 |
canv.restoreState()
|
|
831 |
|
|
832 |
|
|
833 |
class PPPolygon:
|
|
834 |
def __init__(self, pointlist):
|
|
835 |
self.points = pointlist
|
|
836 |
self.fillColor = None
|
|
837 |
self.strokeColor = (1,1,1)
|
|
838 |
self.lineWidth=0
|
|
839 |
|
|
840 |
def drawOn(self, canv):
|
|
841 |
canv.saveState()
|
|
842 |
canv.setLineWidth(self.lineWidth)
|
|
843 |
if self.strokeColor:
|
|
844 |
r,g,b = checkColor(self.strokeColor)
|
|
845 |
canv.setStrokeColorRGB(r,g,b)
|
|
846 |
if self.fillColor:
|
|
847 |
r,g,b = checkColor(self.fillColor)
|
|
848 |
canv.setFillColorRGB(r,g,b)
|
|
849 |
|
|
850 |
path = canv.beginPath()
|
|
851 |
(x,y) = self.points[0]
|
|
852 |
path.moveTo(x,y)
|
|
853 |
for (x,y) in self.points[1:]:
|
|
854 |
path.lineTo(x,y)
|
|
855 |
path.close()
|
|
856 |
canv.drawPath(path,
|
|
857 |
stroke=(self.strokeColor<>None),
|
|
858 |
fill=(self.fillColor<>None))
|
|
859 |
canv.restoreState()
|
|
860 |
|
|
861 |
|
|
862 |
class PPString:
|
|
863 |
def __init__(self, x, y):
|
|
864 |
self.text = ''
|
|
865 |
self.x = x
|
|
866 |
self.y = y
|
|
867 |
self.align = TA_LEFT
|
|
868 |
self.font = 'Times-Roman'
|
|
869 |
self.size = 12
|
|
870 |
self.color = (0,0,0)
|
|
871 |
self.hasInfo = 0 # these can have data substituted into them
|
|
872 |
|
|
873 |
def normalizeText(self):
|
|
874 |
"""It contains literal XML text typed over several lines.
|
|
875 |
We want to throw away
|
|
876 |
tabs, newlines and so on, and only accept embedded string
|
|
877 |
like '\n'"""
|
|
878 |
lines = string.split(self.text, '\n')
|
|
879 |
newtext = []
|
|
880 |
for line in lines:
|
|
881 |
newtext.append(string.strip(line))
|
|
882 |
#accept all the '\n' as newlines
|
|
883 |
|
|
884 |
self.text = newtext
|
|
885 |
|
|
886 |
def drawOn(self, canv):
|
|
887 |
# for a string in a section, this will be drawn several times;
|
|
888 |
# so any substitution into the text should be in a temporary
|
|
889 |
# variable
|
|
890 |
if self.hasInfo:
|
|
891 |
# provide a dictionary of stuff which might go into
|
|
892 |
# the string, so they can number pages, do headers
|
|
893 |
# etc.
|
|
894 |
info = {}
|
|
895 |
info['title'] = canv._doc.info.title
|
|
896 |
info['author'] = canv._doc.info.author
|
|
897 |
info['subject'] = canv._doc.info.subject
|
|
898 |
info['page'] = canv.getPageNumber()
|
|
899 |
drawText = self.text % info
|
|
900 |
else:
|
|
901 |
drawText = self.text
|
|
902 |
|
|
903 |
if self.color is None:
|
|
904 |
return
|
|
905 |
lines = string.split(string.strip(drawText), '\\n')
|
|
906 |
canv.saveState()
|
|
907 |
|
|
908 |
canv.setFont(self.font, self.size)
|
|
909 |
|
|
910 |
r,g,b = checkColor(self.color)
|
|
911 |
canv.setFillColorRGB(r,g,b)
|
|
912 |
cur_y = self.y
|
|
913 |
for line in lines:
|
|
914 |
if self.align == TA_LEFT:
|
|
915 |
canv.drawString(self.x, cur_y, line)
|
|
916 |
elif self.align == TA_CENTER:
|
|
917 |
canv.drawCentredString(self.x, cur_y, line)
|
|
918 |
elif self.align == TA_RIGHT:
|
|
919 |
canv.drawRightString(self.x, cur_y, line)
|
|
920 |
cur_y = cur_y - 1.2*self.size
|
|
921 |
|
|
922 |
canv.restoreState()
|
|
923 |
|
|
924 |
class PPDrawing:
|
|
925 |
def __init__(self):
|
|
926 |
self.drawing = None
|
|
927 |
def getFlowable(self):
|
|
928 |
return self.drawing
|
|
929 |
|
|
930 |
class PPFigure:
|
|
931 |
def __init__(self):
|
|
932 |
self.figure = None
|
|
933 |
def getFlowable(self):
|
|
934 |
return self.figure
|
|
935 |
|
|
936 |
def getSampleStyleSheet():
|
|
937 |
from reportlab.tools.pythonpoint.styles.standard import getParagraphStyles
|
|
938 |
return getParagraphStyles()
|
|
939 |
|
|
940 |
|
|
941 |
#make a singleton and a function to access it
|
|
942 |
_styles = None
|
|
943 |
def getStyles():
|
|
944 |
global _styles
|
|
945 |
if not _styles:
|
|
946 |
_styles = getSampleStyleSheet()
|
|
947 |
return _styles
|
|
948 |
|
|
949 |
|
|
950 |
def setStyles(newStyleSheet):
|
|
951 |
global _styles
|
|
952 |
_styles = newStyleSheet
|
|
953 |
|
|
954 |
_pyRXP_Parser = None
|
|
955 |
def validate(rawdata):
|
|
956 |
global _pyRXP_Parser
|
|
957 |
if not _pyRXP_Parser:
|
|
958 |
try:
|
|
959 |
import pyRXP
|
|
960 |
except ImportError:
|
|
961 |
return
|
|
962 |
from reportlab.lib.utils import open_and_read, _RL_DIR, rl_isfile
|
|
963 |
dtd = 'pythonpoint.dtd'
|
|
964 |
if not rl_isfile(dtd):
|
|
965 |
dtd = os.path.join(_RL_DIR,'tools','pythonpoint','pythonpoint.dtd')
|
|
966 |
if not rl_isfile(dtd): return
|
|
967 |
def eocb(URI,dtdText=open_and_read(dtd),dtd=dtd):
|
|
968 |
if os.path.basename(URI)=='pythonpoint.dtd': return dtd,dtdText
|
|
969 |
return URI
|
|
970 |
_pyRXP_Parser = pyRXP.Parser(eoCB=eocb)
|
|
971 |
return _pyRXP_Parser.parse(rawdata)
|
|
972 |
|
|
973 |
def process(datafile, notes=0, handout=0, printout=0, cols=0, verbose=0, outDir=None, datafilename=None, fx=1):
|
|
974 |
"Process one PythonPoint source file."
|
|
975 |
if not hasattr(datafile, "read"):
|
|
976 |
if not datafilename: datafilename = datafile
|
|
977 |
datafile = open(datafile)
|
|
978 |
else:
|
|
979 |
if not datafilename: datafilename = "PseudoFile"
|
|
980 |
rawdata = datafile.read()
|
|
981 |
|
|
982 |
#if pyRXP present, use it to check and get line numbers for errors...
|
|
983 |
validate(rawdata)
|
|
984 |
return _process(rawdata, datafilename, notes, handout, printout, cols, verbose, outDir, fx)
|
|
985 |
|
|
986 |
def _process(rawdata, datafilename, notes=0, handout=0, printout=0, cols=0, verbose=0, outDir=None, fx=1):
|
|
987 |
#print 'inner process fx=%d' % fx
|
|
988 |
from reportlab.tools.pythonpoint.stdparser import PPMLParser
|
|
989 |
parser = PPMLParser()
|
|
990 |
parser.fx = fx
|
|
991 |
parser.sourceFilename = datafilename
|
|
992 |
parser.feed(rawdata)
|
|
993 |
pres = parser.getPresentation()
|
|
994 |
pres.sourceFilename = datafilename
|
|
995 |
pres.outDir = outDir
|
|
996 |
pres.notes = notes
|
|
997 |
pres.handout = handout
|
|
998 |
pres.printout = printout
|
|
999 |
pres.cols = cols
|
|
1000 |
pres.verbose = verbose
|
|
1001 |
|
|
1002 |
if printout:
|
|
1003 |
pres.slides = handleHiddenSlides(pres.slides)
|
|
1004 |
|
|
1005 |
#this does all the work
|
|
1006 |
pdfcontent = pres.save()
|
|
1007 |
|
|
1008 |
if verbose:
|
|
1009 |
print 'saved presentation %s.pdf' % os.path.splitext(datafilename)[0]
|
|
1010 |
parser.close()
|
|
1011 |
|
|
1012 |
return pdfcontent
|
|
1013 |
##class P:
|
|
1014 |
## def feed(self, text):
|
|
1015 |
## parser = stdparser.PPMLParser()
|
|
1016 |
## d = pyRXP.parse(text)
|
|
1017 |
##
|
|
1018 |
##
|
|
1019 |
##def process2(datafilename, notes=0, handout=0, cols=0):
|
|
1020 |
## "Process one PythonPoint source file."
|
|
1021 |
##
|
|
1022 |
## import pyRXP, pprint
|
|
1023 |
##
|
|
1024 |
## rawdata = open(datafilename).read()
|
|
1025 |
## d = pyRXP.parse(rawdata)
|
|
1026 |
## pprint.pprint(d)
|
|
1027 |
|
|
1028 |
|
|
1029 |
def handleOptions():
|
|
1030 |
# set defaults
|
|
1031 |
from reportlab import rl_config
|
|
1032 |
options = {'cols':2,
|
|
1033 |
'handout':0,
|
|
1034 |
'printout':0,
|
|
1035 |
'help':0,
|
|
1036 |
'notes':0,
|
|
1037 |
'fx':1,
|
|
1038 |
'verbose':rl_config.verbose,
|
|
1039 |
'silent':0,
|
|
1040 |
'outDir': None}
|
|
1041 |
|
|
1042 |
args = sys.argv[1:]
|
|
1043 |
args = filter(lambda x: x and x[0]=='-',args) + filter(lambda x: not x or x[0]!='-',args)
|
|
1044 |
try:
|
|
1045 |
shortOpts = 'hnvsx'
|
|
1046 |
longOpts = string.split('cols= outdir= handout help notes printout verbose silent nofx')
|
|
1047 |
optList, args = getopt.getopt(args, shortOpts, longOpts)
|
|
1048 |
except getopt.error, msg:
|
|
1049 |
options['help'] = 1
|
|
1050 |
|
|
1051 |
if not args and os.path.isfile('pythonpoint.xml'):
|
|
1052 |
args = ['pythonpoint.xml']
|
|
1053 |
|
|
1054 |
# Remove leading dashes (max. two).
|
|
1055 |
for i in range(len(optList)):
|
|
1056 |
o, v = optList[i]
|
|
1057 |
while o[0] == '-':
|
|
1058 |
o = o[1:]
|
|
1059 |
optList[i] = (o, v)
|
|
1060 |
|
|
1061 |
if o == 'cols': options['cols'] = int(v)
|
|
1062 |
elif o=='outdir': options['outDir'] = v
|
|
1063 |
|
|
1064 |
if filter(lambda ov: ov[0] == 'handout', optList):
|
|
1065 |
options['handout'] = 1
|
|
1066 |
|
|
1067 |
if filter(lambda ov: ov[0] == 'printout', optList):
|
|
1068 |
options['printout'] = 1
|
|
1069 |
|
|
1070 |
if optList == [] and args == [] or \
|
|
1071 |
filter(lambda ov: ov[0] in ('h', 'help'), optList):
|
|
1072 |
options['help'] = 1
|
|
1073 |
|
|
1074 |
if filter(lambda ov: ov[0] in ('n', 'notes'), optList):
|
|
1075 |
options['notes'] = 1
|
|
1076 |
|
|
1077 |
if filter(lambda ov: ov[0] in ('x', 'nofx'), optList):
|
|
1078 |
options['fx'] = 0
|
|
1079 |
|
|
1080 |
if filter(lambda ov: ov[0] in ('v', 'verbose'), optList):
|
|
1081 |
options['verbose'] = 1
|
|
1082 |
|
|
1083 |
#takes priority over verbose. Used by our test suite etc.
|
|
1084 |
#to ensure no output at all
|
|
1085 |
if filter(lambda ov: ov[0] in ('s', 'silent'), optList):
|
|
1086 |
options['silent'] = 1
|
|
1087 |
options['verbose'] = 0
|
|
1088 |
|
|
1089 |
|
|
1090 |
return options, args
|
|
1091 |
|
|
1092 |
def main():
|
|
1093 |
options, args = handleOptions()
|
|
1094 |
|
|
1095 |
if options['help']:
|
|
1096 |
print USAGE_MESSAGE
|
|
1097 |
sys.exit(0)
|
|
1098 |
|
|
1099 |
if options['verbose'] and options['notes']:
|
|
1100 |
print 'speaker notes mode'
|
|
1101 |
|
|
1102 |
if options['verbose'] and options['handout']:
|
|
1103 |
print 'handout mode'
|
|
1104 |
|
|
1105 |
if options['verbose'] and options['printout']:
|
|
1106 |
print 'printout mode'
|
|
1107 |
|
|
1108 |
if not options['fx']:
|
|
1109 |
print 'suppressing special effects'
|
|
1110 |
for fileGlobs in args:
|
|
1111 |
files = glob.glob(fileGlobs)
|
|
1112 |
if not files:
|
|
1113 |
print fileGlobs, "not found"
|
|
1114 |
return
|
|
1115 |
for datafile in files:
|
|
1116 |
if os.path.isfile(datafile):
|
|
1117 |
file = os.path.join(os.getcwd(), datafile)
|
|
1118 |
notes, handout, printout, cols, verbose, fx = options['notes'], options['handout'], options['printout'], options['cols'], options['verbose'], options['fx']
|
|
1119 |
process(file, notes, handout, printout, cols, verbose, options['outDir'], fx=fx)
|
|
1120 |
else:
|
|
1121 |
print 'Data file not found:', datafile
|
|
1122 |
|
|
1123 |
if __name__ == '__main__':
|
|
1124 |
main()
|