reportlab/lib/styles.py
author rgbecker
Wed, 25 Oct 2000 08:57:46 +0000
changeset 494 54257447cfe9
parent 472 cdcff9b000e9
child 512 c12ae96634d5
permissions -rw-r--r--
Changed to indirect copyright
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
494
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 472
diff changeset
     1
#copyright ReportLab Inc. 2000
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 472
diff changeset
     2
#see license.txt for license details
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 472
diff changeset
     3
#history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/lib/styles.py?cvsroot=reportlab
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 472
diff changeset
     4
#$Header: /tmp/reportlab/reportlab/lib/styles.py,v 1.8 2000/10/25 08:57:45 rgbecker Exp $
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 472
diff changeset
     5
__version__=''' $Id: styles.py,v 1.8 2000/10/25 08:57:45 rgbecker Exp $ '''
125
2742c6dfd19e Moved out of layout.py
rgbecker
parents:
diff changeset
     6
128
a0676f013314 Splitting layout.py
rgbecker
parents: 125
diff changeset
     7
from reportlab.lib.colors import white, black
a0676f013314 Splitting layout.py
rgbecker
parents: 125
diff changeset
     8
from reportlab.lib.enums import TA_LEFT
125
2742c6dfd19e Moved out of layout.py
rgbecker
parents:
diff changeset
     9
2742c6dfd19e Moved out of layout.py
rgbecker
parents:
diff changeset
    10
###########################################################
2742c6dfd19e Moved out of layout.py
rgbecker
parents:
diff changeset
    11
# This class provides an 'instance inheritance'
2742c6dfd19e Moved out of layout.py
rgbecker
parents:
diff changeset
    12
# mechanism for its descendants, simpler than acquisition
2742c6dfd19e Moved out of layout.py
rgbecker
parents:
diff changeset
    13
# but not as far-reaching
2742c6dfd19e Moved out of layout.py
rgbecker
parents:
diff changeset
    14
###########################################################
2742c6dfd19e Moved out of layout.py
rgbecker
parents:
diff changeset
    15
class PropertySet:
187
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    16
    defaults = {}
125
2742c6dfd19e Moved out of layout.py
rgbecker
parents:
diff changeset
    17
187
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    18
    def __init__(self, name, parent=None, **kw):
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    19
        """When initialized, it copies the class defaults;
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    20
        then takes a copy of the attributes of the parent
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    21
        if any.  All the work is done in init - styles
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    22
        should cost little to use at runtime."""
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    23
        # step one - validate the hell out of it
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    24
        assert not self.defaults.has_key('name'), "Class Defaults may not contain a 'name' attribute"
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    25
        assert not self.defaults.has_key('parent'), "Class Defaults may not contain a 'parent' attribute"
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    26
        if parent:
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    27
            assert parent.__class__ == self.__class__, "Parent style must have same class as new style"
125
2742c6dfd19e Moved out of layout.py
rgbecker
parents:
diff changeset
    28
187
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    29
        #step two 
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    30
        self.name = name
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    31
        self.parent = parent
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    32
        self.__dict__.update(self.defaults)
125
2742c6dfd19e Moved out of layout.py
rgbecker
parents:
diff changeset
    33
187
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    34
        #step two - copy from parent if any.  Try to be
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    35
        # very strict that only keys in class defaults are
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    36
        # allowed, so they cannot inherit
224
764725e69f94 readJPEGinfo moved from canvas to pdfutils;
andy_robinson
parents: 187
diff changeset
    37
        self.refresh()
764725e69f94 readJPEGinfo moved from canvas to pdfutils;
andy_robinson
parents: 187
diff changeset
    38
        
187
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    39
        #step three - copy keywords if any                    
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    40
        for (key, value) in kw.items():
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    41
             self.__dict__[key] = value
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    42
125
2742c6dfd19e Moved out of layout.py
rgbecker
parents:
diff changeset
    43
187
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    44
    def __repr__(self):
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    45
        return "<%s '%s'>" % (self.__class__.__name__, self.name)
125
2742c6dfd19e Moved out of layout.py
rgbecker
parents:
diff changeset
    46
224
764725e69f94 readJPEGinfo moved from canvas to pdfutils;
andy_robinson
parents: 187
diff changeset
    47
    def refresh(self):
764725e69f94 readJPEGinfo moved from canvas to pdfutils;
andy_robinson
parents: 187
diff changeset
    48
        """re-fetches attributes from the parent on demand;
764725e69f94 readJPEGinfo moved from canvas to pdfutils;
andy_robinson
parents: 187
diff changeset
    49
        use if you have been hacking the styles.  This is
764725e69f94 readJPEGinfo moved from canvas to pdfutils;
andy_robinson
parents: 187
diff changeset
    50
        used by __init__"""
764725e69f94 readJPEGinfo moved from canvas to pdfutils;
andy_robinson
parents: 187
diff changeset
    51
        if self.parent:
764725e69f94 readJPEGinfo moved from canvas to pdfutils;
andy_robinson
parents: 187
diff changeset
    52
            for (key, value) in self.parent.__dict__.items():
764725e69f94 readJPEGinfo moved from canvas to pdfutils;
andy_robinson
parents: 187
diff changeset
    53
                if (key not in ['name','parent']):
764725e69f94 readJPEGinfo moved from canvas to pdfutils;
andy_robinson
parents: 187
diff changeset
    54
                    self.__dict__[key] = value
764725e69f94 readJPEGinfo moved from canvas to pdfutils;
andy_robinson
parents: 187
diff changeset
    55
764725e69f94 readJPEGinfo moved from canvas to pdfutils;
andy_robinson
parents: 187
diff changeset
    56
187
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    57
    def listAttrs(self, indent=''):
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    58
        print indent + 'name =', self.name
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    59
        print indent + 'parent =', self.parent
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    60
        keylist = self.__dict__.keys()
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    61
        keylist.sort()
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    62
        keylist.remove('name')
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    63
        keylist.remove('parent')
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    64
        for key in keylist:
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    65
            value = self.__dict__.get(key, None)
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    66
            print indent + '%s = %s' % (key, value)
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    67
            
125
2742c6dfd19e Moved out of layout.py
rgbecker
parents:
diff changeset
    68
class ParagraphStyle(PropertySet):
187
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    69
    defaults = {
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    70
        'fontName':'Times-Roman',
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    71
        'fontSize':10,
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    72
        'leading':12,
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    73
        'leftIndent':0,
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    74
        'rightIndent':0,
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    75
        'firstLineIndent':0,
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    76
        'alignment':TA_LEFT,
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    77
        'spaceBefore':0,
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    78
        'spaceAfter':0,
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    79
        'bulletFontName':'Times-Roman',
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    80
        'bulletFontSize':10,
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    81
        'bulletIndent':0,
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    82
        'textColor': black
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    83
        }
125
2742c6dfd19e Moved out of layout.py
rgbecker
parents:
diff changeset
    84
2742c6dfd19e Moved out of layout.py
rgbecker
parents:
diff changeset
    85
class LineStyle(PropertySet):
187
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    86
    defaults = {
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    87
        'width':1,
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    88
        'color': black
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    89
        }
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    90
    def prepareCanvas(self, canvas):
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    91
        """You can ask a LineStyle to set up the canvas for drawing
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    92
        the lines."""
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    93
        canvas.setLineWidth(1)
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    94
        #etc. etc.
125
2742c6dfd19e Moved out of layout.py
rgbecker
parents:
diff changeset
    95
2742c6dfd19e Moved out of layout.py
rgbecker
parents:
diff changeset
    96
class CellStyle(PropertySet):
187
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    97
    defaults = {
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    98
        'fontName':'Times-Roman',
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
    99
        'fontsize':10,
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   100
        'leading':12,
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   101
        'leftPadding':6,
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   102
        'rightPadding':6,
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   103
        'topPadding':3,
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   104
        'bottomPadding':3,
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   105
        'firstLineIndent':0,
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   106
        'color':white,
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   107
        'alignment': 'LEFT',
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   108
        }
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   109
class StyleSheet1:
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   110
    """This may or may not be used.  The idea is to
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   111
    1. slightly simplify construction of stylesheets;
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   112
    2. enforce rules to validate styles when added
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   113
       (e.g. we may choose to disallow having both
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   114
       'heading1' and 'Heading1' - actual rules are
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   115
       open to discussion);
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   116
    3. allow aliases and alternate style lookup
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   117
       mechanisms
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   118
    4. Have a place to hang style-manipulation
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   119
       methods (save, load, maybe support a GUI
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   120
       editor)
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   121
       Access is via getitem, so they can be
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   122
       compatible with plain old dictionaries.
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   123
       """
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   124
    def __init__(self):
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   125
        self.byName = {}
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   126
        self.byAlias = {}
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   127
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   128
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   129
    def __getitem__(self, key):
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   130
        try:
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   131
            return self.byAlias[key]
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   132
        except KeyError:
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   133
            try:
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   134
                return self.byName[key]
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   135
            except KeyError:
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   136
                raise KeyError, "Style '%s' not found in stylesheet" % key
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   137
460
6244c4f117ce added has_key method to stylesheet1
andy_robinson
parents: 224
diff changeset
   138
    def has_key(self, key):
6244c4f117ce added has_key method to stylesheet1
andy_robinson
parents: 224
diff changeset
   139
        if self.byAlias.has_key(key):
6244c4f117ce added has_key method to stylesheet1
andy_robinson
parents: 224
diff changeset
   140
            return 1
6244c4f117ce added has_key method to stylesheet1
andy_robinson
parents: 224
diff changeset
   141
        elif self.byName.has_key(key):
6244c4f117ce added has_key method to stylesheet1
andy_robinson
parents: 224
diff changeset
   142
            return 1
6244c4f117ce added has_key method to stylesheet1
andy_robinson
parents: 224
diff changeset
   143
        else:
6244c4f117ce added has_key method to stylesheet1
andy_robinson
parents: 224
diff changeset
   144
            return 0
6244c4f117ce added has_key method to stylesheet1
andy_robinson
parents: 224
diff changeset
   145
187
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   146
    def add(self, style, alias=None):
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   147
        key = style.name
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   148
        if self.byName.has_key(key):
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   149
            raise KeyError, "Style '%s' already defined in stylesheet" % key
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   150
        if self.byAlias.has_key(key):
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   151
            raise KeyError, "Style name '%s' is already an alias in stylesheet" % key
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   152
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   153
        if alias:
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   154
            if self.byName.has_key(alias):
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   155
                raise KeyError, "Style '%s' already defined in stylesheet" % alias
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   156
            if self.byAlias.has_key(alias):
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   157
                raise KeyError, "Alias name '%s' is already an alias in stylesheet" % alias
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   158
        #passed all tests?  OK, add it    
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   159
        self.byName[key] = style
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   160
        if alias:
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   161
            self.byAlias[alias] = style
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   162
     
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   163
    def list(self):
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   164
        styles = self.byName.items()
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   165
        styles.sort()
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   166
        alii = {}
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   167
        for (alias, style) in self.byAlias.items():
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   168
            alii[style] = alias
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   169
        for (name, style) in styles:
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   170
            alias = alii.get(style, None)
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   171
            print name, alias
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   172
            style.listAttrs('    ')
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   173
            print
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   174
            
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   175
        
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   176
125
2742c6dfd19e Moved out of layout.py
rgbecker
parents:
diff changeset
   177
2742c6dfd19e Moved out of layout.py
rgbecker
parents:
diff changeset
   178
def testStyles():
187
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   179
    pNormal = ParagraphStyle('Normal',None)
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   180
    pNormal.fontName = 'Times-Roman'
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   181
    pNormal.fontSize = 12
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   182
    pNormal.leading = 14.4
125
2742c6dfd19e Moved out of layout.py
rgbecker
parents:
diff changeset
   183
187
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   184
    pNormal.listAttrs()
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   185
    print
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   186
    pPre = ParagraphStyle('Literal', pNormal)
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   187
    pPre.fontName = 'Courier'
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   188
    pPre.listAttrs()
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   189
    return pNormal, pPre
125
2742c6dfd19e Moved out of layout.py
rgbecker
parents:
diff changeset
   190
2742c6dfd19e Moved out of layout.py
rgbecker
parents:
diff changeset
   191
def getSampleStyleSheet():
187
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   192
    """Returns a dictionary of styles to get you started.  Should be
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   193
    usable for fairly basic word processing tasks.  We should really have
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   194
    a class for StyleSheets, which can list itself and avoid the
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   195
    duplication of item names seen below."""
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   196
    stylesheet = {}
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   197
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   198
    para = ParagraphStyle('Normal', None)   #the ancestor of all
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   199
    para.fontName = 'Times-Roman'
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   200
    para.fontSize = 10
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   201
    para.leading = 12
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   202
    stylesheet['Normal'] = para
125
2742c6dfd19e Moved out of layout.py
rgbecker
parents:
diff changeset
   203
187
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   204
    para = ParagraphStyle('BodyText', stylesheet['Normal'])
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   205
    para.spaceBefore = 6
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   206
    stylesheet['BodyText'] = para
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   207
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   208
    para = ParagraphStyle('Italic', stylesheet['BodyText'])
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   209
    para.fontName = 'Times-Italic'
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   210
    stylesheet['Italic'] = para
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   211
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   212
    para = ParagraphStyle('Heading1', stylesheet['Normal'])
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   213
    para.fontName = 'Times-Bold'
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   214
    para.fontSize = 18
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   215
    para.spaceAfter = 6
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   216
    stylesheet['Heading1'] = para
125
2742c6dfd19e Moved out of layout.py
rgbecker
parents:
diff changeset
   217
187
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   218
    para = ParagraphStyle('Heading2', stylesheet['Normal'])
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   219
    para.fontName = 'Times-Bold'
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   220
    para.fontSize = 14
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   221
    para.spaceBefore = 12
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   222
    para.spaceAfter = 6
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   223
    stylesheet['Heading2'] = para
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   224
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   225
    para = ParagraphStyle('Heading3', stylesheet['Normal'])
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   226
    para.fontName = 'Times-BoldItalic'
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   227
    para.fontSize = 12
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   228
    para.spaceBefore = 12
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   229
    para.spaceAfter = 6
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   230
    stylesheet['Heading3'] = para
125
2742c6dfd19e Moved out of layout.py
rgbecker
parents:
diff changeset
   231
187
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   232
    para = ParagraphStyle('Bullet', stylesheet['Normal'])
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   233
    para.firstLineIndent = 36
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   234
    para.leftIndent = 36
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   235
    para.spaceBefore = 3
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   236
    stylesheet['Bullet'] = para
125
2742c6dfd19e Moved out of layout.py
rgbecker
parents:
diff changeset
   237
187
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   238
    para = ParagraphStyle('Definition', stylesheet['Normal'])
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   239
    #use this for definition lists
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   240
    para.firstLineIndent = 36
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   241
    para.leftIndent = 36
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   242
    para.bulletIndent = 0
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   243
    para.spaceBefore = 6
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   244
    para.bulletFontName = 'Times-BoldItalic'
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   245
    stylesheet['Definition'] = para
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   246
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   247
    para = ParagraphStyle('Code', stylesheet['Normal'])
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   248
    para.fontName = 'Courier'
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   249
    para.fontSize = 8
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   250
    para.leading = 8.8
472
cdcff9b000e9 Code needs a firstLineIndent same as normal lineIndent
rgbecker
parents: 460
diff changeset
   251
    para.firstLineIndent = 36
187
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   252
    para.leftIndent = 36
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   253
    stylesheet['Code'] = para
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   254
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   255
    return stylesheet
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   256
125
2742c6dfd19e Moved out of layout.py
rgbecker
parents:
diff changeset
   257
187
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   258
def getSampleStyleSheet1():
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   259
    """Returns a stylesheet object"""
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   260
    stylesheet = StyleSheet1()
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   261
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   262
    stylesheet.add(ParagraphStyle(name='Normal',
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   263
                                  fontName='Times-Roman',
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   264
                                  fontSize=10,
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   265
                                  leading=12)
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   266
                   )
125
2742c6dfd19e Moved out of layout.py
rgbecker
parents:
diff changeset
   267
187
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   268
    stylesheet.add(ParagraphStyle(name='BodyText',
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   269
                                  parent=stylesheet['Normal'],
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   270
                                  spaceBefore=6)
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   271
                   )
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   272
    stylesheet.add(ParagraphStyle(name='Italic',
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   273
                                  parent=stylesheet['BodyText'],
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   274
                                  fontName = 'Times-Italic')
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   275
                   )
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   276
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   277
    stylesheet.add(ParagraphStyle(name='Heading1',
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   278
                                  parent=stylesheet['Normal'],
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   279
                                  fontName = 'Times-Bold',
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   280
                                  fontSize=18,
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   281
                                  spaceAfter=6),
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   282
                   alias='h1')
125
2742c6dfd19e Moved out of layout.py
rgbecker
parents:
diff changeset
   283
187
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   284
    stylesheet.add(ParagraphStyle(name='Heading2',
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   285
                                  parent=stylesheet['Normal'],
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   286
                                  fontName = 'Times-Bold',
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   287
                                  fontSize=14,
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   288
                                  spaceBefore=12,
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   289
                                  spaceAfter=6),
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   290
                   alias='h2')
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   291
    
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   292
    stylesheet.add(ParagraphStyle(name='Heading3',
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   293
                                  parent=stylesheet['Normal'],
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   294
                                  fontName = 'Times-BoldItalic',
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   295
                                  fontSize=12,
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   296
                                  spaceBefore=12,
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   297
                                  spaceAfter=6),
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   298
                   alias='h3')
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   299
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   300
    stylesheet.add(ParagraphStyle(name='Bullet',
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   301
                                  parent=stylesheet['Normal'],
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   302
                                  firstLineIndent=36,
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   303
                                  spaceBefore=3),
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   304
                   alias='bu')
125
2742c6dfd19e Moved out of layout.py
rgbecker
parents:
diff changeset
   305
187
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   306
    stylesheet.add(ParagraphStyle(name='Definition',
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   307
                                  parent=stylesheet['Normal'],
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   308
                                  firstLineIndent=36,
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   309
                                  leftIndent=36,
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   310
                                  bulletIndent=0,
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   311
                                  spaceBefore=6,
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   312
                                  bulletFontIndent='Times-BoldItalic'),
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   313
                   alias='df')
125
2742c6dfd19e Moved out of layout.py
rgbecker
parents:
diff changeset
   314
187
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   315
    stylesheet.add(ParagraphStyle(name='Code',
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   316
                                  parent=stylesheet['Normal'],
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   317
                                  fontName='Courier',
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   318
                                  fontSize=8,
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   319
                                  leading=8.8,
472
cdcff9b000e9 Code needs a firstLineIndent same as normal lineIndent
rgbecker
parents: 460
diff changeset
   320
                                  firstLineIndent=36,
187
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   321
                                  leftIndent=36))
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   322
    
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   323
    
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   324
    return stylesheet
125
2742c6dfd19e Moved out of layout.py
rgbecker
parents:
diff changeset
   325
187
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   326
# substitute new one for testing
1f22787ae36b Stylesheets become classes; styles copy data on __init__
andy_robinson
parents: 142
diff changeset
   327
getSampleStyleSheet = getSampleStyleSheet1