~activity/openobject-server/trunk

« back to all changes in this revision

Viewing changes to bin/pychart/pychart_types.py

  • Committer: Dainius Malachovskis
  • Date: 2009-06-11 21:01:55 UTC
  • mfrom: (1235.2.5 server)
  • Revision ID: dainius.malachovskis@sandas.eu-20090611210155-ql9k1pd0dnr9avr0
merged

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
12
# for more details.
13
13
#
14
 
import pychart_util
15
 
import types
16
 
AnyType = 9998
17
 
 
18
 
def CoordType(val):
19
 
    if type(val) != types.TupleType and type(val) != types.ListType:
20
 
        return (" not a valid coordinate.")
21
 
    if len(val) != 2:
22
 
        return "Coordinate must be a pair of numbers.\n"
23
 
    if val[0] != None:
24
 
        error = NumType(val[0])
25
 
        if error: return error
26
 
    if val[1] != None:    
27
 
        error = NumType(val[1])
28
 
        if error: return error
29
 
    return None    
30
 
 
31
 
def IntervalType(val):
32
 
    if type(val) in (types.IntType, types.LongType,
33
 
                     types.FloatType, types.FunctionType):
34
 
        return None
35
 
    return "Expecting a number or a function"
36
 
 
37
 
def CoordOrNoneType(val):
38
 
    if type(val) not in (types.TupleType, types.ListType):
39
 
        return "Expecting a tuple or a list."
40
 
    if len(val) != 2:
41
 
        return "Coordinate must be a pair of numbers.\n"
42
 
    for v in val:
43
 
        if v != None and NumType(val[0]) != None:
44
 
            return "Expecting a pair of numbers"
45
 
    return None    
46
 
    
47
 
def NumType(val):
48
 
    if type(val) in (types.IntType, types.LongType, types.FloatType):
49
 
        return None
50
 
    else:
51
 
        return "Expecting a number, found \"" + str(val) + "\""
52
 
 
53
 
def UnitType(val):
54
 
    if type(val) in (types.IntType, types.LongType, types.FloatType):
55
 
        return None
56
 
    else:
57
 
        return "Expecting a unit, found \"" + str(val) + "\""
58
 
    
59
 
def ShadowType(val):
60
 
    if type(val) not in (types.TupleType, types.ListType):
61
 
        return "Expecting tuple or list."
62
 
    if len(val) != 3:
63
 
        return "Expecting (xoff, yoff, fill)."
64
 
    return None
65
 
 
66
 
def FormatType(val):
67
 
    if type(val) in (types.StringType, types.FunctionType):
68
 
        return None
69
 
    return "Format must be a string or a function"
70
 
 
 
14
import pychart_util
 
15
import types
 
16
AnyType = 9998
 
17
 
 
18
def IntervalType(val):
 
19
    if type(val) in (types.IntType, types.LongType,
 
20
                     types.FloatType, types.FunctionType):
 
21
        return None
 
22
    return "Expecting a number or a function"
 
23
 
 
24
def CoordType(val):
 
25
    if type(val) not in (types.TupleType, types.ListType):
 
26
        return "Expecting a tuple or a list"
 
27
    if len(val) != 2:
 
28
        return "Coordinate must be a pair of numbers"
 
29
    for v in val:
 
30
        if v != None and NumberType(v):
 
31
            return "Expecting a pair of numbers (got %s)" % str(v)
 
32
    return None 
 
33
    
 
34
def NumberType(val):
 
35
    if type(val) in (types.IntType, types.LongType, types.FloatType):
 
36
        return None
 
37
    else:
 
38
        return "Expecting a number"
 
39
 
 
40
def UnitType(val):
 
41
    if type(val) in (types.IntType, types.LongType, types.FloatType):
 
42
        return
 
43
    else:
 
44
        return "Expecting a unit"
 
45
def ShadowType(val):
 
46
    if type(val) not in (types.TupleType, types.ListType):
 
47
        return "Expecting tuple or list."
 
48
    if len(val) != 3:
 
49
        return "Expecting (xoff, yoff, fill)."
 
50
    return None
 
51
 
 
52
def FormatType(val):
 
53
    if type(val) in (types.StringType, types.FunctionType):
 
54
        return None
 
55
    return "Format must be a string or a function"
 
56