docs/userguide/genuserguide.py
author andy_robinson
Mon, 10 Jul 2000 12:00:17 +0000
changeset 340 f3f2af39e7d7
parent 337 76141601ec1f
child 341 27c68d524504
permissions -rw-r--r--
More work on chapter 1
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
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
     2
###############################################################################
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
     3
#
317
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
     4
#   ReportLab Public License Version 1.0
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
     5
#
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
     6
#   Except for the change of names the spirit and intention of this
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
     7
#   license is the same as that of Python
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
     8
#
317
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
     9
#   (C) Copyright ReportLab Inc. 1998-2000.
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
    10
#
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
# All Rights Reserved
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
    13
#
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
    14
# Permission to use, copy, modify, and distribute this software and its
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
    15
# documentation for any purpose and without fee is hereby granted, provided
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
    16
# that the above copyright notice appear in all copies and that both that
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
    17
# copyright notice and this permission notice appear in supporting
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
    18
# documentation, and that the name of ReportLab not be used
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
    19
# in advertising or publicity pertaining to distribution of the software
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
    20
# without specific, written prior permission. 
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
    21
# 
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
    22
#
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
    23
# Disclaimer
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
    24
#
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
    25
# ReportLab Inc. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
    26
# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
    27
# IN NO EVENT SHALL ReportLab BE LIABLE FOR ANY SPECIAL, INDIRECT
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
    28
# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
    29
# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
    30
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
    31
# PERFORMANCE OF THIS SOFTWARE. 
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
    32
#
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
    33
###############################################################################
317
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    34
#   $Log: genuserguide.py,v $
340
f3f2af39e7d7 More work on chapter 1
andy_robinson
parents: 337
diff changeset
    35
#   Revision 1.24  2000/07/10 12:00:17  andy_robinson
f3f2af39e7d7 More work on chapter 1
andy_robinson
parents: 337
diff changeset
    36
#   More work on chapter 1
f3f2af39e7d7 More work on chapter 1
andy_robinson
parents: 337
diff changeset
    37
#
337
76141601ec1f Broke out chapter 1
andy_robinson
parents: 336
diff changeset
    38
#   Revision 1.23  2000/07/08 13:24:27  andy_robinson
76141601ec1f Broke out chapter 1
andy_robinson
parents: 336
diff changeset
    39
#   Broke out chapter 1
76141601ec1f Broke out chapter 1
andy_robinson
parents: 336
diff changeset
    40
#
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
    41
#   Revision 1.22  2000/07/08 12:52:25  andy_robinson
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
    42
#   Separated out actual text from genuserguide, so it can be broken into
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
    43
#   chapters.
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
    44
#
334
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
    45
#   Revision 1.21  2000/07/07 22:55:31  andy_robinson
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
    46
#   Added paragraph examples and widget to User Guide
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
    47
#
331
df7a5344d9e3 More on paragraphs
rgbecker
parents: 330
diff changeset
    48
#   Revision 1.20  2000/07/07 16:18:37  rgbecker
df7a5344d9e3 More on paragraphs
rgbecker
parents: 330
diff changeset
    49
#   More on paragraphs
df7a5344d9e3 More on paragraphs
rgbecker
parents: 330
diff changeset
    50
#
330
e392b1be9211 Start on Paragraph
rgbecker
parents: 328
diff changeset
    51
#   Revision 1.19  2000/07/07 15:09:21  rgbecker
e392b1be9211 Start on Paragraph
rgbecker
parents: 328
diff changeset
    52
#   Start on Paragraph
e392b1be9211 Start on Paragraph
rgbecker
parents: 328
diff changeset
    53
#
328
e0122856a912 Started on Tables added EmbeddedCode utility
rgbecker
parents: 323
diff changeset
    54
#   Revision 1.18  2000/07/06 15:38:15  rgbecker
e0122856a912 Started on Tables added EmbeddedCode utility
rgbecker
parents: 323
diff changeset
    55
#   Started on Tables added EmbeddedCode utility
e0122856a912 Started on Tables added EmbeddedCode utility
rgbecker
parents: 323
diff changeset
    56
#
323
5795e28c5910 Platypus Start
rgbecker
parents: 320
diff changeset
    57
#   Revision 1.17  2000/07/05 16:06:01  rgbecker
5795e28c5910 Platypus Start
rgbecker
parents: 320
diff changeset
    58
#   Platypus Start
5795e28c5910 Platypus Start
rgbecker
parents: 320
diff changeset
    59
#
320
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
    60
#   Revision 1.16  2000/07/04 22:22:40  andy_robinson
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
    61
#   Tidied up genuserguide.py, especially figure handling; began
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
    62
#   adding PDF special features docco
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
    63
#
318
03c9f114c621 Changes to heading structure
andy_robinson
parents: 317
diff changeset
    64
#   Revision 1.15  2000/07/03 16:03:31  andy_robinson
03c9f114c621 Changes to heading structure
andy_robinson
parents: 317
diff changeset
    65
#   Changes to heading structure
03c9f114c621 Changes to heading structure
andy_robinson
parents: 317
diff changeset
    66
#
317
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    67
#   Revision 1.14  2000/07/03 15:50:31  andy_robinson
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    68
#   Pushed down most existing lessons one level; added
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    69
#   functions heading1..heading3 for building story
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    70
#   unambiguously; spelled Hugh Hefner right!
314
72c75740504b abspath is 1.5.2 only
rgbecker
parents: 311
diff changeset
    71
#
317
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    72
#   Revision 1.13  2000/07/03 09:51:38  rgbecker
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    73
#   abspath is 1.5.2 only
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    74
#   
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    75
#   Revision 1.12  2000/06/28 16:10:00  rgbecker
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    76
#   Fix unwanted 'i'
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    77
#   
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    78
#   Revision 1.11  2000/06/28 14:52:43  rgbecker
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    79
#   Documentation changes
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    80
#   
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    81
#   Revision 1.10  2000/06/27 10:09:48  rgbecker
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    82
#   Minor cosmetic changes
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    83
#   
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    84
#   Revision 1.9  2000/06/23 21:09:03  aaron_watters
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    85
#   text text and more text
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    86
#   
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    87
#   Revision 1.8  2000/06/22 19:05:24  aaron_watters
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    88
#   added quickhack for font changes in paragraphs and lots of new text
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    89
#   
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    90
#   Revision 1.7  2000/06/22 13:55:59  aaron_watters
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    91
#   showPage resets all state parameters warning.
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    92
#   
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    93
#   Revision 1.6  2000/06/22 13:35:28  aaron_watters
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    94
#   textobject and pathobject methods, among other things
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    95
#   
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    96
#   Revision 1.5  2000/06/21 21:19:29  aaron_watters
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    97
#   colors, line styles, more examples
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    98
#   
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
    99
#   Revision 1.4  2000/06/21 15:16:05  aaron_watters
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   100
#   Lots of graphical examples added
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   101
#   
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   102
#   Revision 1.3  2000/06/20 20:31:42  aaron_watters
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   103
#   typos and more examples
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   104
#   
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   105
#   Revision 1.2  2000/06/19 21:13:02  aaron_watters
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   106
#   2nd try. more text
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   107
#   
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   108
#   Revision 1.1  2000/06/17 02:57:56  aaron_watters
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   109
#   initial checkin. user guide generation framework.
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   110
#   
340
f3f2af39e7d7 More work on chapter 1
andy_robinson
parents: 337
diff changeset
   111
__version__=''' $Id: genuserguide.py,v 1.24 2000/07/10 12:00:17 andy_robinson Exp $ '''
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   112
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   113
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   114
__doc__ = """
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   115
This module contains the script for building the user guide.
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   116
"""
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   117
320
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   118
import os, sys
334
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   119
import string
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   120
320
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   121
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
   122
from rltemplate import RLDocTemplate
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   123
from stylesheet import getStyleSheet
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   124
styleSheet = getStyleSheet()
310
cbec783cfb81 Documentation changes
rgbecker
parents: 308
diff changeset
   125
320
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   126
#from reportlab.platypus.doctemplate import SimpleDocTemplate
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   127
from reportlab.lib.units import inch
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   128
from reportlab.lib.pagesizes import letter
328
e0122856a912 Started on Tables added EmbeddedCode utility
rgbecker
parents: 323
diff changeset
   129
from reportlab.platypus import Paragraph, Spacer, Preformatted,\
e0122856a912 Started on Tables added EmbeddedCode utility
rgbecker
parents: 323
diff changeset
   130
            PageBreak, CondPageBreak, Flowable, Table, TableStyle
310
cbec783cfb81 Documentation changes
rgbecker
parents: 308
diff changeset
   131
from reportlab.lib.styles import ParagraphStyle
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   132
from reportlab.lib import colors
317
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   133
from reportlab.lib.sequencer import getSequencer
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   134
import examples
320
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   135
import platdemos
328
e0122856a912 Started on Tables added EmbeddedCode utility
rgbecker
parents: 323
diff changeset
   136
import StringIO
318
03c9f114c621 Changes to heading structure
andy_robinson
parents: 317
diff changeset
   137
03c9f114c621 Changes to heading structure
andy_robinson
parents: 317
diff changeset
   138
03c9f114c621 Changes to heading structure
andy_robinson
parents: 317
diff changeset
   139
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   140
from reportlab.lib.corp import ReportLabLogo
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   141
LOGO = ReportLabLogo(0.25*inch, 0.25*inch, inch, 0.75*inch)
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   142
301
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
   143
from t_parse import Template
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
   144
QFcodetemplate = Template("X$X$", "X")
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
   145
QFreptemplate = Template("X^X^", "X")
320
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   146
codesubst = "%s<font name=Courier>%s</font>"
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   147
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
   148
    
301
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
   149
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
   150
def quickfix(text):
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
   151
    """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
   152
       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
   153
       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
   154
       $ is $\\$ (^ is ^\\^.
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
   155
    """
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
   156
    from string import join
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
   157
    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
   158
        fragment = text
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
   159
        parts = []
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
   160
        try:
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
   161
            while fragment:
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
   162
                try:
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
   163
                    (matches, index) = template.PARSE(fragment)
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
   164
                except: raise ValueError
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
   165
                else:
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
   166
                    [prefix, code] = matches
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
   167
                    if code == "\\":
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
   168
                        part = fragment[:index]
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
   169
                    else:
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
   170
                        part = subst % (prefix, code)
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
   171
                    parts.append(part)
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
   172
                    fragment = fragment[index:]
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
   173
        except ValueError:
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
   174
            parts.append(fragment)
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
   175
        text = join(parts, "")
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
   176
    return text
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 300
diff changeset
   177
#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
   178
320
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   179
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   180
310
cbec783cfb81 Documentation changes
rgbecker
parents: 308
diff changeset
   181
H1 = styleSheet['Heading1']
cbec783cfb81 Documentation changes
rgbecker
parents: 308
diff changeset
   182
H2 = styleSheet['Heading2']
317
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   183
H3 = styleSheet['Heading3']
323
5795e28c5910 Platypus Start
rgbecker
parents: 320
diff changeset
   184
H4 = styleSheet['Heading4']
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   185
B = styleSheet['BodyText']
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   186
BU = styleSheet['Bullet']
317
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   187
Comment = styleSheet['Comment']
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   188
318
03c9f114c621 Changes to heading structure
andy_robinson
parents: 317
diff changeset
   189
#set up numbering
03c9f114c621 Changes to heading structure
andy_robinson
parents: 317
diff changeset
   190
seq = getSequencer()
03c9f114c621 Changes to heading structure
andy_robinson
parents: 317
diff changeset
   191
seq.setFormat('Chapter','1')
03c9f114c621 Changes to heading structure
andy_robinson
parents: 317
diff changeset
   192
seq.setFormat('Section','1')
03c9f114c621 Changes to heading structure
andy_robinson
parents: 317
diff changeset
   193
seq.setFormat('Appendix','A')
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   194
seq.setFormat('Figure', '1')
318
03c9f114c621 Changes to heading structure
andy_robinson
parents: 317
diff changeset
   195
seq.chain('Chapter','Section')
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   196
seq.chain('Chapter','Figure')
318
03c9f114c621 Changes to heading structure
andy_robinson
parents: 317
diff changeset
   197
03c9f114c621 Changes to heading structure
andy_robinson
parents: 317
diff changeset
   198
320
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   199
lessonnamestyle = H2
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   200
discussiontextstyle = B
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   201
exampletextstyle = styleSheet['Code']
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   202
# size for every example
283
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 273
diff changeset
   203
examplefunctionxinches = 5.5
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 273
diff changeset
   204
examplefunctionyinches = 3
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 273
diff changeset
   205
examplefunctiondisplaysizes = (examplefunctionxinches*inch, examplefunctionyinches*inch)
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   206
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   207
# for testing
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   208
def NOP(*x,**y):
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   209
    return None
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   210
323
5795e28c5910 Platypus Start
rgbecker
parents: 320
diff changeset
   211
def CPage(inches):
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   212
    getStory().append(CondPageBreak(inches*inch))
334
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   213
    
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   214
def newPage():
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   215
    getStory().append(PageBreak())
334
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   216
    
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   217
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
   218
    text = quickfix(text)
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   219
    P = klass(text, style)
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   220
    getStory().append(P)
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   221
340
f3f2af39e7d7 More work on chapter 1
andy_robinson
parents: 337
diff changeset
   222
def restartList():
f3f2af39e7d7 More work on chapter 1
andy_robinson
parents: 337
diff changeset
   223
    getSequencer().reset('list1')
f3f2af39e7d7 More work on chapter 1
andy_robinson
parents: 337
diff changeset
   224
f3f2af39e7d7 More work on chapter 1
andy_robinson
parents: 337
diff changeset
   225
def list(text):
f3f2af39e7d7 More work on chapter 1
andy_robinson
parents: 337
diff changeset
   226
    text='<bullet><seq id="list1"/>.</bullet>' + quickfix(text)
f3f2af39e7d7 More work on chapter 1
andy_robinson
parents: 337
diff changeset
   227
    P = Paragraph(text, BU)
f3f2af39e7d7 More work on chapter 1
andy_robinson
parents: 337
diff changeset
   228
    getStory().append(P)
f3f2af39e7d7 More work on chapter 1
andy_robinson
parents: 337
diff changeset
   229
    
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   230
def bullet(text):
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   231
    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
   232
    P = Paragraph(text, BU)
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   233
    getStory().append(P)
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   234
    
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   235
def eg(text):
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   236
    getStory().append(Spacer(0.1*inch, 0.1*inch))
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   237
    disc(text, klass=Preformatted, style=exampletextstyle)
328
e0122856a912 Started on Tables added EmbeddedCode utility
rgbecker
parents: 323
diff changeset
   238
e0122856a912 Started on Tables added EmbeddedCode utility
rgbecker
parents: 323
diff changeset
   239
def EmbeddedCode(code,name='t', fn='embedded.tmp'):
e0122856a912 Started on Tables added EmbeddedCode utility
rgbecker
parents: 323
diff changeset
   240
    eg(code)
e0122856a912 Started on Tables added EmbeddedCode utility
rgbecker
parents: 323
diff changeset
   241
    disc("produces")
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   242
    exec code+("\ngetStory().append(%s)\n"%name)
310
cbec783cfb81 Documentation changes
rgbecker
parents: 308
diff changeset
   243
cbec783cfb81 Documentation changes
rgbecker
parents: 308
diff changeset
   244
def title(text):
317
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   245
    """Use this for the document title only"""
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   246
    disc(text,style=styleSheet['Title'])
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   247
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   248
#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
   249
#should be swapped over to using them.
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   250
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   251
def heading1(text):
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   252
    """Use this for chapters.  Lessons within a big chapter
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   253
    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
   254
    getStory().append(PageBreak())
317
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   255
    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
   256
    getStory().append(p)
317
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   257
    
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   258
def heading2(text):
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   259
    """Used to be 'lesson'"""
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   260
    getStory().append(CondPageBreak(inch))
317
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   261
    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
   262
    getStory().append(p)
317
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   263
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   264
def heading3(text):
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   265
    """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
   266
    getStory().append(CondPageBreak(inch))
317
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   267
    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
   268
    getStory().append(p)
323
5795e28c5910 Platypus Start
rgbecker
parents: 320
diff changeset
   269
 
5795e28c5910 Platypus Start
rgbecker
parents: 320
diff changeset
   270
def heading4(text):
5795e28c5910 Platypus Start
rgbecker
parents: 320
diff changeset
   271
    """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
   272
    getStory().append(CondPageBreak(inch))
323
5795e28c5910 Platypus Start
rgbecker
parents: 320
diff changeset
   273
    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
   274
    getStory().append(p)
317
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   275
    
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   276
def todo(text):
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   277
    """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
   278
    getStory().append(Paragraph(quickfix(text), Comment))
317
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   279
    
320
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   280
class Illustration(platdemos.Figure):
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   281
    """The examples are all presented as functions which do
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   282
    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
   283
    used.  This puts them inside a figure box with a caption."""
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   284
    
320
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   285
    def __init__(self, operation, caption):
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   286
        stdwidth, stdheight = examplefunctiondisplaysizes
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   287
        #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
   288
        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
   289
                    'Figure <seq template="%(Chapter)s-%(Figure+)s"/>: ' + quickfix(caption))
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   290
        self.operation = operation
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   291
        
320
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   292
    def drawFigure(self):
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   293
        #shrink it a little...
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   294
        #self.canv.scale(0.75, 0.75)
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   295
        self.operation(self.canv)
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   296
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   297
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   298
def illust(operation, caption):
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   299
    i = Illustration(operation, caption)
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   300
    getStory().append(i)
334
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   301
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   302
class ParaBox(platdemos.Figure):
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   303
    descrStyle = ParagraphStyle('description',
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   304
                                fontName='Courier',
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   305
                                fontSize=8,
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   306
                                leading=9.6)
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   307
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   308
    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
   309
        platdemos.Figure.__init__(self, 0, 0, caption)
334
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   310
        self.text = text
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   311
        self.style = style
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   312
        self.para = Paragraph(text, style)
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   313
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   314
        styleText = self.getStyleText(style)
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   315
        self.pre = Preformatted(styleText, self.descrStyle)
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   316
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   317
    def wrap(self, availWidth, availHeight):
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   318
        """Left 30% is for attributes, right 50% for sample,
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   319
        10% gutter each side."""
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   320
        self.x0 = availWidth * 0.05  #left of box
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   321
        self.x1 = availWidth * 0.1   #left of descriptive text
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   322
        self.x2 = availWidth * 0.5   #left of para itself
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   323
        self.x3 = availWidth * 0.9   #right of para itself
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   324
        self.x4 = availWidth * 0.95  #right of box
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   325
        self.width = self.x4 - self.x0
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   326
        self.dx = 0.5 * (availWidth - self.width)
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   327
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   328
        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
   329
        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
   330
        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
   331
        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
   332
        return platdemos.Figure.wrap(self, availWidth, availHeight)
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   333
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   334
    def getStyleText(self, style):
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   335
        """Converts style to preformatted block of text"""
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   336
        lines = []
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   337
        for (key, value) in style.__dict__.items():
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   338
            lines.append('%s = %s' % (key, value))
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   339
        lines.sort()
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   340
        return string.join(lines, '\n')        
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   341
        
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   342
    def drawFigure(self):
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   343
        
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   344
        #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
   345
        self.canv.saveState()
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   346
        self.canv.setFillGray(0.95)
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   347
        self.canv.setDash(1,3)
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   348
        self.canv.rect(self.x2 - self.x0,
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   349
                       self.figureHeight * 0.95 - self.pah,
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   350
                       self.x3-self.x2, self.para.height,
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   351
                       fill=1,stroke=1)
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   352
        
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   353
        self.canv.setFillGray(0.90)
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   354
        self.canv.rect(self.x2 - self.x0, #spaceBefore
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   355
                       self.figureHeight * 0.95 - self.pah + self.para.height,
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   356
                       self.x3-self.x2, self.style.spaceBefore,
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   357
                       fill=1,stroke=1)
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   358
        
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   359
        self.canv.rect(self.x2 - self.x0, #spaceBefore
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   360
                       self.figureHeight * 0.95 - self.pah - self.style.spaceAfter,
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   361
                       self.x3-self.x2, self.style.spaceAfter,
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   362
                       fill=1,stroke=1)
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   363
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   364
        self.canv.restoreState()
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   365
        #self.canv.setFillColor(colors.yellow)
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   366
        self.para.drawOn(self.canv, self.x2 - self.x0,
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   367
                         self.figureHeight * 0.95 - self.pah)
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   368
        self.pre.drawOn(self.canv, self.x1 - self.x0,
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   369
                         self.figureHeight * 0.95 - self.prh)
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   370
        
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   371
        
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   372
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   373
    def getStyleText(self, style):
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   374
        """Converts style to preformatted block of text"""
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   375
        lines = []
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   376
        for (key, value) in style.__dict__.items():
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   377
            if key not in ('name','parent'):
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   378
                lines.append('%s = %s' % (key, value))
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   379
        return string.join(lines, '\n')
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   380
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   381
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
   382
    p = ParaBox(text, style,
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   383
                '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
   384
                )
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   385
    getStory().append(p)
320
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 318
diff changeset
   386
    
296
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   387
def pencilnote():
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   388
    getStory().append(examples.NoteAnnotation())
296
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   389
        
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   390
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   391
_story = []
283
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 273
diff changeset
   392
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   393
def getStory():
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   394
    return _story
283
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 273
diff changeset
   395
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   396
def setStory(st):
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   397
    tmp = _story
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   398
    _story = st
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   399
    return tmp
296
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   400
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   401
def resetStory():
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   402
    _story = []
298
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   403
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   404
def extendStory(lst):
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   405
    for item in lst:
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   406
        _story.append(item)
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   407
        
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   408
def run():
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   409
    doc = RLDocTemplate('userguide.pdf',pagesize = letter)
283
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 273
diff changeset
   410
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 273
diff changeset
   411
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   412
    #this builds the story    
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   413
    resetStory()
323
5795e28c5910 Platypus Start
rgbecker
parents: 320
diff changeset
   414
337
76141601ec1f Broke out chapter 1
andy_robinson
parents: 336
diff changeset
   415
    import ch1_intro
76141601ec1f Broke out chapter 1
andy_robinson
parents: 336
diff changeset
   416
    #extendStory(ch1_intro.getStory())
76141601ec1f Broke out chapter 1
andy_robinson
parents: 336
diff changeset
   417
    
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   418
    import most_chapters
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   419
    extendStory(most_chapters.getStory())
334
6f9c206a34c0 Added paragraph examples and widget to User Guide
andy_robinson
parents: 331
diff changeset
   420
    
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   421
    doc.build(getStory())
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   422
    print 'userguide.pdf is ready'
317
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 314
diff changeset
   423
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   424
    
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   425
    
273
cd705b27b6a5 initial checkin. user guide generation framework.
aaron_watters
parents:
diff changeset
   426
if __name__=="__main__":
336
c0fcae4341cf Separated out actual text from genuserguide, so it can be broken into
andy_robinson
parents: 334
diff changeset
   427
    run()