~syleam/openobject-server/exit-properly

« back to all changes in this revision

Viewing changes to bin/pychart/doc_support.py

  • Committer: pinky
  • Date: 2006-12-07 13:41:40 UTC
  • Revision ID: pinky-3f10ee12cea3c4c75cef44ab04ad33ef47432907
New trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Copyright (C) 2000-2005 by Yasushi Saito (yasushi.saito@gmail.com)
 
3
 
4
# Jockey is free software; you can redistribute it and/or modify it
 
5
# under the terms of the GNU General Public License as published by the
 
6
# Free Software Foundation; either version 2, or (at your option) any
 
7
# later version.
 
8
#
 
9
# Jockey is distributed in the hope that it will be useful, but WITHOUT
 
10
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
11
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 
12
# for more details.
 
13
#
 
14
import string
 
15
import sys
 
16
import re
 
17
import os.path
 
18
from pychart import *
 
19
from types import *
 
20
from pychart.pychart_types import *
 
21
 
 
22
oldstdout = sys.stdout
 
23
if os.path.exists("/dev/null"):
 
24
    sys.stdout = open("/dev/null", "w")
 
25
 
 
26
modules = {}
 
27
values = []
 
28
 
 
29
sys.stdout = oldstdout
 
30
g = globals()
 
31
for mod in g.keys():
 
32
    val = g[mod]
 
33
    if type(val) == ModuleType:
 
34
        dic = {}
 
35
        for name in val.__dict__.keys():
 
36
            v = val.__dict__[name]
 
37
            if name[0] != '_':
 
38
                values.append((v, mod + "." + name))
 
39
            if type(v) == type and issubclass(v, chart_object.T):
 
40
                dic[name] = v
 
41
        modules[mod] = dic
 
42
 
 
43
def stringify_type(t):
 
44
    s = str(t)
 
45
    if t == AnyType:
 
46
        return "any"
 
47
    if t == ShadowType:
 
48
        return "(xoff,yoff,fill)"
 
49
    elif re.search("NumType", s):    
 
50
        return "number"
 
51
    elif re.search("UnitType", s):    
 
52
        return "length in points (\\\\xref{unit})"
 
53
    elif re.search("CoordType", s):
 
54
        return "(x,y)"
 
55
    elif re.search("CoordSystemType", s):
 
56
        return "['linear'|'log'|'category']"
 
57
    elif re.search("CoordOrNoneType", s):
 
58
        return "(x,y) or None"
 
59
    elif re.search("TextAlignType", s):
 
60
        return "['R'|'L'|'C'|None]"
 
61
    elif re.search("FormatType", s):
 
62
        return "printf format string"
 
63
    elif re.search("IntervalType", s):
 
64
        return "Number or function"
 
65
 
 
66
    mo = re.match("<type '([^']+)'>", s)
 
67
    if mo:
 
68
        return mo.group(1)
 
69
    mo = re.match("<class 'pychart\.([^']+)'>", s)
 
70
    if mo:
 
71
        return mo.group(1)
 
72
    mo = re.match("<class '([^']+)'>", s)
 
73
    if mo:
 
74
        return mo.group(1)
 
75
    mo = re.match("pychart\\.(.*)", s)
 
76
    if mo:
 
77
        return mo.group(1)
 
78
    return s
 
79
 
 
80
def stringify_value(val):
 
81
    t = type(val)
 
82
    if t == StringType:
 
83
        return '"' + val + '"'
 
84
    if t == bool:
 
85
        if val: return "True"
 
86
        else: return "False"
 
87
        
 
88
    if t in (IntType, LongType, FloatType):
 
89
        return str(val)
 
90
    if val == None:
 
91
        return "None"
 
92
    if type(val) == ListType:
 
93
        return map(stringify_value, val)
 
94
    for pair in values:
 
95
        if pair[0] == val:
 
96
            return pair[1]
 
97
    return str(val)
 
98
 
 
99
def break_string(name):
 
100
    max_len = 10
 
101
    if len(name) < max_len:
 
102
        return name
 
103
    
 
104
    name = re.sub("(\\d\\d)([^\\d])", "\\1-\n\\2", name) 
 
105
    name = re.sub("black(.)", "black-\n\\1", name)
 
106
 
 
107
    elems = string.split(name, "\n")
 
108
    while 1:
 
109
        broken = 0
 
110
        for i in range(len(elems)):
 
111
            elem = elems[i]
 
112
            if len(elem) < max_len:
 
113
                continue
 
114
            broken = 1
 
115
            elem1 = elem[0:len(elem)/2]
 
116
            elem2 = elem[len(elem)/2:]
 
117
            elems[i:i+1] = [elem1, elem2]
 
118
            break
 
119
        if not broken:
 
120
            break
 
121
    name = "\n".join(elems)
 
122
    return name