Proxies an `a:gradFill` element.
| 219 | |
| 220 | |
| 221 | class _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 | |
| 278 | class _GrpFill(_Fill): |
no outgoing calls
searching dependent graphs…