[MERGE] Remove the embedded pychart library, and use the online version
[odoo/odoo.git] /
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2000-2005 by Yasushi Saito (yasushi.saito@gmail.com)
4
5 # Jockey is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 2, or (at your option) any
8 # later version.
9 #
10 # Jockey is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13 # for more details.
14 #
15 import color
16 import pychart_util
17 import chart_object
18 import object_set
19 import theme
20 import line_style_doc
21 from pychart_types import *
22 from types import *
23
24 _keys = {
25     "width" : (UnitType, theme.default_line_width, "Width of the line, in points."),
26     "color": (color.T, color.default, "The color of the line."),
27     "dash" : (TupleType, None,
28               """The value
29               of None will draw a solid line. Otherwise, this
30               attribute specifies the style of dashed lines. 
31               The 2N'th value specifies the length of the line (in points), 
32               and 2N+1'th value specifies the length of the blank.
33
34               For example, the dash style of (3,2,4,1) draws a dashed line that
35               looks like @samp{---__----_---__----_...}.
36               """),
37     "cap_style": (IntType, 0,
38                   """Defines the style of the tip of the line segment.
39                   0: butt cap (square cutoff, with no projection beyond),
40                   1: round cap (arc), 2: projecting square cap
41                   (square cutoff, but the line extends half the line width).
42                   See also Postscript/PDF reference manual."""),
43     "join_style": (IntType, 0,
44                    """Join style. 0: Miter join (sharp, pointed corners),
45                    1: round join (rounded corners),
46                    2: bevel join (flattened corners).
47                    See also Postscript/PDF reference manual.""")
48     }
49
50 class T(chart_object.T):
51     __doc__ = line_style_doc.doc
52     keys = _keys
53 ##AUTOMATICALLY GENERATED
54
55 ##END AUTOMATICALLY GENERATED
56     def __str__(self):
57         s = name_table().lookup(self)
58         if s:
59             return s
60         return "<linestyle: width=%s, color=%s, dash=%s, cap=%d, join=%d>" \
61                % (self.width, self.color, self.dash, self.cap_style, self.join_style)
62     
63 default = T(color=color.default)
64
65 dash1 = 1.5,1.5  # - - - -
66 dash2 = 5,2,5,2  # -- -- -- --
67 dash3 = 1,1
68
69 black = T(color=color.black)
70 black_dash1 = T(color=color.black, dash=dash1)
71 black_dash2 = T(color=color.black, dash=dash2)
72 black_dash3 = T(color=color.black, dash=dash3)
73
74 gray70 = T(color=color.gray70)
75 gray70_dash1 = T(color=color.gray70, dash=dash1)
76 gray70_dash2 = T(color=color.gray70, dash=dash2)
77 gray70_dash3 = T(color=color.gray70, dash=dash3)
78
79 gray10 = T(color=color.gray10)
80 gray10_dash1 = T(color=color.gray10, dash=dash1)
81 gray10_dash2 = T(color=color.gray10, dash=dash2)
82 gray10_dash3 = T(color=color.gray10, dash=dash3)
83
84 gray50 = T(color=color.gray50)
85 gray50_dash1 = T(color=color.gray50, dash=dash1)
86 gray50_dash2 = T(color=color.gray50, dash=dash2)
87 gray50_dash3 = T(color=color.gray50, dash=dash3)
88
89 gray60 = T(color=color.gray60)
90 gray60_dash1 = T(color=color.gray60, dash=dash1)
91 gray60_dash2 = T(color=color.gray60, dash=dash2)
92 gray60_dash3 = T(color=color.gray60, dash=dash3)
93
94 gray90 = T(color=color.gray90)
95 gray90_dash1 = T(color=color.gray90, dash=dash1)
96 gray90_dash2 = T(color=color.gray90, dash=dash2)
97 gray90_dash3 = T(color=color.gray90, dash=dash3)
98
99 gray30 = T(color=color.gray30)
100 gray30_dash1 = T(color=color.gray30, dash=dash1)
101 gray30_dash2 = T(color=color.gray30, dash=dash2)
102 gray30_dash3 = T(color=color.gray30, dash=dash3)
103
104 white = T(color=color.white)
105 default = black
106
107 red = T(color=color.red)
108 darkblue = T(color=color.darkblue)
109 darkseagreen = T(color=color.darkseagreen)
110 darkkhaki = T(color = color.darkkhaki)
111
112 blue = T(color=color.blue)
113 green = T(color=color.green)
114
115 red_dash1 = T(color=color.red, dash=dash1)
116 darkblue_dash1 = T(color=color.darkblue, dash=dash1)
117 darkseagreen_dash1 = T(color=color.darkseagreen, dash=dash1)
118 darkkhaki_dash1 = T(color=color.darkkhaki, dash=dash1)
119     
120 red_dash2 = T(color=color.red, dash=dash2)
121 darkblue_dash2 = T(color=color.darkblue, dash=dash2)
122 darkseagreen_dash2 = T(color=color.darkseagreen, dash=dash2)
123 darkkhaki_dash2 = T(color=color.darkkhaki, dash=dash2)
124
125 standards = None
126 _name_table = None
127
128 def init():
129     global standards, _name_table
130     standards = object_set.T()
131     
132     if theme.use_color:
133         standards.add(black, red, darkblue, gray70, darkseagreen,
134                       darkkhaki, gray30,
135                       black_dash1, red_dash1, darkblue_dash1, gray70_dash1,
136                       darkseagreen_dash1, darkkhaki_dash1, gray30_dash1,
137                       black_dash2, red_dash2, darkblue_dash2, gray70_dash2,
138                       darkseagreen_dash2, darkkhaki_dash2, gray30_dash2)
139     else:
140         standards.add(black, black_dash1, black_dash2,
141                       gray70, gray70_dash1, gray70_dash2,
142                       gray10, gray10_dash1, gray10_dash2,
143                       gray50, gray50_dash1, gray50_dash2,
144                       gray90, gray90_dash1, gray90_dash2,
145                       gray30, gray30_dash1, gray30_dash2,
146                       black_dash3,
147                       gray70_dash3, gray10_dash3, gray50_dash3, gray90_dash3)
148     for style in standards.list():
149         style.width = theme.default_line_width
150     _name_table = None
151     
152 def name_table():
153     global _name_table
154     if not _name_table:
155         _name_table = pychart_util.symbol_lookup_table(globals(), standards)
156     return _name_table
157
158 init()
159 theme.add_reinitialization_hook(init)