Source code

Download source archive ↓

src/openpyxl/drawing/effect.py

1# Copyright (c) 2010-2024 openpyxl
2
3from openpyxl.descriptors.serialisable import Serialisable
4from openpyxl.descriptors import (
5    Typed,
6    String,
7    Set,
8    Bool,
9    Integer,
10    Float,
11)
12
13from .colors import ColorChoice
14
15
16class TintEffect(Serialisable):
17
18    tagname = "tint"
19
20    hue = Integer()
21    amt = Integer()
22
23    def __init__(self,
24                 hue=0,
25                 amt=0,
26                ):
27        self.hue = hue
28        self.amt = amt
29
30
31class LuminanceEffect(Serialisable):
32
33    tagname = "lum"
34
35    bright = Integer() #Pct ?
36    contrast = Integer() #Pct#
37
38    def __init__(self,
39                 bright=0,
40                 contrast=0,
41                ):
42        self.bright = bright
43        self.contrast = contrast
44
45
46class HSLEffect(Serialisable):
47
48    hue = Integer()
49    sat = Integer()
50    lum = Integer()
51
52    def __init__(self,
53                 hue=None,
54                 sat=None,
55                 lum=None,
56                ):
57        self.hue = hue
58        self.sat = sat
59        self.lum = lum
60
61
62class GrayscaleEffect(Serialisable):
63
64    tagname = "grayscl"
65
66
67class FillOverlayEffect(Serialisable):
68
69    blend = Set(values=(['over', 'mult', 'screen', 'darken', 'lighten']))
70
71    def __init__(self,
72                 blend=None,
73                ):
74        self.blend = blend
75
76
77class DuotoneEffect(Serialisable):
78
79    pass
80
81class ColorReplaceEffect(Serialisable):
82
83    pass
84
85class Color(Serialisable):
86
87    pass
88
89class ColorChangeEffect(Serialisable):
90
91    useA = Bool(allow_none=True)
92    clrFrom = Typed(expected_type=Color, )
93    clrTo = Typed(expected_type=Color, )
94
95    def __init__(self,
96                 useA=None,
97                 clrFrom=None,
98                 clrTo=None,
99                ):
100        self.useA = useA
101        self.clrFrom = clrFrom
102        self.clrTo = clrTo
103
104
105class BlurEffect(Serialisable):
106
107    rad = Float()
108    grow = Bool(allow_none=True)
109
110    def __init__(self,
111                 rad=None,
112                 grow=None,
113                ):
114        self.rad = rad
115        self.grow = grow
116
117
118class BiLevelEffect(Serialisable):
119
120    thresh = Integer()
121
122    def __init__(self,
123                 thresh=None,
124                ):
125        self.thresh = thresh
126
127
128class AlphaReplaceEffect(Serialisable):
129
130    a = Integer()
131
132    def __init__(self,
133                 a=None,
134                ):
135        self.a = a
136
137
138class AlphaModulateFixedEffect(Serialisable):
139
140    amt = Integer()
141
142    def __init__(self,
143                 amt=None,
144                ):
145        self.amt = amt
146
147
148class EffectContainer(Serialisable):
149
150    type = Set(values=(['sib', 'tree']))
151    name = String(allow_none=True)
152
153    def __init__(self,
154                 type=None,
155                 name=None,
156                ):
157        self.type = type
158        self.name = name
159
160
161class AlphaModulateEffect(Serialisable):
162
163    cont = Typed(expected_type=EffectContainer, )
164
165    def __init__(self,
166                 cont=None,
167                ):
168        self.cont = cont
169
170
171class AlphaInverseEffect(Serialisable):
172
173    pass
174
175class AlphaFloorEffect(Serialisable):
176
177    pass
178
179class AlphaCeilingEffect(Serialisable):
180
181    pass
182
183class AlphaBiLevelEffect(Serialisable):
184
185    thresh = Integer()
186
187    def __init__(self,
188                 thresh=None,
189                ):
190        self.thresh = thresh
191
192
193class GlowEffect(ColorChoice):
194
195    rad = Float()
196    # uses element group EG_ColorChoice
197    scrgbClr = ColorChoice.scrgbClr
198    srgbClr = ColorChoice.srgbClr
199    hslClr = ColorChoice.hslClr
200    sysClr = ColorChoice.sysClr
201    schemeClr = ColorChoice.schemeClr
202    prstClr = ColorChoice.prstClr
203
204    __elements__ = ('scrgbClr', 'srgbClr', 'hslClr', 'sysClr', 'schemeClr', 'prstClr')
205
206    def __init__(self,
207                 rad=None,
208                 **kw
209                ):
210        self.rad = rad
211        super().__init__(**kw)
212
213
214class InnerShadowEffect(ColorChoice):
215
216    blurRad = Float()
217    dist = Float()
218    dir = Integer()
219    # uses element group EG_ColorChoice
220    scrgbClr = ColorChoice.scrgbClr
221    srgbClr = ColorChoice.srgbClr
222    hslClr = ColorChoice.hslClr
223    sysClr = ColorChoice.sysClr
224    schemeClr = ColorChoice.schemeClr
225    prstClr = ColorChoice.prstClr
226
227    __elements__ = ('scrgbClr', 'srgbClr', 'hslClr', 'sysClr', 'schemeClr', 'prstClr')
228
229    def __init__(self,
230                 blurRad=None,
231                 dist=None,
232                 dir=None,
233                 **kw
234                 ):
235        self.blurRad = blurRad
236        self.dist = dist
237        self.dir = dir
238        super().__init__(**kw)
239
240
241class OuterShadow(ColorChoice):
242
243    tagname = "outerShdw"
244
245    blurRad = Float(allow_none=True)
246    dist = Float(allow_none=True)
247    dir = Integer(allow_none=True)
248    sx = Integer(allow_none=True)
249    sy = Integer(allow_none=True)
250    kx = Integer(allow_none=True)
251    ky = Integer(allow_none=True)
252    algn = Set(values=['tl', 't', 'tr', 'l', 'ctr', 'r', 'bl', 'b', 'br'])
253    rotWithShape = Bool(allow_none=True)
254    # uses element group EG_ColorChoice
255    scrgbClr = ColorChoice.scrgbClr
256    srgbClr = ColorChoice.srgbClr
257    hslClr = ColorChoice.hslClr
258    sysClr = ColorChoice.sysClr
259    schemeClr = ColorChoice.schemeClr
260    prstClr = ColorChoice.prstClr
261
262    __elements__ = ('scrgbClr', 'srgbClr', 'hslClr', 'sysClr', 'schemeClr', 'prstClr')
263
264    def __init__(self,
265                 blurRad=None,
266                 dist=None,
267                 dir=None,
268                 sx=None,
269                 sy=None,
270                 kx=None,
271                 ky=None,
272                 algn=None,
273                 rotWithShape=None,
274                 **kw
275                ):
276        self.blurRad = blurRad
277        self.dist = dist
278        self.dir = dir
279        self.sx = sx
280        self.sy = sy
281        self.kx = kx
282        self.ky = ky
283        self.algn = algn
284        self.rotWithShape = rotWithShape
285        super().__init__(**kw)
286
287
288class PresetShadowEffect(ColorChoice):
289
290    prst = Set(values=(['shdw1', 'shdw2', 'shdw3', 'shdw4', 'shdw5', 'shdw6',
291                        'shdw7', 'shdw8', 'shdw9', 'shdw10', 'shdw11', 'shdw12', 'shdw13',
292                        'shdw14', 'shdw15', 'shdw16', 'shdw17', 'shdw18', 'shdw19', 'shdw20']))
293    dist = Float()
294    dir = Integer()
295    # uses element group EG_ColorChoice
296    scrgbClr = ColorChoice.scrgbClr
297    srgbClr = ColorChoice.srgbClr
298    hslClr = ColorChoice.hslClr
299    sysClr = ColorChoice.sysClr
300    schemeClr = ColorChoice.schemeClr
301    prstClr = ColorChoice.prstClr
302
303    __elements__ = ('scrgbClr', 'srgbClr', 'hslClr', 'sysClr', 'schemeClr', 'prstClr')
304
305    def __init__(self,
306                 prst=None,
307                 dist=None,
308                 dir=None,
309                 **kw
310                ):
311        self.prst = prst
312        self.dist = dist
313        self.dir = dir
314        super().__init__(**kw)
315
316
317class ReflectionEffect(Serialisable):
318
319    blurRad = Float()
320    stA = Integer()
321    stPos = Integer()
322    endA = Integer()
323    endPos = Integer()
324    dist = Float()
325    dir = Integer()
326    fadeDir = Integer()
327    sx = Integer()
328    sy = Integer()
329    kx = Integer()
330    ky = Integer()
331    algn = Set(values=(['tl', 't', 'tr', 'l', 'ctr', 'r', 'bl', 'b', 'br']))
332    rotWithShape = Bool(allow_none=True)
333
334    def __init__(self,
335                 blurRad=None,
336                 stA=None,
337                 stPos=None,
338                 endA=None,
339                 endPos=None,
340                 dist=None,
341                 dir=None,
342                 fadeDir=None,
343                 sx=None,
344                 sy=None,
345                 kx=None,
346                 ky=None,
347                 algn=None,
348                 rotWithShape=None,
349                ):
350        self.blurRad = blurRad
351        self.stA = stA
352        self.stPos = stPos
353        self.endA = endA
354        self.endPos = endPos
355        self.dist = dist
356        self.dir = dir
357        self.fadeDir = fadeDir
358        self.sx = sx
359        self.sy = sy
360        self.kx = kx
361        self.ky = ky
362        self.algn = algn
363        self.rotWithShape = rotWithShape
364
365
366class SoftEdgesEffect(Serialisable):
367
368    rad = Float()
369
370    def __init__(self,
371                 rad=None,
372                ):
373        self.rad = rad
374
375
376class EffectList(Serialisable):
377
378    blur = Typed(expected_type=BlurEffect, allow_none=True)
379    fillOverlay = Typed(expected_type=FillOverlayEffect, allow_none=True)
380    glow = Typed(expected_type=GlowEffect, allow_none=True)
381    innerShdw = Typed(expected_type=InnerShadowEffect, allow_none=True)
382    outerShdw = Typed(expected_type=OuterShadow, allow_none=True)
383    prstShdw = Typed(expected_type=PresetShadowEffect, allow_none=True)
384    reflection = Typed(expected_type=ReflectionEffect, allow_none=True)
385    softEdge = Typed(expected_type=SoftEdgesEffect, allow_none=True)
386
387    __elements__ = ('blur', 'fillOverlay', 'glow', 'innerShdw', 'outerShdw',
388                    'prstShdw', 'reflection', 'softEdge')
389
390    def __init__(self,
391                 blur=None,
392                 fillOverlay=None,
393                 glow=None,
394                 innerShdw=None,
395                 outerShdw=None,
396                 prstShdw=None,
397                 reflection=None,
398                 softEdge=None,
399                ):
400        self.blur = blur
401        self.fillOverlay = fillOverlay
402        self.glow = glow
403        self.innerShdw = innerShdw
404        self.outerShdw = outerShdw
405        self.prstShdw = prstShdw
406        self.reflection = reflection
407        self.softEdge = softEdge