-
Notifications
You must be signed in to change notification settings - Fork 700
Expand file tree
/
Copy patheffect.py
More file actions
164 lines (134 loc) · 5.3 KB
/
effect.py
File metadata and controls
164 lines (134 loc) · 5.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
"""Visual effects on a shape such as shadow, glow, and reflection."""
from __future__ import annotations
from typing import TYPE_CHECKING
from pptx.dml.color import ColorFormat
from pptx.util import Emu, lazyproperty
if TYPE_CHECKING:
from pptx.oxml.dml.effect import CT_OuterShadowEffect
from pptx.util import Length
class ShadowFormat(object):
"""Provides access to shadow effect on a shape."""
def __init__(self, spPr):
# ---spPr may also be a grpSpPr; both have a:effectLst child---
self._element = spPr
@property
def angle(self) -> float | None:
"""Direction of shadow in degrees (0 = right, 90 = below, etc.).
Read/write. Returns |None| if no shadow is explicitly defined. Setting this property
creates an outer shadow if one doesn't exist.
"""
outerShdw = self._outerShdw
if outerShdw is None:
return None
return outerShdw.dir
@angle.setter
def angle(self, value: float | None) -> None:
if value is None:
return
outerShdw = self._get_or_add_outerShdw()
outerShdw.dir = value
@property
def blur_radius(self) -> Length | None:
"""Blur radius of shadow in EMU.
Read/write. Returns |None| if no shadow is explicitly defined.
"""
outerShdw = self._outerShdw
if outerShdw is None:
return None
return Emu(outerShdw.blurRad)
@blur_radius.setter
def blur_radius(self, value: Length | None) -> None:
if value is None:
return
outerShdw = self._get_or_add_outerShdw()
outerShdw.blurRad = int(value)
@lazyproperty
def color(self) -> ColorFormat:
"""Color of the shadow.
Returns a |ColorFormat| object. Setting color properties creates an outer shadow with a
solid color fill if one doesn't exist.
"""
outerShdw = self._get_or_add_outerShdw()
return ColorFormat.from_colorchoice_parent(outerShdw)
@property
def distance(self) -> Length | None:
"""Distance of shadow from shape in EMU.
Read/write. Returns |None| if no shadow is explicitly defined.
"""
outerShdw = self._outerShdw
if outerShdw is None:
return None
return Emu(outerShdw.dist)
@distance.setter
def distance(self, value: Length | None) -> None:
if value is None:
return
outerShdw = self._get_or_add_outerShdw()
outerShdw.dist = int(value)
@property
def inherit(self):
"""True if shape inherits shadow settings.
Read/write. An explicitly-defined shadow setting on a shape causes
this property to return |False|. A shape with no explicitly-defined
shadow setting inherits its shadow settings from the style hierarchy
(and so returns |True|).
Assigning |True| causes any explicitly-defined shadow setting to be
removed and inheritance is restored. Note this has the side-effect of
removing **all** explicitly-defined effects, such as glow and
reflection, and restoring inheritance for all effects on the shape.
Assigning |False| causes the inheritance link to be broken and **no**
effects to appear on the shape.
"""
if self._element.effectLst is None:
return True
return False
@inherit.setter
def inherit(self, value):
inherit = bool(value)
if inherit:
# ---remove any explicitly-defined effects
self._element._remove_effectLst()
else:
# ---ensure at least the effectLst element is present
self._element.get_or_add_effectLst()
@property
def rotate_with_shape(self) -> bool | None:
"""Whether the shadow rotates with the shape.
Read/write. Returns |None| if no shadow is explicitly defined.
"""
outerShdw = self._outerShdw
if outerShdw is None:
return None
return outerShdw.rotWithShape
@rotate_with_shape.setter
def rotate_with_shape(self, value: bool | None) -> None:
if value is None:
return
outerShdw = self._get_or_add_outerShdw()
outerShdw.rotWithShape = value
@property
def visible(self) -> bool:
"""Whether a shadow is visible on this shape.
Read/write. Returns |True| if an outer shadow element is present. Assigning |True| creates
a default outer shadow. Assigning |False| removes any outer shadow.
"""
return self._outerShdw is not None
@visible.setter
def visible(self, value: bool) -> None:
if value:
self._get_or_add_outerShdw()
else:
effectLst = self._element.effectLst
if effectLst is not None:
effectLst._remove_outerShdw()
def _get_or_add_outerShdw(self) -> CT_OuterShadowEffect:
"""Return the `a:outerShdw` element, creating parent elements as needed."""
effectLst = self._element.get_or_add_effectLst()
return effectLst.get_or_add_outerShdw()
@property
def _outerShdw(self) -> CT_OuterShadowEffect | None:
"""Return `a:outerShdw` element or None if not present."""
effectLst = self._element.effectLst
if effectLst is None:
return None
return effectLst.outerShdw