1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 from muntjac.addon.invient.paint import IPaint
16
17 try:
18 from cStringIO import StringIO
19 except ImportError:
20 from StringIO import StringIO
21
22
23 -class Unit(object):
24
25 NUMBER = None
26 PERCENT = None
27
29 self._name = name
30 self._symbol = symbol
31
34
37
38 @classmethod
41
42 Unit.NUMBER = Unit('number', '')
43 Unit.PERCENT = Unit('percent', '%')
47 """Represents a stop-value and a color. The stop-value should be in range
48 (0.0-1.0). The color of the gradient at each stop is the color specified
49 for that stop. Between each such stop, the colors and the alpha component
50 will be linearly interpolated over the RGBA.
51
52 @author: Invient
53 @author: Richard Lincoln
54 """
55
57 raise NotImplementedError
58
60 raise NotImplementedError
61
63 raise NotImplementedError
64
67 """The Gradient defines a way to fill a shape with a linear color gradient
68 pattern.
69
70 @author: Invient
71 @author: Richard Lincoln
72 """
73
75 """Returns the x-coordinate of a point at which linear gradient
76 starts.
77 @return: the x-coordinate of a point at which linear gradient
78 starts.
79 """
80 raise NotImplementedError
81
83 """Returns the unit of x-coordinate of a point at which linear gradient starts.
84 @return: the unit of x-coordinate of a point at which linear gradient starts.
85 """
86 raise NotImplementedError
87
89 """Returns the y-coordinate of a point at which linear gradient starts.
90 @return: the y-coordinate of a point at which linear gradient starts.
91 """
92 raise NotImplementedError
93
95 """Returns the unit of y-coordinate of a point at which linear gradient starts.
96 @return: the unit of y-coordinate of a point at which linear gradient starts.
97 """
98 raise NotImplementedError
99
101 """Returns the x-coordinate of a point at which linear gradient
102 ends.
103 @return: the x-coordinate of a point at which linear gradient
104 ends.
105 """
106 raise NotImplementedError
107
109 """Returns the unit of x-coordinate of a point at which linear gradient ends.
110 @return: the unit of x-coordinate of a point at which linear gradient ends.
111 """
112 raise NotImplementedError
113
115 """Returns the x-coordinate of a point at which linear gradient ends.
116 @return: the x-coordinate of a point at which linear gradient ends.
117 """
118 raise NotImplementedError
119
121 """Returns the unit of y-coordinate of a point at which linear gradient ends.
122 @return: the unit of y-coordinate of a point at which linear gradient ends.
123 """
124 raise NotImplementedError
125
127 """Returns a list of colorstops associated with this gradient.
128 @return: a list of colorstops associated with this gradient.
129 @see: L{IColorStop}
130 """
131 raise NotImplementedError
132
135 """Represents linear gradient where points of a linear gradient specify a
136 line. For more details on gradient, refer to CSS 3 gradient
137 documentation.
138
139 @author: Invient
140 @author: Richard Lincoln
141 """
142
143 - def __init__(self, xStart, xStartUnit_or_yStart, yStart_or_xEnd,
144 yStartUnit_or_yEnd, xEnd_or_colorStops, xEndUnit=None,
145 yEnd=None, yEndUnit=None, colorStops=None):
146 """Creates a LinearGradient with the specified xStart, xEnd, yStart
147 and yEnd values with default {@link Unit} value number.
148
149 @param xStart:
150 the x-coordinate of a point at which linear gradient
151 starts.
152 @param xStartUnit_or_yStart:
153 the unit for the xStart value. It can have one of the two
154 values Unit.NUMBER or Unit.PERCENT. If it is null then the
155 default value is Unit.NUMBER. Or the y-coordinate of a point
156 at which linear gradient starts.
157 @param yStart_or_xEnd:
158 the y-coordinate of a point at which linear gradient
159 starts or the x-coordinate of a point at which linear
160 gradient ends.
161 @param yStartUnit_or_yEnd:
162 the unit for the yStart value. It can have one of the two
163 values Unit.NUMBER or Unit.PERCENT. If it is null then the
164 default value is Unit.NUMBER. Or the y-coordinate of a point
165 at which linear gradient ends.
166 @param xEnd_or_colorStops:
167 the x-coordinate of a point at which linear gradient ends or
168 the list of colorstops for the linear gradient.
169 @param xEndUnit:
170 the unit for the xEnd value. It can have one of the two
171 values Unit.NUMBER or Unit.PERCENT. If it is null then the
172 default value is Unit.NUMBER.
173 @param yEnd:
174 the y-coordinate of a point at which linear gradient ends.
175 @param yEndUnit
176 the unit for the yEnd value. It can have one of the two
177 values Unit.NUMBER or Unit.PERCENT. If it is null then the
178 default value is Unit.NUMBER.
179 @param colorStops:
180 the list of colorstops for the linear gradient.
181 """
182 self._xStart = 0
183 self._xStartUnit = Unit.NUMBER
184 self._yStart = 0
185 self._yStartUnit = Unit.NUMBER
186 self._xEnd = 0
187 self._xEndUnit = Unit.NUMBER
188 self._yEnd = 0
189 self._yEndUnit = Unit.NUMBER
190 self._colorStops = list()
191
192 xStartUnit = yStartUnit = None
193 if xEndUnit is None:
194 xStart, yStart, xEnd, yEnd, colorStops = (xStart,
195 xStartUnit_or_yStart, yStart_or_xEnd, yStartUnit_or_yEnd,
196 xEnd_or_colorStops)
197 else:
198 xStartUnit, yStart, yStartUnit, xEnd, xEndUnit, yEnd, yEndUnit, \
199 colorStops = (xStartUnit_or_yStart, yStart_or_xEnd,
200 yStartUnit_or_yEnd, xEnd_or_colorStops, xEndUnit, yEnd,
201 yEndUnit, colorStops)
202
203 super(LinearGradient, self).__init__()
204
205 self._xStart = xStart
206 if xStartUnit is not None:
207 self._xStartUnit = xStartUnit
208
209 self._yStart = yStart
210 if yStartUnit is not None:
211 self._yStartUnit = yStartUnit
212
213 self._xEnd = xEnd
214 if xEndUnit is not None:
215 self._xEndUnit = xEndUnit
216
217 self._yEnd = yEnd
218 if yEndUnit is not None:
219 self._yEndUnit = yEndUnit
220
221 if colorStops is not None:
222 self._colorStops = colorStops
223
226
229
232
235
237 return self._xStartUnit
238
240 return self._yStartUnit
241
243 return self._xEndUnit
244
246 return self._yEndUnit
247
249 return self._colorStops
250
252 """@return: Returns string representation of this LinearGradient"""
253 sb = StringIO()
254
255
256 x1 = '\'' + str(self._xStart) + self._xStartUnit.getSymbol() + '\''
257 y1 = '\'' + str(self._yStart) + self._yStartUnit.getSymbol() + '\''
258 x2 = '\'' + str(self._xEnd) + self._xEndUnit.getSymbol() + '\''
259 y2 = '\'' + str(self._yEnd) + self._yEndUnit.getSymbol() + '\''
260 sb.write('JSOBJ:{')
261 sb.write(' linearGradient: [' + x1 + ',' + y1 + ',' + x2 + ',' + y2 + '],')
262 sb.write(' stops: [')
263 count = 0
264 for colorStop in self._colorStops:
265 if colorStop.getColor() is not None:
266 stopAt = ('\'' + str(colorStop.getStopAt())
267 + colorStop.getStopAtUnit().getSymbol() + '\'')
268 stopColor = '\'' + colorStop.getColor().getString() + '\''
269 if count > 0:
270 sb.write(',')
271 sb.write('[' + stopAt + ', ' + stopColor + ']')
272 count += 1
273 sb.write(' ]')
274 sb.write('}')
275 return sb.getvalue()
276
279 """Represents stop-value and color for the L{LinearGradient}
280
281 @author: Invient
282 @author: Richard Lincoln
283 """
284
285 - def __init__(self, stopAt, stopAtUnit_or_color, color=None):
286 self._stopAt = None
287 self._stopAtUnit = Unit.NUMBER
288 self._color = None
289
290 if color == None:
291 color = stopAtUnit_or_color
292 super(LinearColorStop, self).__init__()
293 self._stopAt = stopAt
294 self._color = color
295 else:
296 stopAtUnit = stopAtUnit_or_color
297 super(LinearColorStop, self).__init__()
298 self._stopAt = stopAt
299 if stopAtUnit is not None:
300 self._stopAtUnit = stopAtUnit
301 self._color = color
302
305
307 return self._stopAtUnit
308
311