docs/userguide/genuserguide.py
author rgbecker
Wed, 25 Oct 2000 08:57:46 +0000
changeset 494 54257447cfe9
parent 444 f939b29eca9a
child 495 13cb53ed7fdf
permissions -rw-r--r--
Changed to indirect copyright
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
     1
#!/bin/env python
494
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 444
diff changeset
     2
#copyright ReportLab Inc. 2000
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 444
diff changeset
     3
#see license.txt for license details
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 444
diff changeset
     4
#history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/docs/userguide/genuserguide.py?cvsroot=reportlab
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 444
diff changeset
     5
#$Header: /tmp/reportlab/docs/userguide/genuserguide.py,v 1.36 2000/10/25 08:57:45 rgbecker Exp $
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 444
diff changeset
     6
__version__=''' $Id: genuserguide.py,v 1.36 2000/10/25 08:57:45 rgbecker Exp $ '''
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
     7
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
     8
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
     9
__doc__ = """
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
    10
This module contains the script for building the user guide.
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
    11
"""
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
    12
320
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
    13
import os, sys
334
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
    14
import string
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
    15
320
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
    16
sys.path.insert(0,os.path.join(os.path.dirname(sys.argv[0]),'..','tools'))
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
    17
from rltemplate import RLDocTemplate
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
    18
from stylesheet import getStyleSheet
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
    19
styleSheet = getStyleSheet()
310
cbec783cfb81 Documentation changes
rgbecker
parents: 308
diff changeset
    20
320
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
    21
#from reportlab.platypus.doctemplate import SimpleDocTemplate
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
    22
from reportlab.lib.units import inch
494
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 444
diff changeset
    23
from reportlab.lib.pagesizes import letter, A4
328
e0122856a912 Started on Tables added EmbeddedCode utility
rgbecker
parents: 323
diff changeset
    24
from reportlab.platypus import Paragraph, Spacer, Preformatted,\
344
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
    25
            PageBreak, CondPageBreak, Flowable, Table, TableStyle, \
441
4b7abf4f9565 Preformatted docco added
rgbecker
parents: 424
diff changeset
    26
            NextPageTemplate, KeepTogether, Image, XPreformatted
310
cbec783cfb81 Documentation changes
rgbecker
parents: 308
diff changeset
    27
from reportlab.lib.styles import ParagraphStyle
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
    28
from reportlab.lib import colors
317
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    29
from reportlab.lib.sequencer import getSequencer
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
    30
import examples
320
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
    31
import platdemos
328
e0122856a912 Started on Tables added EmbeddedCode utility
rgbecker
parents: 323
diff changeset
    32
import StringIO
370
d3ddde4cc30b begin app_demos.py
rgbecker
parents: 369
diff changeset
    33
appmode=0
318
03c9f114c621 Changes to heading structure
andy_robinson
parents: 317
diff changeset
    34
03c9f114c621 Changes to heading structure
andy_robinson
parents: 317
diff changeset
    35
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
    36
from reportlab.lib.corp import ReportLabLogo
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
    37
LOGO = ReportLabLogo(0.25*inch, 0.25*inch, inch, 0.75*inch)
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
    38
301
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
    39
from t_parse import Template
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
    40
QFcodetemplate = Template("X$X$", "X")
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
    41
QFreptemplate = Template("X^X^", "X")
320
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
    42
codesubst = "%s<font name=Courier>%s</font>"
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
    43
QFsubst = "%s<font name=Courier><i>%s</i></font>"
317
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    44
    
301
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
    45
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
    46
def quickfix(text):
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
    47
    """inside text find any subsequence of form $subsequence$.
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
    48
       Format the subsequence as code.  If similarly if text contains ^arg^
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
    49
       format the arg as replaceable.  The escape sequence for literal
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
    50
       $ is $\\$ (^ is ^\\^.
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
    51
    """
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
    52
    from string import join
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
    53
    for (template,subst) in [(QFcodetemplate, codesubst), (QFreptemplate, QFsubst)]:
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
    54
        fragment = text
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
    55
        parts = []
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
    56
        try:
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
    57
            while fragment:
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
    58
                try:
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
    59
                    (matches, index) = template.PARSE(fragment)
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
    60
                except: raise ValueError
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
    61
                else:
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
    62
                    [prefix, code] = matches
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
    63
                    if code == "\\":
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
    64
                        part = fragment[:index]
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
    65
                    else:
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
    66
                        part = subst % (prefix, code)
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
    67
                    parts.append(part)
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
    68
                    fragment = fragment[index:]
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
    69
        except ValueError:
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
    70
            parts.append(fragment)
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
    71
        text = join(parts, "")
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
    72
    return text
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
    73
#print quickfix("$testing$ testing $one$ ^two^ $three(^four^)$")
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
    74
320
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
    75
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
    76
310
cbec783cfb81 Documentation changes
rgbecker
parents: 308
diff changeset
    77
H1 = styleSheet['Heading1']
cbec783cfb81 Documentation changes
rgbecker
parents: 308
diff changeset
    78
H2 = styleSheet['Heading2']
317
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    79
H3 = styleSheet['Heading3']
323
5795e28c5910 Platypus Start
rgbecker
parents: 320
diff changeset
    80
H4 = styleSheet['Heading4']
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
    81
B = styleSheet['BodyText']
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
    82
BU = styleSheet['Bullet']
317
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    83
Comment = styleSheet['Comment']
344
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
    84
Centred = styleSheet['Centred']
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
    85
Caption = styleSheet['Caption']
317
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    86
318
03c9f114c621 Changes to heading structure
andy_robinson
parents: 317
diff changeset
    87
#set up numbering
03c9f114c621 Changes to heading structure
andy_robinson
parents: 317
diff changeset
    88
seq = getSequencer()
03c9f114c621 Changes to heading structure
andy_robinson
parents: 317
diff changeset
    89
seq.setFormat('Chapter','1')
03c9f114c621 Changes to heading structure
andy_robinson
parents: 317
diff changeset
    90
seq.setFormat('Section','1')
03c9f114c621 Changes to heading structure
andy_robinson
parents: 317
diff changeset
    91
seq.setFormat('Appendix','A')
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
    92
seq.setFormat('Figure', '1')
318
03c9f114c621 Changes to heading structure
andy_robinson
parents: 317
diff changeset
    93
seq.chain('Chapter','Section')
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
    94
seq.chain('Chapter','Figure')
318
03c9f114c621 Changes to heading structure
andy_robinson
parents: 317
diff changeset
    95
03c9f114c621 Changes to heading structure
andy_robinson
parents: 317
diff changeset
    96
320
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
    97
lessonnamestyle = H2
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
    98
discussiontextstyle = B
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
    99
exampletextstyle = styleSheet['Code']
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   100
# size for every example
283
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 273
diff changeset
   101
examplefunctionxinches = 5.5
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 273
diff changeset
   102
examplefunctionyinches = 3
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 273
diff changeset
   103
examplefunctiondisplaysizes = (examplefunctionxinches*inch, examplefunctionyinches*inch)
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   104
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   105
# for testing
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   106
def NOP(*x,**y):
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   107
    return None
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   108
323
5795e28c5910 Platypus Start
rgbecker
parents: 320
diff changeset
   109
def CPage(inches):
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   110
    getStory().append(CondPageBreak(inches*inch))
334
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   111
    
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   112
def newPage():
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   113
    getStory().append(PageBreak())
344
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   114
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   115
def nextTemplate(templName):
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   116
    f = NextPageTemplate(templName)
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   117
    getStory().append(f)
334
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   118
    
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   119
def disc(text, klass=Paragraph, style=discussiontextstyle):
301
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
   120
    text = quickfix(text)
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   121
    P = klass(text, style)
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   122
    getStory().append(P)
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   123
340
f3f2af39e7d7 More work on chapter 1
andy_robinson
parents: 337
diff changeset
   124
def restartList():
f3f2af39e7d7 More work on chapter 1
andy_robinson
parents: 337
diff changeset
   125
    getSequencer().reset('list1')
f3f2af39e7d7 More work on chapter 1
andy_robinson
parents: 337
diff changeset
   126
384
286a631ebdbc Added space, optional bullet and eg after spacing
rgbecker
parents: 381
diff changeset
   127
def list(text, doBullet=1):
286a631ebdbc Added space, optional bullet and eg after spacing
rgbecker
parents: 381
diff changeset
   128
    text=quickfix(text)
286a631ebdbc Added space, optional bullet and eg after spacing
rgbecker
parents: 381
diff changeset
   129
    if doBullet:
286a631ebdbc Added space, optional bullet and eg after spacing
rgbecker
parents: 381
diff changeset
   130
        text='<bullet><seq id="list1"/>.</bullet>'+text
340
f3f2af39e7d7 More work on chapter 1
andy_robinson
parents: 337
diff changeset
   131
    P = Paragraph(text, BU)
f3f2af39e7d7 More work on chapter 1
andy_robinson
parents: 337
diff changeset
   132
    getStory().append(P)
f3f2af39e7d7 More work on chapter 1
andy_robinson
parents: 337
diff changeset
   133
    
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   134
def bullet(text):
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   135
    text='<bullet><font name="Symbol">'+chr(183)+'</font></bullet>' + quickfix(text)
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   136
    P = Paragraph(text, BU)
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   137
    getStory().append(P)
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   138
    
384
286a631ebdbc Added space, optional bullet and eg after spacing
rgbecker
parents: 381
diff changeset
   139
def eg(text,before=0.1,after=0):
286a631ebdbc Added space, optional bullet and eg after spacing
rgbecker
parents: 381
diff changeset
   140
    space(before)
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   141
    disc(text, klass=Preformatted, style=exampletextstyle)
384
286a631ebdbc Added space, optional bullet and eg after spacing
rgbecker
parents: 381
diff changeset
   142
    space(after)
286a631ebdbc Added space, optional bullet and eg after spacing
rgbecker
parents: 381
diff changeset
   143
286a631ebdbc Added space, optional bullet and eg after spacing
rgbecker
parents: 381
diff changeset
   144
def space(inches=1./6):
286a631ebdbc Added space, optional bullet and eg after spacing
rgbecker
parents: 381
diff changeset
   145
	if inches: getStory().append(Spacer(0,inches*inch))
328
e0122856a912 Started on Tables added EmbeddedCode utility
rgbecker
parents: 323
diff changeset
   146
424
240ee4e6d0d7 Table cell updates
rgbecker
parents: 400
diff changeset
   147
def EmbeddedCode(code,name='t'):
328
e0122856a912 Started on Tables added EmbeddedCode utility
rgbecker
parents: 323
diff changeset
   148
    eg(code)
e0122856a912 Started on Tables added EmbeddedCode utility
rgbecker
parents: 323
diff changeset
   149
    disc("produces")
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   150
    exec code+("\ngetStory().append(%s)\n"%name)
310
cbec783cfb81 Documentation changes
rgbecker
parents: 308
diff changeset
   151
369
53a1b7bd93ff Added some more
rgbecker
parents: 344
diff changeset
   152
def startKeep():
53a1b7bd93ff Added some more
rgbecker
parents: 344
diff changeset
   153
    return len(getStory())
53a1b7bd93ff Added some more
rgbecker
parents: 344
diff changeset
   154
53a1b7bd93ff Added some more
rgbecker
parents: 344
diff changeset
   155
def endKeep(s):
53a1b7bd93ff Added some more
rgbecker
parents: 344
diff changeset
   156
    S = getStory()
53a1b7bd93ff Added some more
rgbecker
parents: 344
diff changeset
   157
    k = KeepTogether(S[s:])
53a1b7bd93ff Added some more
rgbecker
parents: 344
diff changeset
   158
    S[s:] = [k]
53a1b7bd93ff Added some more
rgbecker
parents: 344
diff changeset
   159
 
310
cbec783cfb81 Documentation changes
rgbecker
parents: 308
diff changeset
   160
def title(text):
317
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   161
    """Use this for the document title only"""
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   162
    disc(text,style=styleSheet['Title'])
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   163
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   164
#AR 3/7/2000 - defining three new levels of headings; code
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   165
#should be swapped over to using them.
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   166
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   167
def heading1(text):
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   168
    """Use this for chapters.  Lessons within a big chapter
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   169
    should now use heading2 instead.  Chapters get numbered."""
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   170
    getStory().append(PageBreak())
400
2c967654b495 removed header dashes.
dinu_gherman
parents: 384
diff changeset
   171
    p = Paragraph('Chapter <seq id="Chapter"/> ' + quickfix(text), H1)
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   172
    getStory().append(p)
369
53a1b7bd93ff Added some more
rgbecker
parents: 344
diff changeset
   173
370
d3ddde4cc30b begin app_demos.py
rgbecker
parents: 369
diff changeset
   174
def Appendix1(text,):
371
4b5524993d85 More demos in appendix
rgbecker
parents: 370
diff changeset
   175
    global appmode
369
53a1b7bd93ff Added some more
rgbecker
parents: 344
diff changeset
   176
    getStory().append(PageBreak())
370
d3ddde4cc30b begin app_demos.py
rgbecker
parents: 369
diff changeset
   177
    if not appmode:
369
53a1b7bd93ff Added some more
rgbecker
parents: 344
diff changeset
   178
        seq.setFormat('Chapter','A')
53a1b7bd93ff Added some more
rgbecker
parents: 344
diff changeset
   179
        seq.reset('Chapter')
370
d3ddde4cc30b begin app_demos.py
rgbecker
parents: 369
diff changeset
   180
        appmode = 1
400
2c967654b495 removed header dashes.
dinu_gherman
parents: 384
diff changeset
   181
    p = Paragraph('Appendix <seq id="Chapter"/> ' + quickfix(text), H1)
369
53a1b7bd93ff Added some more
rgbecker
parents: 344
diff changeset
   182
    getStory().append(p)
53a1b7bd93ff Added some more
rgbecker
parents: 344
diff changeset
   183
317
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   184
def heading2(text):
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   185
    """Used to be 'lesson'"""
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   186
    getStory().append(CondPageBreak(inch))
400
2c967654b495 removed header dashes.
dinu_gherman
parents: 384
diff changeset
   187
    p = Paragraph('<seq template="%(Chapter)s.%(Section+)s "/>' + quickfix(text), H2)
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   188
    getStory().append(p)
317
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   189
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   190
def heading3(text):
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   191
    """Used to be most of the plain old 'head' sections"""
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   192
    getStory().append(CondPageBreak(inch))
317
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   193
    p = Paragraph(quickfix(text), H3)
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   194
    getStory().append(p)
444
f939b29eca9a Added Mac Intro
rgbecker
parents: 441
diff changeset
   195
f939b29eca9a Added Mac Intro
rgbecker
parents: 441
diff changeset
   196
def image(path, width=None, height=None ):
f939b29eca9a Added Mac Intro
rgbecker
parents: 441
diff changeset
   197
	s = startKeep()
f939b29eca9a Added Mac Intro
rgbecker
parents: 441
diff changeset
   198
	space(.2)
f939b29eca9a Added Mac Intro
rgbecker
parents: 441
diff changeset
   199
	getStory().append(Image(os.path.join(os.path.dirname(sys.argv[0]),'..','images',path),width,height))
f939b29eca9a Added Mac Intro
rgbecker
parents: 441
diff changeset
   200
	space(.2)
f939b29eca9a Added Mac Intro
rgbecker
parents: 441
diff changeset
   201
	endKeep(s)
323
5795e28c5910 Platypus Start
rgbecker
parents: 320
diff changeset
   202
 
5795e28c5910 Platypus Start
rgbecker
parents: 320
diff changeset
   203
def heading4(text):
5795e28c5910 Platypus Start
rgbecker
parents: 320
diff changeset
   204
    """Used to be most of the plain old 'head' sections"""
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   205
    getStory().append(CondPageBreak(inch))
323
5795e28c5910 Platypus Start
rgbecker
parents: 320
diff changeset
   206
    p = Paragraph(quickfix(text), H4)
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   207
    getStory().append(p)
317
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   208
    
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   209
def todo(text):
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   210
    """Used for notes to ourselves"""
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   211
    getStory().append(Paragraph(quickfix(text), Comment))
344
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   212
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   213
def centred(text):
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   214
    getStory().append(Paragraph(quickfix(text), Centred))
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   215
                      
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   216
def caption(text):
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   217
    getStory().append(Paragraph(quickfix(text), Caption))
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   218
320
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   219
class Illustration(platdemos.Figure):
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   220
    """The examples are all presented as functions which do
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   221
    something to a canvas, with a constant height and width
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   222
    used.  This puts them inside a figure box with a caption."""
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   223
    
320
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   224
    def __init__(self, operation, caption):
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   225
        stdwidth, stdheight = examplefunctiondisplaysizes
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   226
        #platdemos.Figure.__init__(self, stdwidth * 0.75, stdheight * 0.75)
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   227
        platdemos.Figure.__init__(self, stdwidth, stdheight,
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   228
                    'Figure <seq template="%(Chapter)s-%(Figure+)s"/>: ' + quickfix(caption))
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   229
        self.operation = operation
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   230
        
320
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   231
    def drawFigure(self):
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   232
        #shrink it a little...
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   233
        #self.canv.scale(0.75, 0.75)
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   234
        self.operation(self.canv)
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   235
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   236
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   237
def illust(operation, caption):
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   238
    i = Illustration(operation, caption)
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   239
    getStory().append(i)
334
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   240
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   241
class ParaBox(platdemos.Figure):
344
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   242
    """Illustrates paragraph examples, with style attributes on the left"""
334
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   243
    descrStyle = ParagraphStyle('description',
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   244
                                fontName='Courier',
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   245
                                fontSize=8,
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   246
                                leading=9.6)
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   247
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   248
    def __init__(self, text, style, caption):
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   249
        platdemos.Figure.__init__(self, 0, 0, caption)
334
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   250
        self.text = text
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   251
        self.style = style
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   252
        self.para = Paragraph(text, style)
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   253
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   254
        styleText = self.getStyleText(style)
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   255
        self.pre = Preformatted(styleText, self.descrStyle)
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   256
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   257
    def wrap(self, availWidth, availHeight):
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   258
        """Left 30% is for attributes, right 50% for sample,
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   259
        10% gutter each side."""
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   260
        self.x0 = availWidth * 0.05  #left of box
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   261
        self.x1 = availWidth * 0.1   #left of descriptive text
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   262
        self.x2 = availWidth * 0.5   #left of para itself
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   263
        self.x3 = availWidth * 0.9   #right of para itself
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   264
        self.x4 = availWidth * 0.95  #right of box
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   265
        self.width = self.x4 - self.x0
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   266
        self.dx = 0.5 * (availWidth - self.width)
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   267
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   268
        paw, self.pah = self.para.wrap(self.x3 - self.x2, availHeight)
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   269
        self.pah = self.pah + self.style.spaceBefore + self.style.spaceAfter
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   270
        prw, self.prh = self.pre.wrap(self.x2 - self.x1, availHeight)
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   271
        self.figureHeight = max(self.prh, self.pah) * 10.0/9.0
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   272
        return platdemos.Figure.wrap(self, availWidth, availHeight)
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   273
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   274
    def getStyleText(self, style):
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   275
        """Converts style to preformatted block of text"""
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   276
        lines = []
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   277
        for (key, value) in style.__dict__.items():
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   278
            lines.append('%s = %s' % (key, value))
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   279
        lines.sort()
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   280
        return string.join(lines, '\n')        
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   281
        
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   282
    def drawFigure(self):
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   283
        
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   284
        #now we fill in the bounding box and before/after boxes       
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   285
        self.canv.saveState()
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   286
        self.canv.setFillGray(0.95)
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   287
        self.canv.setDash(1,3)
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   288
        self.canv.rect(self.x2 - self.x0,
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   289
                       self.figureHeight * 0.95 - self.pah,
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   290
                       self.x3-self.x2, self.para.height,
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   291
                       fill=1,stroke=1)
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   292
        
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   293
        self.canv.setFillGray(0.90)
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   294
        self.canv.rect(self.x2 - self.x0, #spaceBefore
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   295
                       self.figureHeight * 0.95 - self.pah + self.para.height,
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   296
                       self.x3-self.x2, self.style.spaceBefore,
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   297
                       fill=1,stroke=1)
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   298
        
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   299
        self.canv.rect(self.x2 - self.x0, #spaceBefore
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   300
                       self.figureHeight * 0.95 - self.pah - self.style.spaceAfter,
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   301
                       self.x3-self.x2, self.style.spaceAfter,
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   302
                       fill=1,stroke=1)
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   303
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   304
        self.canv.restoreState()
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   305
        #self.canv.setFillColor(colors.yellow)
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   306
        self.para.drawOn(self.canv, self.x2 - self.x0,
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   307
                         self.figureHeight * 0.95 - self.pah)
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   308
        self.pre.drawOn(self.canv, self.x1 - self.x0,
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   309
                         self.figureHeight * 0.95 - self.prh)
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   310
        
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   311
        
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   312
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   313
    def getStyleText(self, style):
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   314
        """Converts style to preformatted block of text"""
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   315
        lines = []
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   316
        for (key, value) in style.__dict__.items():
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   317
            if key not in ('name','parent'):
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   318
                lines.append('%s = %s' % (key, value))
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   319
        return string.join(lines, '\n')
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   320
344
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   321
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   322
class ParaBox2(platdemos.Figure):
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   323
    """Illustrates a paragraph side-by-side with the raw
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   324
    text, to show how the XML works."""
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   325
    def __init__(self, text, caption):
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   326
        platdemos.Figure.__init__(self, 0, 0, caption)
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   327
        descrStyle = ParagraphStyle('description',
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   328
                                fontName='Courier',
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   329
                                fontSize=8,
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   330
                                leading=9.6)
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   331
        textStyle = B
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   332
        self.text = text
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   333
        self.left = Paragraph('<![CDATA[' + text + ']]>', descrStyle)
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   334
        self.right = Paragraph(text, B)
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   335
        
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   336
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   337
    def wrap(self, availWidth, availHeight):
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   338
        self.width = availWidth * 0.9
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   339
        colWidth = 0.4 * self.width
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   340
        lw, self.lh = self.left.wrap(colWidth, availHeight)
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   341
        rw, self.rh = self.right.wrap(colWidth, availHeight)
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   342
        self.figureHeight = max(self.lh, self.rh) * 10.0/9.0
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   343
        return platdemos.Figure.wrap(self, availWidth, availHeight)
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   344
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   345
    def drawFigure(self):
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   346
        self.left.drawOn(self.canv,
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   347
                         self.width * 0.05,
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   348
                         self.figureHeight * 0.95 - self.lh
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   349
                         ) 
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   350
        self.right.drawOn(self.canv,
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   351
                         self.width * 0.55,
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   352
                         self.figureHeight * 0.95 - self.rh
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   353
                         ) 
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   354
334
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   355
def parabox(text, style, caption):
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   356
    p = ParaBox(text, style,
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   357
                'Figure <seq template="%(Chapter)s-%(Figure+)s"/>: ' + quickfix(caption)
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   358
                )
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   359
    getStory().append(p)
320
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   360
    
344
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   361
def parabox2(text, caption):
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   362
    p = ParaBox2(text, 
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   363
                'Figure <seq template="%(Chapter)s-%(Figure+)s"/>: ' + quickfix(caption)
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   364
                )
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   365
    getStory().append(p)
dd6e41c2b0ed Paragraphs chapter pretty much complete. Fancy cover.
andy_robinson
parents: 341
diff changeset
   366
296
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   367
def pencilnote():
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   368
    getStory().append(examples.NoteAnnotation())
381
2ca856765ed1 various mods
aaron_watters
parents: 371
diff changeset
   369
    
2ca856765ed1 various mods
aaron_watters
parents: 371
diff changeset
   370
2ca856765ed1 various mods
aaron_watters
parents: 371
diff changeset
   371
from reportlab.lib.colors import tan, green
2ca856765ed1 various mods
aaron_watters
parents: 371
diff changeset
   372
def handnote(xoffset=0, size=None, fillcolor=tan, strokecolor=green):
2ca856765ed1 various mods
aaron_watters
parents: 371
diff changeset
   373
    getStory().append(examples.HandAnnotation(xoffset,size,fillcolor,strokecolor))
2ca856765ed1 various mods
aaron_watters
parents: 371
diff changeset
   374
    
296
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   375
        
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   376
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents: 340
diff changeset
   377
#make a singleton, created when requested rather
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents: 340
diff changeset
   378
#than each time a chapter imports it.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents: 340
diff changeset
   379
_story = None
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   380
def getStory():
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents: 340
diff changeset
   381
    global _story
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents: 340
diff changeset
   382
    if _story is None:
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents: 340
diff changeset
   383
        _story = []
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   384
    return _story
283
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 273
diff changeset
   385
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   386
        
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   387
def run():
494
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 444
diff changeset
   388
    doc = RLDocTemplate('userguide.pdf',pagesize = A4)
283
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 273
diff changeset
   389
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 273
diff changeset
   390
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   391
    #this builds the story    
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents: 340
diff changeset
   392
    #resetStory()
323
5795e28c5910 Platypus Start
rgbecker
parents: 320
diff changeset
   393
337
76141601ec1f Broke out chapter 1
andy_robinson
parents: 336
diff changeset
   394
    import ch1_intro
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents: 340
diff changeset
   395
    import ch2_graphics
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents: 340
diff changeset
   396
    import ch3_pdffeatures
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents: 340
diff changeset
   397
    import ch4_platypus_concepts
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents: 340
diff changeset
   398
    import ch5_paragraphs
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents: 340
diff changeset
   399
    import ch6_tables
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents: 340
diff changeset
   400
    import ch7_custom
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents: 340
diff changeset
   401
    import ch8_future
337
76141601ec1f Broke out chapter 1
andy_robinson
parents: 336
diff changeset
   402
    
370
d3ddde4cc30b begin app_demos.py
rgbecker
parents: 369
diff changeset
   403
    import app_demos
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents: 340
diff changeset
   404
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents: 340
diff changeset
   405
    # I don't know WHAT is going on here.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents: 340
diff changeset
   406
    # the submodules all do 'import *',
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents: 340
diff changeset
   407
    # and the story they have access to
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents: 340
diff changeset
   408
    # contains it all; but the one defined
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents: 340
diff changeset
   409
    # in this module seems to be empty.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents: 340
diff changeset
   410
    #if I just call getStory, it has no
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents: 340
diff changeset
   411
    #items!
334
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   412
    
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents: 340
diff changeset
   413
    story = ch8_future.getStory()
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents: 340
diff changeset
   414
    print 'Built story contains %d flowables...' % len(story)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents: 340
diff changeset
   415
    doc.build(story)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents: 340
diff changeset
   416
    print 'Saved userguide.pdf'
317
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   417
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   418
    
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   419
    
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   420
if __name__=="__main__":
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   421
    run()