Source code

Download source archive ↓

src/openpyxl/drawing/properties.py

1# Copyright (c) 2010-2024 openpyxl
2
3from openpyxl.xml.constants import DRAWING_NS
4from openpyxl.descriptors.serialisable import Serialisable
5from openpyxl.descriptors import (
6    Typed,
7    Bool,
8    Integer,
9    Set,
10    String,
11    Alias,
12    NoneSet,
13)
14from openpyxl.descriptors.excel import ExtensionList as OfficeArtExtensionList
15
16from .geometry import GroupTransform2D, Scene3D
17from .text import Hyperlink
18
19
20class GroupShapeProperties(Serialisable):
21
22    tagname = "grpSpPr"
23
24    bwMode = NoneSet(values=(['clr', 'auto', 'gray', 'ltGray', 'invGray',
25                          'grayWhite', 'blackGray', 'blackWhite', 'black', 'white', 'hidden']))
26    xfrm = Typed(expected_type=GroupTransform2D, allow_none=True)
27    scene3d = Typed(expected_type=Scene3D, allow_none=True)
28    extLst = Typed(expected_type=OfficeArtExtensionList, allow_none=True)
29
30    def __init__(self,
31                 bwMode=None,
32                 xfrm=None,
33                 scene3d=None,
34                 extLst=None,
35                ):
36        self.bwMode = bwMode
37        self.xfrm = xfrm
38        self.scene3d = scene3d
39        self.extLst = extLst
40
41
42class GroupLocking(Serialisable):
43
44    tagname = "grpSpLocks"
45    namespace = DRAWING_NS
46
47    noGrp = Bool(allow_none=True)
48    noUngrp = Bool(allow_none=True)
49    noSelect = Bool(allow_none=True)
50    noRot = Bool(allow_none=True)
51    noChangeAspect = Bool(allow_none=True)
52    noMove = Bool(allow_none=True)
53    noResize = Bool(allow_none=True)
54    noChangeArrowheads = Bool(allow_none=True)
55    noEditPoints = Bool(allow_none=True)
56    noAdjustHandles = Bool(allow_none=True)
57    noChangeArrowheads = Bool(allow_none=True)
58    noChangeShapeType = Bool(allow_none=True)
59    extLst = Typed(expected_type=OfficeArtExtensionList, allow_none=True)
60
61    __elements__ = ()
62
63    def __init__(self,
64                 noGrp=None,
65                 noUngrp=None,
66                 noSelect=None,
67                 noRot=None,
68                 noChangeAspect=None,
69                 noChangeArrowheads=None,
70                 noMove=None,
71                 noResize=None,
72                 noEditPoints=None,
73                 noAdjustHandles=None,
74                 noChangeShapeType=None,
75                 extLst=None,
76                ):
77        self.noGrp = noGrp
78        self.noUngrp = noUngrp
79        self.noSelect = noSelect
80        self.noRot = noRot
81        self.noChangeAspect = noChangeAspect
82        self.noChangeArrowheads = noChangeArrowheads
83        self.noMove = noMove
84        self.noResize = noResize
85        self.noEditPoints = noEditPoints
86        self.noAdjustHandles = noAdjustHandles
87        self.noChangeShapeType = noChangeShapeType
88
89
90class NonVisualGroupDrawingShapeProps(Serialisable):
91
92    tagname = "cNvGrpSpPr"
93
94    grpSpLocks = Typed(expected_type=GroupLocking, allow_none=True)
95    extLst = Typed(expected_type=OfficeArtExtensionList, allow_none=True)
96
97    __elements__ = ("grpSpLocks",)
98
99    def __init__(self,
100                 grpSpLocks=None,
101                 extLst=None,
102                ):
103        self.grpSpLocks = grpSpLocks
104
105
106class NonVisualDrawingShapeProps(Serialisable):
107
108    tagname = "cNvSpPr"
109
110    spLocks = Typed(expected_type=GroupLocking, allow_none=True)
111    txBax = Bool(allow_none=True)
112    extLst = Typed(expected_type=OfficeArtExtensionList, allow_none=True)
113
114    __elements__ = ("spLocks", "txBax")
115
116    def __init__(self,
117                 spLocks=None,
118                 txBox=None,
119                 extLst=None,
120                ):
121        self.spLocks = spLocks
122        self.txBox = txBox
123
124
125class NonVisualDrawingProps(Serialisable):
126
127    tagname = "cNvPr"
128
129    id = Integer()
130    name = String()
131    descr = String(allow_none=True)
132    hidden = Bool(allow_none=True)
133    title = String(allow_none=True)
134    hlinkClick = Typed(expected_type=Hyperlink, allow_none=True)
135    hlinkHover = Typed(expected_type=Hyperlink, allow_none=True)
136    extLst = Typed(expected_type=OfficeArtExtensionList, allow_none=True)
137
138    __elements__ = ["hlinkClick", "hlinkHover"]
139
140    def __init__(self,
141                 id=None,
142                 name=None,
143                 descr=None,
144                 hidden=None,
145                 title=None,
146                 hlinkClick=None,
147                 hlinkHover=None,
148                 extLst=None,
149                ):
150        self.id = id
151        self.name = name
152        self.descr = descr
153        self.hidden = hidden
154        self.title = title
155        self.hlinkClick = hlinkClick
156        self.hlinkHover = hlinkHover
157        self.extLst = extLst
158
159class NonVisualGroupShape(Serialisable):
160
161    tagname = "nvGrpSpPr"
162
163    cNvPr = Typed(expected_type=NonVisualDrawingProps)
164    cNvGrpSpPr = Typed(expected_type=NonVisualGroupDrawingShapeProps)
165
166    __elements__ = ("cNvPr", "cNvGrpSpPr")
167
168    def __init__(self,
169                 cNvPr=None,
170                 cNvGrpSpPr=None,
171                ):
172        self.cNvPr = cNvPr
173        self.cNvGrpSpPr = cNvGrpSpPr
174