[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 os
17 import gs_frontend
18 import theme
19
20 class T(gs_frontend.T):
21     def close(self):
22         gs_frontend.T.close(self)
23         if self.__output_lines == []:
24             return
25
26         if theme.use_color:
27             gs_args = "-sDEVICE=png256 -dTextAlphaBits=4 -q -dNOPAUSE" #PDS
28         else:
29             gs_args = "-sDEVICE=pnggray -dTextAlphaBits=4 -q -dNOPAUSE" #PDS
30
31             
32         temp_fname = None # the temporary file desc.
33         out_fd = None  # the final destination. 
34         
35         if self.__out_fname and isinstance(self.__out_fname, str):
36             gs_args += " -sOutputFile=%s" % self.__out_fname
37         else:
38             if not self.__out_fname:
39                 out_fd = sys.stdout
40             else:
41                 if not hasattr(self.__out_fname, "write"):
42                     raise Exception, "Expecting either a filename or a file-like object, but got %s" % self.__out_fname
43                 out_fd = self.__out_fname
44             import tempfile
45             temp_fname = tempfile.mktemp()
46             gs_args += " -sOutputFile=%s" % temp_fname
47         self.start_gs(gs_args)
48         self.close_gs()
49
50         if temp_fname:
51             temp_fd = file(temp_fname, 'rb')
52             out_fd.write(temp_fd.read())
53             temp_fd.close()
54             
55
56