Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/openpyxl/drawing/fill.py: 70%

218 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2023-07-17 14:22 -0600

1# Copyright (c) 2010-2022 openpyxl 

2 

3 

4from openpyxl.descriptors.serialisable import Serialisable 

5from openpyxl.descriptors import ( 

6 Alias, 

7 Bool, 

8 Integer, 

9 Set, 

10 NoneSet, 

11 Typed, 

12 MinMax, 

13 Sequence, 

14) 

15from openpyxl.descriptors.excel import ( 

16 Relation, 

17 Percentage, 

18) 

19from openpyxl.descriptors.nested import NestedNoneSet, NestedValue 

20from openpyxl.descriptors.sequence import NestedSequence 

21from openpyxl.xml.constants import DRAWING_NS 

22 

23from .colors import ( 

24 ColorChoice, 

25 HSLColor, 

26 SystemColor, 

27 SchemeColor, 

28 RGBPercent, 

29 PRESET_COLORS, 

30) 

31 

32 

33from openpyxl.descriptors.excel import ExtensionList as OfficeArtExtensionList 

34from .effect import * 

35 

36""" 

37Fill elements from drawing main schema 

38""" 

39 

40class PatternFillProperties(Serialisable): 

41 

42 tagname = "pattFill" 

43 namespace = DRAWING_NS 

44 

45 prst = NoneSet(values=(['pct5', 'pct10', 'pct20', 'pct25', 'pct30', 'pct40', 

46 'pct50', 'pct60', 'pct70', 'pct75', 'pct80', 'pct90', 'horz', 'vert', 

47 'ltHorz', 'ltVert', 'dkHorz', 'dkVert', 'narHorz', 'narVert', 'dashHorz', 

48 'dashVert', 'cross', 'dnDiag', 'upDiag', 'ltDnDiag', 'ltUpDiag', 

49 'dkDnDiag', 'dkUpDiag', 'wdDnDiag', 'wdUpDiag', 'dashDnDiag', 

50 'dashUpDiag', 'diagCross', 'smCheck', 'lgCheck', 'smGrid', 'lgGrid', 

51 'dotGrid', 'smConfetti', 'lgConfetti', 'horzBrick', 'diagBrick', 

52 'solidDmnd', 'openDmnd', 'dotDmnd', 'plaid', 'sphere', 'weave', 'divot', 

53 'shingle', 'wave', 'trellis', 'zigZag'])) 

54 preset = Alias("prst") 

55 fgClr = Typed(expected_type=ColorChoice, allow_none=True) 

56 foreground = Alias("fgClr") 

57 bgClr = Typed(expected_type=ColorChoice, allow_none=True) 

58 background = Alias("bgClr") 

59 

60 __elements__ = ("fgClr", "bgClr") 

61 

62 def __init__(self, 

63 prst=None, 

64 fgClr=None, 

65 bgClr=None, 

66 ): 

67 self.prst = prst 

68 self.fgClr = fgClr 

69 self.bgClr = bgClr 

70 

71 

72class RelativeRect(Serialisable): 

73 

74 tagname = "rect" 

75 namespace = DRAWING_NS 

76 

77 l = Percentage(allow_none=True) 

78 left = Alias('l') 

79 t = Percentage(allow_none=True) 

80 top = Alias('t') 

81 r = Percentage(allow_none=True) 

82 right = Alias('r') 

83 b = Percentage(allow_none=True) 

84 bottom = Alias('b') 

85 

86 def __init__(self, 

87 l=None, 

88 t=None, 

89 r=None, 

90 b=None, 

91 ): 

92 self.l = l 

93 self.t = t 

94 self.r = r 

95 self.b = b 

96 

97 

98class StretchInfoProperties(Serialisable): 

99 

100 tagname = "stretch" 

101 namespace = DRAWING_NS 

102 

103 fillRect = Typed(expected_type=RelativeRect, allow_none=True) 

104 

105 def __init__(self, 

106 fillRect=RelativeRect(), 

107 ): 

108 self.fillRect = fillRect 

109 

110 

111class GradientStop(Serialisable): 

112 

113 tagname = "gs" 

114 namespace = DRAWING_NS 

115 

116 pos = MinMax(min=0, max=100000, allow_none=True) 

117 # Color Choice Group 

118 scrgbClr = Typed(expected_type=RGBPercent, allow_none=True) 

119 RGBPercent = Alias('scrgbClr') 

120 srgbClr = NestedValue(expected_type=str, allow_none=True) # needs pattern and can have transform 

121 RGB = Alias('srgbClr') 

122 hslClr = Typed(expected_type=HSLColor, allow_none=True) 

123 sysClr = Typed(expected_type=SystemColor, allow_none=True) 

124 schemeClr = Typed(expected_type=SchemeColor, allow_none=True) 

125 prstClr = NestedNoneSet(values=PRESET_COLORS) 

126 

127 __elements__ = ('scrgbClr', 'srgbClr', 'hslClr', 'sysClr', 'schemeClr', 'prstClr') 

128 

129 def __init__(self, 

130 pos=None, 

131 scrgbClr=None, 

132 srgbClr=None, 

133 hslClr=None, 

134 sysClr=None, 

135 schemeClr=None, 

136 prstClr=None, 

137 ): 

138 if pos is None: 

139 pos = 0 

140 self.pos = pos 

141 

142 self.scrgbClr = scrgbClr 

143 self.srgbClr = srgbClr 

144 self.hslClr = hslClr 

145 self.sysClr = sysClr 

146 self.schemeClr = schemeClr 

147 self.prstClr = prstClr 

148 

149 

150class LinearShadeProperties(Serialisable): 

151 

152 tagname = "lin" 

153 namespace = DRAWING_NS 

154 

155 ang = Integer() 

156 scaled = Bool(allow_none=True) 

157 

158 def __init__(self, 

159 ang=None, 

160 scaled=None, 

161 ): 

162 self.ang = ang 

163 self.scaled = scaled 

164 

165 

166class PathShadeProperties(Serialisable): 

167 

168 tagname = "path" 

169 namespace = DRAWING_NS 

170 

171 path = Set(values=(['shape', 'circle', 'rect'])) 

172 fillToRect = Typed(expected_type=RelativeRect, allow_none=True) 

173 

174 def __init__(self, 

175 path=None, 

176 fillToRect=None, 

177 ): 

178 self.path = path 

179 self.fillToRect = fillToRect 

180 

181 

182class GradientFillProperties(Serialisable): 

183 

184 tagname = "gradFill" 

185 namespace = DRAWING_NS 

186 

187 flip = NoneSet(values=(['x', 'y', 'xy'])) 

188 rotWithShape = Bool(allow_none=True) 

189 

190 gsLst = NestedSequence(expected_type=GradientStop, count=False) 

191 stop_list = Alias("gsLst") 

192 

193 lin = Typed(expected_type=LinearShadeProperties, allow_none=True) 

194 linear = Alias("lin") 

195 path = Typed(expected_type=PathShadeProperties, allow_none=True) 

196 

197 tileRect = Typed(expected_type=RelativeRect, allow_none=True) 

198 

199 __elements__ = ('gsLst', 'lin', 'path', 'tileRect') 

200 

201 def __init__(self, 

202 flip=None, 

203 rotWithShape=None, 

204 gsLst=(), 

205 lin=None, 

206 path=None, 

207 tileRect=None, 

208 ): 

209 self.flip = flip 

210 self.rotWithShape = rotWithShape 

211 self.gsLst = gsLst 

212 self.lin = lin 

213 self.path = path 

214 self.tileRect = tileRect 

215 

216 

217class SolidColorFillProperties(Serialisable): 

218 

219 tagname = "solidFill" 

220 

221 # uses element group EG_ColorChoice 

222 scrgbClr = Typed(expected_type=RGBPercent, allow_none=True) 

223 RGBPercent = Alias('scrgbClr') 

224 srgbClr = NestedValue(expected_type=str, allow_none=True) # needs pattern and can have transform 

225 RGB = Alias('srgbClr') 

226 hslClr = Typed(expected_type=HSLColor, allow_none=True) 

227 sysClr = Typed(expected_type=SystemColor, allow_none=True) 

228 schemeClr = Typed(expected_type=SchemeColor, allow_none=True) 

229 prstClr = NestedNoneSet(values=PRESET_COLORS) 

230 

231 __elements__ = ('scrgbClr', 'srgbClr', 'hslClr', 'sysClr', 'schemeClr', 'prstClr') 

232 

233 def __init__(self, 

234 scrgbClr=None, 

235 srgbClr=None, 

236 hslClr=None, 

237 sysClr=None, 

238 schemeClr=None, 

239 prstClr=None, 

240 ): 

241 self.scrgbClr = scrgbClr 

242 self.srgbClr = srgbClr 

243 self.hslClr = hslClr 

244 self.sysClr = sysClr 

245 self.schemeClr = schemeClr 

246 self.prstClr = prstClr 

247 

248 

249class Blip(Serialisable): 

250 

251 tagname = "blip" 

252 namespace = DRAWING_NS 

253 

254 #Using attribute groupAG_Blob 

255 cstate = NoneSet(values=(['email', 'screen', 'print', 'hqprint'])) 

256 embed = Relation() #rId 

257 link = Relation() #hyperlink 

258 noGrp = Bool(allow_none=True) 

259 noSelect = Bool(allow_none=True) 

260 noRot = Bool(allow_none=True) 

261 noChangeAspect = Bool(allow_none=True) 

262 noMove = Bool(allow_none=True) 

263 noResize = Bool(allow_none=True) 

264 noEditPoints = Bool(allow_none=True) 

265 noAdjustHandles = Bool(allow_none=True) 

266 noChangeArrowheads = Bool(allow_none=True) 

267 noChangeShapeType = Bool(allow_none=True) 

268 # some elements are choice 

269 extLst = Typed(expected_type=OfficeArtExtensionList, allow_none=True) 

270 alphaBiLevel = Typed(expected_type=AlphaBiLevelEffect, allow_none=True) 

271 alphaCeiling = Typed(expected_type=AlphaCeilingEffect, allow_none=True) 

272 alphaFloor = Typed(expected_type=AlphaFloorEffect, allow_none=True) 

273 alphaInv = Typed(expected_type=AlphaInverseEffect, allow_none=True) 

274 alphaMod = Typed(expected_type=AlphaModulateEffect, allow_none=True) 

275 alphaModFix = Typed(expected_type=AlphaModulateFixedEffect, allow_none=True) 

276 alphaRepl = Typed(expected_type=AlphaReplaceEffect, allow_none=True) 

277 biLevel = Typed(expected_type=BiLevelEffect, allow_none=True) 

278 blur = Typed(expected_type=BlurEffect, allow_none=True) 

279 clrChange = Typed(expected_type=ColorChangeEffect, allow_none=True) 

280 clrRepl = Typed(expected_type=ColorReplaceEffect, allow_none=True) 

281 duotone = Typed(expected_type=DuotoneEffect, allow_none=True) 

282 fillOverlay = Typed(expected_type=FillOverlayEffect, allow_none=True) 

283 grayscl = Typed(expected_type=GrayscaleEffect, allow_none=True) 

284 hsl = Typed(expected_type=HSLEffect, allow_none=True) 

285 lum = Typed(expected_type=LuminanceEffect, allow_none=True) 

286 tint = Typed(expected_type=TintEffect, allow_none=True) 

287 

288 __elements__ = ('alphaBiLevel', 'alphaCeiling', 'alphaFloor', 'alphaInv', 

289 'alphaMod', 'alphaModFix', 'alphaRepl', 'biLevel', 'blur', 'clrChange', 

290 'clrRepl', 'duotone', 'fillOverlay', 'grayscl', 'hsl', 'lum', 'tint') 

291 

292 def __init__(self, 

293 cstate=None, 

294 embed=None, 

295 link=None, 

296 noGrp=None, 

297 noSelect=None, 

298 noRot=None, 

299 noChangeAspect=None, 

300 noMove=None, 

301 noResize=None, 

302 noEditPoints=None, 

303 noAdjustHandles=None, 

304 noChangeArrowheads=None, 

305 noChangeShapeType=None, 

306 extLst=None, 

307 alphaBiLevel=None, 

308 alphaCeiling=None, 

309 alphaFloor=None, 

310 alphaInv=None, 

311 alphaMod=None, 

312 alphaModFix=None, 

313 alphaRepl=None, 

314 biLevel=None, 

315 blur=None, 

316 clrChange=None, 

317 clrRepl=None, 

318 duotone=None, 

319 fillOverlay=None, 

320 grayscl=None, 

321 hsl=None, 

322 lum=None, 

323 tint=None, 

324 ): 

325 self.cstate = cstate 

326 self.embed = embed 

327 self.link = link 

328 self.noGrp = noGrp 

329 self.noSelect = noSelect 

330 self.noRot = noRot 

331 self.noChangeAspect = noChangeAspect 

332 self.noMove = noMove 

333 self.noResize = noResize 

334 self.noEditPoints = noEditPoints 

335 self.noAdjustHandles = noAdjustHandles 

336 self.noChangeArrowheads = noChangeArrowheads 

337 self.noChangeShapeType = noChangeShapeType 

338 self.extLst = extLst 

339 self.alphaBiLevel = alphaBiLevel 

340 self.alphaCeiling = alphaCeiling 

341 self.alphaFloor = alphaFloor 

342 self.alphaInv = alphaInv 

343 self.alphaMod = alphaMod 

344 self.alphaModFix = alphaModFix 

345 self.alphaRepl = alphaRepl 

346 self.biLevel = biLevel 

347 self.blur = blur 

348 self.clrChange = clrChange 

349 self.clrRepl = clrRepl 

350 self.duotone = duotone 

351 self.fillOverlay = fillOverlay 

352 self.grayscl = grayscl 

353 self.hsl = hsl 

354 self.lum = lum 

355 self.tint = tint 

356 

357 

358class TileInfoProperties(Serialisable): 

359 

360 tx = Integer(allow_none=True) 

361 ty = Integer(allow_none=True) 

362 sx = Integer(allow_none=True) 

363 sy = Integer(allow_none=True) 

364 flip = NoneSet(values=(['x', 'y', 'xy'])) 

365 algn = Set(values=(['tl', 't', 'tr', 'l', 'ctr', 'r', 'bl', 'b', 'br'])) 

366 

367 def __init__(self, 

368 tx=None, 

369 ty=None, 

370 sx=None, 

371 sy=None, 

372 flip=None, 

373 algn=None, 

374 ): 

375 self.tx = tx 

376 self.ty = ty 

377 self.sx = sx 

378 self.sy = sy 

379 self.flip = flip 

380 self.algn = algn 

381 

382 

383class BlipFillProperties(Serialisable): 

384 

385 tagname = "blipFill" 

386 

387 dpi = Integer(allow_none=True) 

388 rotWithShape = Bool(allow_none=True) 

389 

390 blip = Typed(expected_type=Blip, allow_none=True) 

391 srcRect = Typed(expected_type=RelativeRect, allow_none=True) 

392 tile = Typed(expected_type=TileInfoProperties, allow_none=True) 

393 stretch = Typed(expected_type=StretchInfoProperties, allow_none=True) 

394 

395 __elements__ = ("blip", "srcRect", "tile", "stretch") 

396 

397 def __init__(self, 

398 dpi=None, 

399 rotWithShape=None, 

400 blip=None, 

401 tile=None, 

402 stretch=StretchInfoProperties(), 

403 srcRect=None, 

404 ): 

405 self.dpi = dpi 

406 self.rotWithShape = rotWithShape 

407 self.blip = blip 

408 self.tile = tile 

409 self.stretch = stretch 

410 self.srcRect = srcRect