[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 string
16 import sys
17 import re
18 import os.path
19 from pychart import *
20 from types import *
21 from pychart.pychart_types import *
22
23 oldstdout = sys.stdout
24 if os.path.exists("/dev/null"):
25     sys.stdout = open("/dev/null", "w")
26
27 modules = {}
28 values = []
29
30 sys.stdout = oldstdout
31 g = globals()
32 for mod in g.keys():
33     val = g[mod]
34     if type(val) == ModuleType:
35         dic = {}
36         for name in val.__dict__.keys():
37             v = val.__dict__[name]
38             if name[0] != '_':
39                 values.append((v, mod + "." + name))
40             if type(v) == type and issubclass(v, chart_object.T):
41                 dic[name] = v
42         modules[mod] = dic
43
44 def stringify_type(t):
45     s = str(t)
46     if t == AnyType:
47         return "any"
48     if t == ShadowType:
49         return "(xoff,yoff,fill)"
50     elif re.search("NumType", s):    
51         return "number"
52     elif re.search("UnitType", s):    
53         return "length in points (\\\\xref{unit})"
54     elif re.search("CoordType", s):
55         return "(x,y)"
56     elif re.search("CoordSystemType", s):
57         return "['linear'|'log'|'category']"
58     elif re.search("CoordOrNoneType", s):
59         return "(x,y) or None"
60     elif re.search("TextAlignType", s):
61         return "['R'|'L'|'C'|None]"
62     elif re.search("FormatType", s):
63         return "printf format string"
64     elif re.search("IntervalType", s):
65         return "Number or function"
66
67     mo = re.match("<type '([^']+)'>", s)
68     if mo:
69         return mo.group(1)
70     mo = re.match("<class 'pychart\.([^']+)'>", s)
71     if mo:
72         return mo.group(1)
73     mo = re.match("<class '([^']+)'>", s)
74     if mo:
75         return mo.group(1)
76     mo = re.match("pychart\\.(.*)", s)
77     if mo:
78         return mo.group(1)
79     return s
80
81 def stringify_value(val):
82     t = type(val)
83     if t == StringType:
84         return '"' + val + '"'
85     if t == bool:
86         if val: return "True"
87         else: return "False"
88         
89     if t in (IntType, LongType, FloatType):
90         return str(val)
91     if val == None:
92         return "None"
93     if type(val) == ListType:
94         return map(stringify_value, val)
95     for pair in values:
96         if pair[0] == val:
97             return pair[1]
98     return str(val)
99
100 def break_string(name):
101     max_len = 10
102     if len(name) < max_len:
103         return name
104     
105     name = re.sub("(\\d\\d)([^\\d])", "\\1-\n\\2", name) 
106     name = re.sub("black(.)", "black-\n\\1", name)
107
108     elems = string.split(name, "\n")
109     while 1:
110         broken = 0
111         for i in range(len(elems)):
112             elem = elems[i]
113             if len(elem) < max_len:
114                 continue
115             broken = 1
116             elem1 = elem[0:len(elem)/2]
117             elem2 = elem[len(elem)/2:]
118             elems[i:i+1] = [elem1, elem2]
119             break
120         if not broken:
121             break
122     name = "\n".join(elems)
123     return name