docs/userguide/graph_widgets.py
author jonas
Fri, 16 Jan 2009 18:23:19 +0000
changeset 3062 d47129e56d9f
child 3617 ae5744e97c42
permissions -rw-r--r--
Merged graphguide into userguide.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3062
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
     1
#Copyright ReportLab Europe Ltd. 2000-2008
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
     2
#see license.txt for license details
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
     3
__version__=''' $Id$ '''
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
     4
from tools.docco.rl_doc_utils import *
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
     5
from reportlab.graphics.shapes import *
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
     6
from reportlab.graphics.widgets import signsandsymbols
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
     7
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
     8
heading2("Widgets")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
     9
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    10
disc("""
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    11
We now describe widgets and how they relate to shapes.
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    12
Using many examples it is shown how widgets make reusable
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    13
graphics components.
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    14
""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    15
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    16
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    17
heading3("Shapes vs. Widgets")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    18
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    19
disc("""Up until now, Drawings have been 'pure data'. There is no code in them
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    20
       to actually do anything, except assist the programmer in checking and
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    21
       inspecting the drawing. In fact, that's the cornerstone of the whole
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    22
       concept and is what lets us achieve portability - a renderer only
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    23
       needs to implement the primitive shapes.""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    24
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    25
disc("""We want to build reusable graphic objects, including a powerful chart
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    26
       library. To do this we need to reuse more tangible things than
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    27
       rectangles and circles. We should be able to write objects for other
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    28
       to reuse - arrows, gears, text boxes, UML diagram nodes, even fully
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    29
       fledged charts.""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    30
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    31
disc("""
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    32
The Widget standard is a standard built on top of the shapes module.
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    33
Anyone can write new widgets, and we can build up libraries of them.
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    34
Widgets support the $getProperties()$ and $setProperties()$ methods,
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    35
so you can inspect and modify as well as document them in a uniform
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    36
way.
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    37
""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    38
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    39
bullet("A widget is a reusable shape ")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    40
bullet("""it can be initialized with no arguments
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    41
       when its $draw()$ method is called it creates a primitive Shape or a
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    42
       Group to represent itself""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    43
bullet("""It can have any parameters you want, and they can drive the way it is
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    44
       drawn""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    45
bullet("""it has a $demo()$ method which should return an attractively drawn
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    46
       example of itself in a 200x100 rectangle. This is the cornerstone of
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    47
       the automatic documentation tools. The $demo()$ method should also have
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    48
       a well written docstring, since that is printed too!""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    49
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    50
disc("""Widgets run contrary to the idea that a drawing is just a bundle of
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    51
       shapes; surely they have their own code? The way they work is that a
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    52
       widget can convert itself to a group of primitive shapes. If some of
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    53
       its components are themselves widgets, they will get converted too.
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    54
       This happens automatically during rendering; the renderer will not see
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    55
       your chart widget, but just a collection of rectangles, lines and
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    56
       strings. You can also explicitly 'flatten out' a drawing, causing all
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    57
       widgets to be converted to primitives.""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    58
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    59
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    60
heading3("Using a Widget")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    61
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    62
disc("""
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    63
Let's imagine a simple new widget.
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    64
We will use a widget to draw a face, then show how it was implemented.""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    65
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    66
eg("""
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    67
>>> from reportlab.lib import colors
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    68
>>> from reportlab.graphics import shapes
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    69
>>> from reportlab.graphics import widgetbase
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    70
>>> from reportlab.graphics import renderPDF
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    71
>>> d = shapes.Drawing(200, 100)
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    72
>>> f = widgetbase.Face()
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    73
>>> f.skinColor = colors.yellow
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    74
>>> f.mood = "sad"
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    75
>>> d.add(f)
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    76
>>> renderPDF.drawToFile(d, 'face.pdf', 'A Face')
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    77
""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    78
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    79
from reportlab.graphics import widgetbase
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    80
d = Drawing(200, 120)
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    81
f = widgetbase.Face()
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    82
f.x = 50
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    83
f.y = 10
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    84
f.skinColor = colors.yellow
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    85
f.mood = "sad"
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    86
d.add(f)
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    87
draw(d, 'A sample widget')
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    88
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    89
disc("""
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    90
Let's see what properties it has available, using the $setProperties()$
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    91
method we have seen earlier:
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    92
""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    93
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    94
eg("""
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    95
>>> f.dumpProperties()
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    96
eyeColor = Color(0.00,0.00,1.00)
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    97
mood = sad
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    98
size = 80
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
    99
skinColor = Color(1.00,1.00,0.00)
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   100
x = 10
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   101
y = 10
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   102
>>>
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   103
""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   104
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   105
disc("""
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   106
One thing which seems strange about the above code is that we did not
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   107
set the size or position when we made the face.
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   108
This is a necessary trade-off to allow a uniform interface for
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   109
constructing widgets and documenting them - they cannot require
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   110
arguments in their $__init__()$ method.
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   111
Instead, they are generally designed to fit in a 200 x 100
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   112
window, and you move or resize them by setting properties such as
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   113
x, y, width and so on after creation.
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   114
""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   115
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   116
disc("""
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   117
In addition, a widget always provides a $demo()$ method.
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   118
Simple ones like this always do something sensible before setting
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   119
properties, but more complex ones like a chart would not have any
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   120
data to plot.
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   121
The documentation tool calls $demo()$ so that your fancy new chart
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   122
class can create a drawing showing what it can do.
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   123
""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   124
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   125
disc("""
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   126
Here are a handful of simple widgets available in the module
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   127
<i>signsandsymbols.py</i>:
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   128
""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   129
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   130
from reportlab.graphics.shapes import Drawing
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   131
from reportlab.graphics.widgets import signsandsymbols
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   132
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   133
d = Drawing(230, 230)
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   134
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   135
ne = signsandsymbols.NoEntry()
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   136
ds = signsandsymbols.DangerSign()
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   137
fd = signsandsymbols.FloppyDisk()
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   138
ns = signsandsymbols.NoSmoking()
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   139
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   140
ne.x, ne.y = 10, 10
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   141
ds.x, ds.y = 120, 10
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   142
fd.x, fd.y = 10, 120
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   143
ns.x, ns.y = 120, 120
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   144
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   145
d.add(ne)
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   146
d.add(ds)
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   147
d.add(fd)
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   148
d.add(ns)
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   149
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   150
draw(d, 'A few samples from signsandsymbols.py')
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   151
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   152
disc("""
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   153
And this is the code needed to generate them as seen in the drawing above:
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   154
""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   155
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   156
eg("""
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   157
from reportlab.graphics.shapes import Drawing
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   158
from reportlab.graphics.widgets import signsandsymbols
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   159
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   160
d = Drawing(230, 230)
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   161
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   162
ne = signsandsymbols.NoEntry()
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   163
ds = signsandsymbols.DangerSign()
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   164
fd = signsandsymbols.FloppyDisk()
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   165
ns = signsandsymbols.NoSmoking()
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   166
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   167
ne.x, ne.y = 10, 10
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   168
ds.x, ds.y = 120, 10
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   169
fd.x, fd.y = 10, 120
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   170
ns.x, ns.y = 120, 120
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   171
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   172
d.add(ne)
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   173
d.add(ds)
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   174
d.add(fd)
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   175
d.add(ns)
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   176
""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   177
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   178
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   179
heading3("Compound Widgets")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   180
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   181
disc("""Let's imagine a compound widget which draws two faces side by side.
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   182
       This is easy to build when you have the Face widget.""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   183
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   184
eg("""
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   185
>>> tf = widgetbase.TwoFaces()
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   186
>>> tf.faceOne.mood
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   187
'happy'
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   188
>>> tf.faceTwo.mood
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   189
'sad'
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   190
>>> tf.dumpProperties()
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   191
faceOne.eyeColor = Color(0.00,0.00,1.00)
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   192
faceOne.mood = happy
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   193
faceOne.size = 80
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   194
faceOne.skinColor = None
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   195
faceOne.x = 10
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   196
faceOne.y = 10
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   197
faceTwo.eyeColor = Color(0.00,0.00,1.00)
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   198
faceTwo.mood = sad
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   199
faceTwo.size = 80
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   200
faceTwo.skinColor = None
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   201
faceTwo.x = 100
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   202
faceTwo.y = 10
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   203
>>>
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   204
""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   205
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   206
disc("""The attributes 'faceOne' and 'faceTwo' are deliberately exposed so you
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   207
       can get at them directly. There could also be top-level attributes,
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   208
       but there aren't in this case.""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   209
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   210
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   211
heading3("Verifying Widgets")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   212
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   213
disc("""The widget designer decides the policy on verification, but by default
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   214
       they work like shapes - checking every assignment - if the designer
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   215
       has provided the checking information.""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   216
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   217
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   218
heading3("Implementing Widgets")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   219
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   220
disc("""We tried to make it as easy to implement widgets as possible. Here's
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   221
       the code for a Face widget which does not do any type checking:""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   222
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   223
eg("""
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   224
class Face(Widget):
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   225
    \"\"\"This draws a face with two eyes, mouth and nose.\"\"\"
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   226
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   227
    def __init__(self):
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   228
        self.x = 10
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   229
        self.y = 10
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   230
        self.size = 80
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   231
        self.skinColor = None
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   232
        self.eyeColor = colors.blue
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   233
        self.mood = 'happy'
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   234
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   235
    def draw(self):
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   236
        s = self.size  # abbreviate as we will use this a lot
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   237
        g = shapes.Group()
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   238
        g.transform = [1,0,0,1,self.x, self.y]
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   239
        # background
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   240
        g.add(shapes.Circle(s * 0.5, s * 0.5, s * 0.5,
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   241
                            fillColor=self.skinColor))
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   242
        # CODE OMITTED TO MAKE MORE SHAPES
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   243
        return g
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   244
""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   245
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   246
disc("""We left out all the code to draw the shapes in this document, but you
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   247
       can find it in the distribution in $widgetbase.py$.""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   248
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   249
disc("""By default, any attribute without a leading underscore is returned by
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   250
       setProperties. This is a deliberate policy to encourage consistent
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   251
       coding conventions.""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   252
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   253
disc("""Once your widget works, you probably want to add support for
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   254
       verification. This involves adding a dictionary to the class called
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   255
       $_verifyMap$, which map from attribute names to 'checking functions'.
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   256
       The $widgetbase.py$ module defines a bunch of checking functions with names
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   257
       like $isNumber$, $isListOfShapes$ and so on. You can also simply use $None$,
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   258
       which means that the attribute must be present but can have any type.
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   259
       And you can and should write your own checking functions. We want to
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   260
       restrict the "mood" custom attribute to the values "happy", "sad" or
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   261
       "ok". So we do this:""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   262
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   263
eg("""
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   264
class Face(Widget):
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   265
    \"\"\"This draws a face with two eyes.  It exposes a
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   266
    couple of properties to configure itself and hides
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   267
    all other details\"\"\"
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   268
    def checkMood(moodName):
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   269
        return (moodName in ('happy','sad','ok'))
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   270
    _verifyMap = {
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   271
        'x': shapes.isNumber,
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   272
        'y': shapes.isNumber,
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   273
        'size': shapes.isNumber,
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   274
        'skinColor':shapes.isColorOrNone,
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   275
        'eyeColor': shapes.isColorOrNone,
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   276
        'mood': checkMood
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   277
        }
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   278
""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   279
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   280
disc("""This checking will be performed on every attribute assignment; or, if
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   281
       $config.shapeChecking$ is off, whenever you call $myFace.verify()$.""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   282
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   283
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   284
heading3("Documenting Widgets")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   285
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   286
disc("""
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   287
We are working on a generic tool to document any Python package or
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   288
module; this is already checked into ReportLab and will be used to
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   289
generate a reference for the ReportLab package.
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   290
When it encounters widgets, it adds extra sections to the
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   291
manual including:""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   292
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   293
bullet("the doc string for your widget class ")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   294
bullet("the code snippet from your <i>demo()</i> method, so people can see how to use it")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   295
bullet("the drawing produced by the <i>demo()</i> method ")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   296
bullet("the property dump for the widget in the drawing. ")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   297
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   298
disc("""
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   299
This tool will mean that we can have guaranteed up-to-date
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   300
documentation on our widgets and charts, both on the web site
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   301
and in print; and that you can do the same for your own widgets,
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   302
too!
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   303
""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   304
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   305
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   306
heading3("Widget Design Strategies")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   307
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   308
disc("""We could not come up with a consistent architecture for designing
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   309
       widgets, so we are leaving that problem to the authors! If you do not
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   310
       like the default verification strategy, or the way
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   311
       $setProperties/getProperties$ works, you can override them yourself.""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   312
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   313
disc("""For simple widgets it is recommended that you do what we did above:
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   314
       select non-overlapping properties, initialize every property on
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   315
       $__init__$ and construct everything when $draw()$ is called. You can
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   316
       instead have $__setattr__$ hooks and have things updated when certain
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   317
       attributes are set. Consider a pie chart. If you want to expose the
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   318
       individual wedges, you might write code like this:""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   319
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   320
eg("""
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   321
from reportlab.graphics.charts import piecharts
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   322
pc = piecharts.Pie()
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   323
pc.defaultColors = [navy, blue, skyblue] #used in rotation
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   324
pc.data = [10,30,50,25]
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   325
pc.slices[7].strokeWidth = 5
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   326
""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   327
#removed 'pc.backColor = yellow' from above code example
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   328
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   329
disc("""The last line is problematic as we have only created four wedges - in
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   330
       fact we might not have created them yet. Does $pc.wedges[7]$ raise an
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   331
       error? Is it a prescription for what should happen if a seventh wedge
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   332
       is defined, used to override the default settings? We dump this
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   333
       problem squarely on the widget author for now, and recommend that you
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   334
       get a simple one working before exposing 'child objects' whose
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   335
       existence depends on other properties' values :-)""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   336
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   337
disc("""We also discussed rules by which parent widgets could pass properties
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   338
       to their children. There seems to be a general desire for a global way
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   339
       to say that 'all wedges get their lineWidth from the lineWidth of
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   340
       their parent' without a lot of repetitive coding. We do not have a
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   341
       universal solution, so again leave that to widget authors. We hope
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   342
       people will experiment with push-down, pull-down and pattern-matching
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   343
       approaches and come up with something nice. In the meantime, we
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   344
       certainly can write monolithic chart widgets which work like the ones
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   345
       in, say, Visual Basic and Delphi.""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   346
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   347
disc("""For now have a look at the following sample code using an early
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   348
       version of a pie chart widget and the output it generates:""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   349
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   350
eg("""
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   351
from reportlab.lib.colors import *
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   352
from reportlab.graphics import shapes,renderPDF
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   353
from reportlab.graphics.charts.piecharts import Pie
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   354
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   355
d = Drawing(400,200)
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   356
d.add(String(100,175,"Without labels", textAnchor="middle"))
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   357
d.add(String(300,175,"With labels", textAnchor="middle"))
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   358
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   359
pc = Pie()
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   360
pc.x = 25
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   361
pc.y = 50
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   362
pc.data = [10,20,30,40,50,60]
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   363
pc.slices[0].popout = 5
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   364
d.add(pc, 'pie1')
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   365
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   366
pc2 = Pie()
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   367
pc2.x = 150
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   368
pc2.y = 50
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   369
pc2.data = [10,20,30,40,50,60]
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   370
pc2.labels = ['a','b','c','d','e','f']
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   371
d.add(pc2, 'pie2')
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   372
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   373
pc3 = Pie()
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   374
pc3.x = 275
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   375
pc3.y = 50
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   376
pc3.data = [10,20,30,40,50,60]
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   377
pc3.labels = ['a','b','c','d','e','f']
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   378
pc3.wedges.labelRadius = 0.65
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   379
pc3.wedges.fontName = "Helvetica-Bold"
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   380
pc3.wedges.fontSize = 16
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   381
pc3.wedges.fontColor = colors.yellow
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   382
d.add(pc3, 'pie3')
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   383
""")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   384
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   385
# Hack to force a new paragraph before the todo() :-(
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   386
disc("")
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   387
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   388
from reportlab.lib.colors import *
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   389
from reportlab.graphics import shapes,renderPDF
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   390
from reportlab.graphics.charts.piecharts import Pie
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   391
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   392
d = Drawing(400,200)
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   393
d.add(String(100,175,"Without labels", textAnchor="middle"))
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   394
d.add(String(300,175,"With labels", textAnchor="middle"))
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   395
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   396
pc = Pie()
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   397
pc.x = 25
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   398
pc.y = 50
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   399
pc.data = [10,20,30,40,50,60]
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   400
pc.slices[0].popout = 5
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   401
d.add(pc, 'pie1')
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   402
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   403
pc2 = Pie()
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   404
pc2.x = 150
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   405
pc2.y = 50
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   406
pc2.data = [10,20,30,40,50,60]
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   407
pc2.labels = ['a','b','c','d','e','f']
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   408
d.add(pc2, 'pie2')
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   409
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   410
pc3 = Pie()
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   411
pc3.x = 275
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   412
pc3.y = 50
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   413
pc3.data = [10,20,30,40,50,60]
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   414
pc3.labels = ['a','b','c','d','e','f']
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   415
pc3.slices.labelRadius = 0.65
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   416
pc3.slices.fontName = "Helvetica-Bold"
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   417
pc3.slices.fontSize = 16
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   418
pc3.slices.fontColor = colors.yellow
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   419
d.add(pc3, 'pie3')
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   420
d47129e56d9f Merged graphguide into userguide.
jonas
parents:
diff changeset
   421
draw(d, 'Some sample Pies')