Added TODO and DEVELOPMENT.
[faces-project.git] / faces / charting / shapes.py
bloba6006591cba8999d57efd098928b693aa387a566
1 #@+leo-ver=4
2 #@+node:@file charting/shapes.py
3 #@+at
4 # gantt widgets can have the different shapes in this modules.
5 #
6 # For all shapes:
7 # the first item of the returned shape list, has to be a patch, that defines,
8 # the connection points
9 #
11 #@-at
12 #@@code
13 #@@language python
14 #@<< Copyright >>
15 #@+node:<< Copyright >>
16 ############################################################################
17 # Copyright (C) 2005, 2006, 2007, 2008 by Reithinger GmbH
18 # mreithinger@web.de
20 # This file is part of faces.
22 # faces is free software; you can redistribute it and/or modify
23 # it under the terms of the GNU General Public License as published by
24 # the Free Software Foundation; either version 2 of the License, or
25 # (at your option) any later version.
27 # faces is distributed in the hope that it will be useful,
28 # but WITHOUT ANY WARRANTY; without even the implied warranty of
29 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 # GNU General Public License for more details.
32 # You should have received a copy of the GNU General Public License
33 # along with this program; if not, write to the
34 # Free Software Foundation, Inc.,
35 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36 ############################################################################
38 #@-node:<< Copyright >>
39 #@nl
40 #@<< Imports >>
41 #@+node:<< Imports >>
42 from patches import *
43 from tools import *
44 import widgets
47 #@-node:<< Imports >>
48 #@nl
50 __all__ = ("bar", "brace", "combibar", "diamond", "circle", "wedge", "house")
51 _is_source_ = True
53 #@+others
54 #@+node:bar
55 def bar(props, name, complete=0):
56 kwargs = make_properties(props, name)
57 bar = Polygon(((LEFT, BOTTOM),
58 (LEFT, VCENTER),
59 (LEFT, TOP),
60 (HCENTER, TOP),
61 (RIGHT, TOP),
62 (RIGHT, VCENTER),
63 (RIGHT, BOTTOM),
64 (HCENTER, BOTTOM)), **kwargs)
65 if complete:
66 kwargs = make_properties(props, "%s.complete" % name)
67 complete /= 100.0
68 complete = Rectangle((LEFT, BOTTOM + VSEP * FACTOR / 4),
69 (RIGHT - LEFT) * complete,
70 VSEP * FACTOR / 2,
71 **kwargs)
72 return (bar, complete)
74 return (bar,)
75 #@-node:bar
76 #@+node:brace
77 def brace(props, name):
78 kwargs = make_properties(props, name)
79 HALF = FACTOR / 2
80 return (Polygon([(LEFT, TOP),
81 (RIGHT, TOP),
82 (RIGHT, BOTTOM),
83 (RIGHT - HALF * HSEP, BOTTOM + HALF * VSEP),
84 (LEFT + HALF * HSEP, BOTTOM + HALF * VSEP),
85 (LEFT, BOTTOM)], **kwargs),)
86 #@-node:brace
87 #@+node:combibar
88 def combibar(props, name, left, right, complete):
89 left = left(props, name + ".start", VCENTER, LEFT)
90 right = right(props, name + ".end", VCENTER, RIGHT)
92 half_height = props(name + ".bar.height") * VSEP / 2
93 top = VCENTER + half_height
94 bottom = VCENTER - half_height
96 def left_vert(vert):
97 x, y = float(vert[0]), float(vert[1])
98 return x < LEFT.get() or y > top.get() or y < bottom.get()
100 def right_vert(vert):
101 x, y = float(vert[0]), float(vert[1])
102 return x > RIGHT.get() or y > top.get() or y < bottom.get()
104 outline_verts = filter(left_vert, left[0].get_verts())\
105 + [(HCENTER, top), (HCENTER, bottom)] \
106 + filter(right_vert, right[0].get_verts())
108 outline = Polygon(outline_verts)
109 outline.set_visible(False)
111 kwargs = make_properties(props, name + ".bar")
112 bar = Polygon([(LEFT, top), (RIGHT, top),
113 (RIGHT, bottom), (LEFT, bottom)], **kwargs)
115 #only take the visible part of the symbols
116 sleft = left[int(len(left) > 1)]
117 sright = right[int(len(right) > 1)]
119 if complete:
120 kwargs = make_properties(props, name + ".complete")
121 half_height = props(name + ".complete.height") * VSEP / 2
122 top = VCENTER + half_height
123 bottom = VCENTER - half_height
124 right = LEFT + (RIGHT - LEFT) * complete / 100
125 complete = Polygon([(LEFT, top), (right, top),
126 (right, bottom), (LEFT, bottom)], **kwargs)
128 return (outline, bar, complete, sleft, sright)
130 return (outline, bar, sleft, sright)
131 #@-node:combibar
132 #@+node:diamond
133 def diamond(props, name="", vc=None, hc=None):
135 A diamond symbol, that can be be used as an argument,
136 for a widgets set_shape method or for a combined shape
137 like combibar.
139 @args:
141 if name: name = ".%s" % name
142 vc = vc or VCENTER
143 hc = hc or HCENTER
144 kwargs = make_properties(props, "diamond" + name)
145 mag = props("diamond" + name + ".magnification")
146 HALF = mag * FACTOR / 2
147 return (Polygon([(hc - HALF * HSEP, vc),
148 (hc, vc - HALF * VSEP),
149 (hc + HALF * HSEP, vc),
150 (hc, vc + HALF * VSEP)], **kwargs),)
151 #@-node:diamond
152 #@+node:circle
153 def circle(props, name="", vc=None, hc=None):
154 if name: name = ".%s" % name
155 vc = vc or VCENTER
156 hc = hc or HCENTER
157 kwargs = make_properties(props, "circle" + name)
158 mag = props("circle" + name + ".magnification")
160 HALF = mag * FACTOR / 2
162 shape = (Polygon([(hc - HALF * HSEP, vc),
163 (hc, vc - HALF * VSEP),
164 (hc + HALF * HSEP, vc),
165 (hc, vc + HALF * VSEP)]),
166 Circle((hc, vc), HALF*VSEP, **kwargs))
167 shape[0].set_visible(False)
168 return shape
169 #@-node:circle
170 #@+node:wedge
171 def wedge(props, name="", vc=None, hc=None):
172 if name: name = ".%s" % name
173 vc = vc or VCENTER
174 hc = hc or HCENTER
175 kwargs = make_properties(props, "wedge" + name)
176 mag = props("wedge" + name + ".magnification")
178 HALF = mag * FACTOR / 2
180 if props("wedge" + name + ".up", True):
181 base = VCENTER - HALF * VSEP
182 head = VCENTER + HALF * VSEP
183 else:
184 base = VCENTER + HALF * VSEP
185 head = VCENTER - HALF * VSEP
187 return (Polygon([(hc - HALF * HSEP, base),
188 (hc, base),
189 (hc + HALF * HSEP, base),
190 (hc + HALF * HSEP / 2, vc),
191 (hc, head),
192 (hc - HALF * HSEP / 2, vc)], **kwargs),)
193 #@-node:wedge
194 #@+node:house
195 def house(props, name="", vc=None, hc=None):
196 if name: name = ".%s" % name
197 vc = vc or VCENTER
198 hc = hc or HCENTER
199 kwargs = make_properties(props, "house" + name)
200 mag = props("house" + name + ".magnification")
202 HALF = mag * FACTOR / 2
204 if props("house" + name + ".up", True):
205 base = VCENTER - HALF * VSEP
206 head = VCENTER + HALF * VSEP
207 else:
208 base = VCENTER + HALF * VSEP
209 head = VCENTER - HALF * VSEP
211 return (Polygon([(hc - HALF * HSEP, base),
212 (hc, base),
213 (hc + HALF * HSEP, base),
214 (hc + HALF * HSEP, vc),
215 (hc, head),
216 (hc - HALF * HSEP, vc)], **kwargs),)
217 #@-node:house
218 #@-others
220 symbols = ("diamond", "circle", "wedge", "house")
222 #@-node:@file charting/shapes.py
223 #@-leo