[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 sys
16 import basecanvas
17 import pscanvas
18 import pdfcanvas
19 import svgcanvas
20 import pngcanvas
21 import x11canvas
22 import theme
23 import re
24
25 invalid_coord = -999999
26 _oldexitfunc = None
27
28 T = basecanvas.T
29
30 def init(fname = None, format = None):
31
32     """This is a "factory" procedure that creates a new canvas.T object.
33     Both parameters, <fname> and
34     <format>, are optional. Parameter <fname> specifies either the output
35     file name or a file object. Parameter <format>, if specified, defines the
36     file's format. Its value must be one of "ps", "pdf", "svg", "x11", or
37     "png".
38
39     When <fname> is omitted or is None, the output is sent to standard
40     output. When <format> is omitted, it is guessed from the <fname>'s
41     suffix; failing that, "ps" is selected."""
42     
43     fname = fname or theme.output_file
44     format = format or theme.output_format
45     
46     if format == None:
47         if not isinstance(fname, str):
48             format = "ps"
49         elif re.search("pdf$", fname):
50             format = "pdf"
51         elif re.search("png$", fname):
52             format = "png"
53         elif re.search("svg$", fname):
54             format = "svg"
55         else:
56             format = "ps"
57
58     if format == "ps":
59         can = pscanvas.T(fname)
60     elif format == "png":
61         can = pngcanvas.T(fname)
62     elif format == "x11":
63         can = x11canvas.T(fname)
64     elif format == "svg":               
65         can = svgcanvas.T(fname)
66     else:
67         can = pdfcanvas.T(fname, theme.compress_output)
68     return can
69
70 def default_canvas():
71     if len(basecanvas.active_canvases) > 0:
72         return basecanvas.active_canvases[0]
73     else:
74         return init(None)
75
76 def _exit():
77     global _oldexitfunc, _active_canvases
78     
79     for can in basecanvas.active_canvases[:]:
80         can.close()
81         
82     if _oldexitfunc:
83         foo = _oldexitfunc
84         _oldexitfunc = None
85         foo()
86
87 #
88 # The following procedures are there just for backward compatibility.
89
90 def line(style, x1, y1, x2, y2):
91     default_canvas().line(style, x1, y1, x2, y2)
92 def curve(style, points):
93     default_canvas().curve(style, points)
94 def clip(x1, y1, x2, y2):
95     default_canvas().clip(x1, y1, x2, y2)
96 def endclip():
97     default_canvas().endclip()
98 def clip_polygon(points):
99     default_canvas().clip_polygon(points)
100 def clip_ellipsis(x, y, radius, ratio = 1.0):
101     default_canvas().clip_ellipsis(x, y, radius, ratio)
102 def ellipsis(line_style, pattern, x, y, radius, ratio = 1.0,
103              start_angle=0, end_angle=360, shadow=None):
104     default_canvas().ellipsis(line_style, pattern, x, y, radius, ratio,
105                               start_angle, end_angle, shadow)
106 def rectangle(edge_style, pat, x1, y1, x2, y2, shadow = None):
107     default_canvas().rectangle(edge_style, pat, x1, y1, x2, y2, shadow)
108 def polygon(edge_style, pat, points, shadow = None):
109     default_canvas().polygon(edge_style, pat, points, shadow = None)
110 def close():
111     default_canvas().close()
112 def round_rectangle(style, fill, x1, y1, x2, y2, radius, shadow=None):
113     default_canvas().round_rectangle(style, fill, x1, y1, x2, y2, radius, shadow)
114 def show(x, y, str):
115     default_canvas().show(x, y, str)
116     
117
118 if not vars(sys).has_key("exitfunc"):
119     sys.exitfunc = _exit
120 elif sys.exitfunc != _exit:
121     _oldexitfunc = sys.exitfunc
122     sys.exitfunc = _exit
123
124 #theme.add_reinitialization_hook(lambda: init(None))