MCPcopy Create free account
hub / github.com/scanny/python-pptx / _GradFill

Class _GradFill

src/pptx/dml/fill.py:221–275  ·  view source on GitHub ↗

Proxies an `a:gradFill` element.

Source from the content-addressed store, hash-verified

219
220
221class _GradFill(_Fill):
222 """Proxies an `a:gradFill` element."""
223
224 def __init__(self, gradFill):
225 self._element = self._gradFill = gradFill
226
227 @property
228 def gradient_angle(self):
229 """Angle in float degrees of line of a linear gradient.
230
231 Read/Write. May be |None|, indicating the angle is inherited from the
232 style hierarchy. An angle of 0.0 corresponds to a left-to-right
233 gradient. Increasing angles represent clockwise rotation of the line,
234 for example 90.0 represents a top-to-bottom gradient. Raises
235 |TypeError| when the fill type is not MSO_FILL_TYPE.GRADIENT. Raises
236 |ValueError| for a non-linear gradient (e.g. a radial gradient).
237 """
238 # ---case 1: gradient path is explicit, but not linear---
239 path = self._gradFill.path
240 if path is not None:
241 raise ValueError("not a linear gradient")
242
243 # ---case 2: gradient path is inherited (no a:lin OR a:path)---
244 lin = self._gradFill.lin
245 if lin is None:
246 return None
247
248 # ---case 3: gradient path is explicitly linear---
249 # angle is stored in XML as a clockwise angle, whereas the UI
250 # reports it as counter-clockwise from horizontal-pointing-right.
251 # Since the UI is consistent with trigonometry conventions, we
252 # respect that in the API.
253 clockwise_angle = lin.ang
254 counter_clockwise_angle = 0.0 if clockwise_angle == 0.0 else (360.0 - clockwise_angle)
255 return counter_clockwise_angle
256
257 @gradient_angle.setter
258 def gradient_angle(self, value):
259 lin = self._gradFill.lin
260 if lin is None:
261 raise ValueError("not a linear gradient")
262 lin.ang = 360.0 - value
263
264 @lazyproperty
265 def gradient_stops(self):
266 """|_GradientStops| object providing access to gradient colors.
267
268 Each stop represents a color between which the gradient smoothly
269 transitions.
270 """
271 return _GradientStops(self._gradFill.get_or_add_gsLst())
272
273 @property
274 def type(self):
275 return MSO_FILL.GRADIENT
276
277
278class _GrpFill(_Fill):

Callers 6

angle_fixtureMethod · 0.90
angle_set_fixtureMethod · 0.90
fill_type_fixtureMethod · 0.90
stops_fixtureMethod · 0.90
gradientMethod · 0.85

Calls

no outgoing calls

Tested by 5

angle_fixtureMethod · 0.72
angle_set_fixtureMethod · 0.72
fill_type_fixtureMethod · 0.72
stops_fixtureMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…