Coverage for /home/martinb/.local/share/virtualenvs/camcops/lib/python3.6/site-packages/openpyxl/styles/differential.py : 58%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# Copyright (c) 2010-2020 openpyxl
3from openpyxl.descriptors import (
4 Integer,
5 String,
6 Typed,
7 Sequence,
8 Alias,
9)
10from openpyxl.descriptors.serialisable import Serialisable
11from openpyxl.styles import (
12 Font,
13 Fill,
14 GradientFill,
15 PatternFill,
16 Border,
17 Alignment,
18 Protection,
19 )
20from .numbers import NumberFormat
23class DifferentialStyle(Serialisable):
25 tagname = "dxf"
27 __elements__ = ("font", "numFmt", "fill", "alignment", "border", "protection")
29 font = Typed(expected_type=Font, allow_none=True)
30 numFmt = Typed(expected_type=NumberFormat, allow_none=True)
31 fill = Typed(expected_type=Fill, allow_none=True)
32 alignment = Typed(expected_type=Alignment, allow_none=True)
33 border = Typed(expected_type=Border, allow_none=True)
34 protection = Typed(expected_type=Protection, allow_none=True)
36 def __init__(self,
37 font=None,
38 numFmt=None,
39 fill=None,
40 alignment=None,
41 border=None,
42 protection=None,
43 extLst=None,
44 ):
45 self.font = font
46 self.numFmt = numFmt
47 self.fill = fill
48 self.alignment = alignment
49 self.border = border
50 self.protection = protection
51 self.extLst = extLst
54class DifferentialStyleList(Serialisable):
55 """
56 Deduping container for differential styles.
57 """
59 tagname = "dxfs"
61 dxf = Sequence(expected_type=DifferentialStyle)
62 styles = Alias("dxf")
65 def __init__(self, dxf=()):
66 self.dxf = dxf
69 def append(self, dxf):
70 """
71 Check to see whether style already exists and append it if does not.
72 """
73 if not isinstance(dxf, DifferentialStyle):
74 raise TypeError('expected ' + str(DifferentialStyle))
75 if dxf in self.styles:
76 return
77 self.styles.append(dxf)
80 def add(self, dxf):
81 """
82 Add a differential style and return its index
83 """
84 self.append(dxf)
85 return self.styles.index(dxf)
88 def __bool__(self):
89 return bool(self.styles)
93 def __getitem__(self, idx):
94 return self.styles[idx]