effect.py 9.2 KB

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