effect.py 9.3 KB

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